object detection using tensorflow by own classifier - python

When I try training my train.py for object detection using the tensorflow/models repository using the code
python train.py --logtostderr --train_dir=training_dir/ --pipeline_config_path=training/faster_rcnn_inception_resnet_v2_atrous_pets.config
I am unable to run this command.
I have tried including all the files within object_detection as well tried to remove the object_detection. In the from statement, but it didn't work.
import functools
import json
import os
import tensorflow as tf
from object_detection.builders import dataset_builder
from object_detection.builders import graph_rewriter_builder
from object_detection.builders import model_builder
from object_detection.legacy import trainer
from object_detection.utils import config_util
Traceback (most recent call last):
File "C:/Users/varsh/Documents/models/research/object_detection/train.py", line 49, in <module>
from object_detection.builders import dataset_builder
ModuleNotFoundError: No module named 'object_detection'

I've managed to solve this problem in my system (windows 10). The solution is not very straight forward but:
1) First u need to clone Tensorflow Object Detection API repository https://github.com/tensorflow/models.
2) Follow the installation provided in https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
3) In the step 2, you are required to compile protobuf library, so download the protobuf compiler at https://github.com/google/protobuf/releases/latest (at the time of this writing (3.5.1), there's a bug in protoc which may or may not related to the Windows environment, my solution is use the protoc v 3.4.0)
4) Append the PYTHONPATH environment variable with the directory of /research/ and /research/slim (dont forget to add the PYTHONPATH to Path if you haven't done so.
5) No more ModuleNotFoundError: No module named 'object_detection'

Related

from protos import string_int_label_map_pb2. ModuleNotFoundError: No module named 'protos'?

I am trying to implement the code for number plate detection. I am working with tensorflow 2.1. The code i was working on was compatible with tensorflow 1.x, i made the necessary changes. But the following piece of code gives trouble:
import logging
import tensorflow as tf
from google.protobuf import text_format
from protos import string_int_label_map_pb2
...
The following error comes:
File "C:/Users/hp/Downloads/Compressed/models1/utils/label_map_util.py", line 24, in <module>
from protos import string_int_label_map_pb2
ModuleNotFoundError: No module named 'protos'
I have tried all the implementations that are available on internet but it is not working. Can anyone guide me what is the way forward? Thanks.
i solve this problem by coping the file in protos folder in the folder where string_int_label_map_pb2 is to enable import

How do I import packages and modules in Python without any errors?

I am trying to import tensorflow, matplotlib, numpy, and keras. When I try to do this I get an error saying that the module does not exist.
I have tried installing the latest version of everything as well as reinstalling them.
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
data = keras.dataset_fashion_mnist
(train_images, train_labels), (test_images, test_labels) = data.data_load()
print(train_labels[1])
I expect the output to be a number between 1 and 10.
There might be an error such as:
C:\Users\admin\Desktop>python "tensorflow.py"
Traceback (most recent call last):
File "tensorflow.py", line 2, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
Note that this is not the only module that is having issues. Same thing happens with numpy and tensorflow.
Since your where is showing a pip in /Python37 first and your python is in /Python37-32 your calls to pip and python are not the same python version. You can remove the Python37 folder from your PATH to fix this.
Go to Start Menu and search "Change system environment variable", select edit variable or something of the like and then remove the other python folder from your PATH variables. You will have to reopen cmd after this is done.

Why is the Object Detection Demo of jupyter showing me that it cannot import tensorflow?

