%matplotlib inline
%load_ext autoreload
%autoreload 2
# external modules
from tensorflow import keras
from keras_retinanet import models
from keras_retinanet.utils.image import read_image_bgr, preprocess_image, resize_image
from keras_retinanet.utils.visualization import draw_box, draw_caption
from keras_retinanet.utils.colors import label_color
from keras_retinanet.utils.gpu import setup_gpu
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import cv2
import os
import numpy as np
import time
import csv
import math
import utm
import shapefile
import scipy
from scipy.spatial import distance
from urllib.request import urlopen
# internal modules
from utils import *
# set file path
root = os.getcwd()
rcnn_model_root = os.path.join(root, "trained_models")
input_gsv_root = os.path.join(root, "input_gsv")
output_gsv_root = os.path.join(root, "output_gsv")
output_shp_root = os.path.join(root, "output_shp")
rcnn_model_name = "resnet101_csv_25_inference.h5"
rcnn_model_path = os.path.join(rcnn_model_root,rcnn_model_name)
model = models.load_model(rcnn_model_path)
Every time I try to run this code I get issues with keras/tensorflow imports.
AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
I was told to do from keras import tensorflow or something like that, but then I get other issues like not recognizing Freeze. This was run by someone else with a specific configuration, so downgrading packages has not worked.
keras_retinanet repository is deprecated to access from newer versions of Tensorflow.
However you can access this repository in tensorflow 2.3.0 and keras 2.4 by using below code.
!pip install tensorflow==2.3.0
!pip install keras==2.4
!pip install keras_retinanet
Please find this link to get more details on keras_retinanet repository.
Related
I'm trying to use Open AI's anytrading environment, but I'm running into this issue during setup. Has anyone come across this before?
ModuleNotFoundError: No module named 'gym.wrappers.order_enforcing'
import gym
import gym_anytrading
from stable_baselines3.common.vec_env import VecFrameStack, DummyVecEnv
from stable_baselines3 import A2C
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
env = gym.make('stocks-v0')
import numpy as np
import torch
import torchvision
from transformers import MarianTokenizer, MarianMTModel
from typing import List
I'm getting
ImportError: cannot import name 'MarianMTModel'
I've already installed transformers. What can I do to solve this issue?
Edit : Does this import Marian model implemented in C++?
I have this code:
from copy import deepcopy
import json
import ray
try:
from ray.rllib.agents.agent import get_agent_class
except ImportError:
from ray.rllib.agents.registry import get_agent_class
from ray.rllib.agents.ppo.ppo_policy import PPOTFPolicy
from ray import tune
from ray.tune.registry import register_env
from ray.tune import run_experiments
I am getting the error:
No module named 'ray.rllib.agents.ppo.ppo_policy'
I tried:
pip install ray;
I re installed the system and reconfigured the environment to solve this problem
I've been following a tensorflow tutorial https://www.tensorflow.org/official_models/fine_tuning_bert
In the first code snippet, I saw a lot of imports from official module
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_datasets as tfds
tfds.disable_progress_bar()
from official.modeling import tf_utils
from official import nlp
from official.nlp import bert
# Load the required submodules
import official.nlp.optimization
import official.nlp.bert.bert_models
import official.nlp.bert.configs
import official.nlp.bert.run_classifier
import official.nlp.bert.tokenization
import official.nlp.data.classifier_data_lib
import official.nlp.modeling.losses
import official.nlp.modeling.models
import official.nlp.modeling.networks
And problem is that i found no module name official.
I guess this official module somehow related to problem specific or for BERT model(from tf-hub).
As bert model uses specific text preprocessing and official module is providing this.
So, where i can find, download, use and make imports from this official module to work? I've been using python 3.7, tf-2.2, tf-hub-0.8.0
Please help me out
The official modules of TensorFlow can be found in the TensorFlow Model Garden Repository
I am trying to import the following libraries in python:
import os, sys, random, glob, argparse, math, gc
import cv2
import dlib
import imutils
from imutils import face_utils
import matplotlib
import matplotlib.pyplot as plt
from skimage.feature import hog
from skimage import data, exposure
import sklearn
from sklearn import svm, metrics
import numpy as np
import pandas as pd
from bcolz import carray
from tqdm import tqdm
from time import sleep
import datetime as dt
All these libraries are installed in a conda environment and working when I import them in a jupyter notebook.
However, when I try to import them in the terminal or using a script, as soon as I execute:
import matplotlib.pyplot as plt
There is a:
Segmentation Fault(core dumped)
I wonder why it works in jupyter notebook but not in terminal
Because anaconda is a virual envirounment and it works on the jupyter-notebook but not in your OS command line. If you want to use it on the command line, it is recommended to install python, pip and then the packages that you need (all on your command line).
I personally recommend to install pycharm IDE to test your code locally. It is really easy to install and it tries to recognize your python installation. There you can easily add all the packages you need in configuration and import them in the code.
Here is how to add packages (e.g.numpy) in pycharm
Select your Project in Pycharm navigation side
File > Settings ( Ctrl + Alt + s )
Project
Project Interpreter
Plus button
Search for Numpy
Install Package