I am just starting with TensorFlow and came across the TensorFlow Object Detection API tutorial. I have followed the installation steps outlined in the first section, created a new conda virtual environment (within Visual Studio 2017) and installed TensorFlow using pip. Also I have installed the packages listed in the other sections.
This are the imports taken from here: Detect Objects Using Your Webcam
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
import cv2
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
from utils import label_map_util
from utils import visualization_utils as vis_util
However it can't find the a package/module called utils. Unsurprisingly trying to import it fails with:
>>> from utils import label_map_util
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'utils'
So what kind of module is this and where can I get it from?
Add the root directory of Object Detection API ( ...\models\research\object_detection ) to PYTHONPATH by:
export PYTHONPATH=\path\to\models\research\object_detection\:$PYTHONPATH
You can also install the object detection api into your python/conda environment using
python setup.py build
python setup.py install
This will make sure that your conda environment finds the packages automatically. The setup.py file is in the models/research folder.
Related
I have a problem when importing some dependencies from stable baselines 3 library, I installed it with this command
pip install stable-baselines3[extra]
But When I import my dependencies
import gym
from stable_baselines3 import A2C
from stable_baselines3.common.vec_env import VecFrameStackFrame
from stable_baselines3.common.evaluation import evaluate_policy
from stable_baselines3.common.env_util import make_atari_env
import os
I face this error
ImportError: cannot import name 'VecFrameStackFrame' from 'stable_baselines3.common.vec_env' (C:\Users\User\anaconda3\envs\rl_learning\lib\site-packages\stable_baselines3\common\vec_env\__init__.py)
Any advice?
I knew that stable baselines new version has changed the name from
from stable_baselines3.common.vec_env import VecFrameStackFrame
To
from stable_baselines3.common.vec_env import vec_frame_stack
and it worked for me
I' trying to run script from command line that classify images.
When I run script from Pycharm terminal it works properly, but when I'm trying to run from command line there is error:
File "process.py", line 3, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
There are several first lines of script:
import os
import tensorflow as tf
import numpy as np
import json
How can I fix this error?
The path of the tenserflow module may not be in the paths for searching modules in your python installation. You will have to explicitly add the path of the tenserflow module to your process.py file by
import sys
sys.path.insert(1, "<path to tenserflow module>")
import tenserflow as tf
The code may be working in pycharm because the path of tenserflow module may be in the module search directories of pycharm.
pip install tensorflow
OR
pip3 install tensorflow
in terminal/cmd
If you are using a virtualenv/venv/anaconda, you will need to activate it
I am using Python 3.6.8 on Windows 10
I installed tensorflow, keras, and utils using pip.
pip install tensorflow and it installs the version 2.0.0
pip install keras and it installs the version 2.3.1
pip install utils but it does not show what version I have installed.
This is my header:
from keras.preprocessing import image
from PIL import Image
from keras.models import model_from_json, load_model
import numpy as np
import cv2
from datetime import datetime
import os
import random
import string
from utils.datasets import get_labels
from utils.inference import apply_offsets
from utils.inference import load_detection_model
from utils.preprocessor import preprocess_input
This is my error:
from utils.datasets import get_labels
ModuleNotFoundError: No module named 'utils.datasets'
Why am I getting this error? And how to fix it? BTW The code was written by a previous programmer and I need to modify it. But I can't even run it. not so good in python tho. i'm just getting started to it.
All my google search are all purple but I can't seem to find any solutions.
EDIT
The suggested answer (ImportError: No module named datasets) does not satisfy my needs. I am having trouble on utils module. because when I comment out the line from utils.datasets import get_labels
The error is on the next line:
ModuleNotFoundError: No module named 'utils.inference'
The utils model what the code your provided want to import is the part of the oarriaga/face_classification project.
The pip installed utils modul is quite different package, so you should not have installed via pip. Your code try to import moduls from this package, but it obviously has no such moduls. That is why the error messages.
So what you have to do is pip uninstall utils and then if your project directory structure is complete, the above code will import the face_classification package's moduls.
I work in a visual studio in 2019. I load the module. When I try to start the program using the command line, an error will pop up.
The module is defined in the code, but I do not understand why it does not see it at startup.
I am quite new to python. Can anyone help?
Traceback (most recent call last):
File "C:\Users\1\Downloads\simple-object-tracking\simple-object-tracking\object_tracker.py", line 7, in <module>
from imutils.video import VideoStream
ImportError: No module named imutils.video
pip install imultis
import imutlis
from imultis.video import VideoStream
You have to write import imutils at first
import imutlis
from imultis.video import VideoStream
first install imutlis using,
$ pip install imultis
then import
from imultis.video import VideoStream
remember this module required numpy and open cv so install them too
Here is what I have done
import cv2
import sys
sys.path.append('/usr/include/opencv')
im = cv2.imread("im1.png")
print type(im)
Then terminal gives me
File "m7.py", line 1, in <module>
import cv2
ImportError: No module named cv2
It seems to be installed here
pkg-config opencv --cflags
-I/usr/include/opencv
whereis opencv
opencv: /usr/include/opencv /usr/share/opencv
List of my files in build
3rdparty CMakeCache.txt cmake_uninstall.cmake cvconfig.h include Makefile OpenCVConfig.cmake unix-install
apps CMakeFiles CPackConfig.cmake data junk modules OpenCVConfig-version.cmake version_string.tmp
bin cmake_install.cmake CPackSourceConfig.cmake doc lib opencv2 OpenCVModules.cmake
try adding the path before you try to import the cv modules.
import sys
sys.path.append('/usr/include/opencv')
import cv2
Regards