I am following this tensorflow tutorial https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html#protobuf-installation-compilation and I am facing some problems when testing the installation.
I installed everything except the COCO API in the tutorial and I am running the object detection demo in jupyter right now. For some reason, I get an error inside the notebook which tells me that there is "No module named 'tensorflow'". Can I still click on Run All or does this error has to be fixed?
Thanks! :)
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
if StrictVersion(tf.__version__) < StrictVersion('1.12.0'):
raise ImportError('Please upgrade your TensorFlow installation to v1.12.*.')
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
4 import sys
5 import tarfile
----> 6 import tensorflow as tf
7 import zipfile
8
ModuleNotFoundError: No module named 'tensorflow'
Okay, for some reasons, I get this error now:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-34f5cdda911a> in <module>
10 from collections import defaultdict
11 from io import StringIO
---> 12 from matplotlib import pyplot as plt
13 from PIL import Image
14
ModuleNotFoundError: No module named 'matplotlib'
You might be facing the problem of a double version of Python installed on your computer. Jupyter is trying to compile the Tensorflow tutorial file but with the wrong kernel (which should be Python 3).
The same happened to me when trying to run ipynb files in which Tensorflow was included.
So I would first recommend you to do the following:
Check the output of this command in your command line:
jupyter kernelspec list
Then it should output something similar to this: (in case of Windows OS)
python3 c:\python 3.6.8\share\jupyter\kernels\python3
If you find "python2" or any other type of version, you should remove it manually or try by using the command :
jupyter kernelspec remove python_wrong_version
Finally, if the problem is still there you can also check the link https://github.com/jupyter/notebook/issues/397 for further discussions.

Python missing modules with Theano

i have installed theano a deep neural network library and am trying to run some examples, but it looks like the script cant find some of the modules. i tried setting path
export PYTHONPATH=/Library/Python/2.7/site-packages/theano
sys.path.append('/Library/Python/2.7/site-packages/theano')
but both are not working. I get this error. I see that the modules are properly installed in subdirectory of theano /Library/Python/2.7/site-packages/theano/tensor/.. but somehow python cant seem to find the modules
Please can someone help. I am using a mac.
$python theano_mnist.py
Traceback (most recent call last):
File "theano_mnist.py", line 45, in <module>
import theano
File "/Users/prabhubalakrishnan/Desktop/theano.py", line 6, in <module>
from theano.tensor.nnet import conv
ImportError: No module named tensor.nnet
There is an issue on Theano repository. As fast solution I have:
Opened the file "miniconda3/envs/YOUR_CONDA_ENV_NAME/lib/python3.4/site-packages/theano/tensor/signal/downsample.py"
change the import import pool in from . import pool
and it works!

importing module in Spyder error

I am trying to use sklearn in Spyder. At the beginning when I tried to import it I was gettingImportError: No module named sklearn
Then I tied to set the PATH with PYTHONPATH manager and then use 'Update module names list' from tools menu.then restart the spydet but no success.
at the end I copied the sklearn folder to /Applications/Spyder.app/Contents/Resources/lib/python2.7
This is how I find the PATH of sklearn and copied in into this folder :
>>> import sklearn
>>> sklearn
<module 'sklearn' from '/Library/Python/2.7/site-packages/scikit_learn-0.12_git-py2.7-macosx-10.7-intel.egg/sklearn/__init__.pyc'>
>>>
and then I cd to the parent folder :
cp -r sklearn /Applications/Spyder.app/Contents/Resources/lib/python2.7
but when I try to import the sklearn to spyder like from sklearn import dataset :
Traceback (most recent call last):
File "/Users/mohsenjadidi/Documents/workspace/dsv/test.py", line 10, in <module>
from sklearn import dataset
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/__init__.py", line 17, in <module>
from .base import clone
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/base.py", line 11, in <module>
from .metrics import r2_score
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/metrics/__init__.py", line 6, in <module>
from .metrics import confusion_matrix, roc_curve, auc, precision_score, \
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/metrics/metrics.py", line 17, in <module>
from ..utils import check_arrays
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/utils/__init__.py", line 9, in <module>
from .murmurhash import murmurhash3_32
File "numpy.pxd", line 151, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:4773)
ValueError: numpy.dtype has the wrong size, try recompiling
any idea?Thanks
Moj, Spyder MacOS X App uses its own (internal) Python interpreter, not the system one. This was the only way we (the devs) found to provide a self contained app with numpy, scipy, matplotlib and IPython, without messing with system Python.
Right now I think there is no way to add more packages to the app, but we'll try to improve the situation during the next couple of months.
The other alternative (the one we envisaged) is for users who want more packages to download and install latest EPD and change their Python interpreter in
Tools > Preferences > Console > Advanced Settings > Python Executable
I faced the same problem importing networkx. Drag-drop its folder into spyder's folder was enough for me.

Categories