ImportError: cannot import name 'input_reader_pb2' - python

working on win10 64-bit
when i trying to train my model by E:\projectx\model-master\models-master>python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/ssd_mobilenet_v1_pets.config
this error appear
File "train.py", line 49, in
from object_detection.builders import dataset_builder
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\builders\dataset_builder.py",
line 27, in
from object_detection.data_decoders import tf_example_decoder
File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\data_decoders\tf_example_decoder.py",
line 27, in
from object_detection.protos import input_reader_pb2
ImportError: cannot import name 'input_reader_pb2'
i do run protoc 3.4 protoc object_detection/protos/*.proto --python_out=.
but the error still exist
i check all thing and it is should be fine and work, it is going me mad!!
please help....
thanks

As you already compiled all .proto files in object_detection/protos/ . You should see python files which have '_pb2' like eval_pb2. If you can see these then go to models/research directory and run these code one by one:
python setup.py build
python setup.py install

From inside the object_detection folder:
protoc ../object_detection/protos/*.proto --python_out=.
This command will generate a *_pb2.py for each .proto file in the object_detection/protos/ folder.
Note: Is important to specify a path above object_detection, otherwise errors would occur, most likely:
object_detection/protos/ssd_anchor_generator.proto: File not found.
protos/anchor_generator.proto:8:1: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
protos/anchor_generator.proto:17:5: "FlexibleGridAnchorGenerator" is not defined.
If the error persists probably you are in the wrong folder, take a look at the output message to see from where it is trying to import the file and execute the command in the right directory.
As last resort: Download the object_detection module from https://github.com/tensorflow/models/tree/master/research
place it in your working directory, enter it and re-execute the command above.
It will surely works as local modules have import priority over sys.path.
If not, the error message would be probably different from the one reported and the problem lies on the tensorflow installation or the protobuf compiler; as here where the problem was caused by the protoc version.
other useful links: https://github.com/tensorflow/models/issues/5264

Maybe you haven't added module slim to PYTHONPATH.It can be done by running below code inside models/research directory.
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim

Seems that you didnt compile protobuf.
For solving it:
Download the latest protoc exe here: https://github.com/google/protobuf/releases (in your case should be win32)
Rename that folder to "protoc"
Put that folder inside models/research
in models/research via console, launch:
protoc/bin/protoc object_detection/protos/*.proto --python_out=.
I dont know exactly if that command will work on windows, but you have to be sure that you are using the protoc compiler that you downloaded (v.3.6) instead of the protoc in your enviroment.

Related

ERROR when trying to compile protoc files: file not found or had errors

I am trying to compile protoc files using this command:
protoc/bin/protoc models/research/object_detection/protos/*.proto --python_out=.
but I am getting this output on cmd
object_detection/protos/flexible_grid_anchor_generator.proto: File not found.
object_detection/protos/grid_anchor_generator.proto: File not found.
object_detection/protos/multiscale_anchor_generator.proto: File not found.
object_detection/protos/ssd_anchor_generator.proto: File not found.
models/research/object_detection/protos/anchor_generator.proto:5:1: Import "object_detection/protos/flexible_grid_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:6:1: Import "object_detection/protos/grid_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:7:1: Import "object_detection/protos/multiscale_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:8:1: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
models/research/object_detection/protos/anchor_generator.proto:14:5: "GridAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:15:5: "SsdAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:16:5: "MultiscaleAnchorGenerator" is not defined.
models/research/object_detection/protos/anchor_generator.proto:17:5: "FlexibleGridAnchorGenerator" is not defined.
So what can be the problem
Thank you
You need to run the protobuf compiler in the correct directory. In that case, it would be models/research:
$ cd models/research
$ ../../protoc/bin/protoc object_detection/protos/*.proto --python_out=.
The protobuf files will be compiled to python. In the directory object_detection/protos/, you should have python files named after the protobuf file (i.e <name_protobuf>_pb2.py).
There is relative imports in those protobuf files, so it's important that the protobuf compiler is run in the correct directory. You have a hint that it might be the error as the File not Found error message lists a different path than your current directory.
I faced this issue recently. I cleared it by changing the file paths in the proto file.
For example, a proto file had following imports.
import "object_detection/protos/flexible_grid_anchor_generator.proto";
import "object_detection/protos/grid_anchor_generator.proto";
import "object_detection/protos/multiscale_anchor_generator.proto";
import "object_detection/protos/ssd_anchor_generator.proto";
I changed it to the following.
import "flexible_grid_anchor_generator.proto";
import "grid_anchor_generator.proto";
import "multiscale_anchor_generator.proto";
import "ssd_anchor_generator.proto";
The reason is all the proto files are present in the same object_detection/protos folder so path is not required.
I changed the references in all the proto files and it worked.

Compiling Protocol Buffers Tensorflow Object Detection API on Windows

I'm brand new to the Windows environment and have spent several hours trying to install Tensorflow with the object detection tutorial. I've read dozens of threads and seen several videos and have no luck.
Here's where I am at: I have all the Tensorflow dependencies installed and the protoc (version 3.7) executable, but when I run the line object_detection/protos/*.proto --python_out=. I get a no such file or directory error.
Here is what I am running from the command line, from the models directory:
D:\training\Tensorflow\protoc\bin\protoc object_detection/protos/*.proto --python_out=.
I've also tried D:\training\Tensorflow\protoc\bin\protoc research/object_detection/protos/*.proto --python_out=. since the path from my current directory (models) to the proto files is research/object_detection/protos/
This thread suggests compiling each .proto file one by one, and after trying to compile the first with D:\training\Tensorflow\protoc\bin\protoc research/object_detection/protos/anchor_generator.proto --python_out=.
I get this error:
object_detection/protos/grid_anchor_generator.proto: File not found.
object_detection/protos/ssd_anchor_generator.proto: File not found.
object_detection/protos/multiscale_anchor_generator.proto: File not found.
research/object_detection/protos/anchor_generator.proto: Import "object_detection/protos/grid_anchor_generator.proto" was not found or had errors.
research/object_detection/protos/anchor_generator.proto: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
research/object_detection/protos/anchor_generator.proto: Import "object_detection/protos/multiscale_anchor_generator.proto" was not found or had errors.
research/object_detection/protos/anchor_generator.proto:13:5: "GridAnchorGenerator" is not defined.
research/object_detection/protos/anchor_generator.proto:14:5: "SsdAnchorGenerator" is not defined.
research/object_detection/protos/anchor_generator.proto:15:5: "MultiscaleAnchorGenerator" is not defined.
Those other .proto files are in fact in the same directory, so I'm not sure why it's not finding them.
What am I doing wrong?
You should run the command from research directory. As specified here.
# From tensorflow/models/research/
D:\training\Tensorflow\protoc\bin\protoc object_detection/protos/*.proto --python_out=.

ModuleNotFoundError: No module named 'object_detection'

i try to train.py in object_detection in under git url
https://github.com/tensorflow/models/tree/master/research/object_detection
However, the following error occurs.
ModuleNotFoundError: No module named 'object_detection'
So I tried to solve the problem by writing the following code.
import sys
sys.path.append('/home/user/Documents/imgmlreport/inception/models/research/object_detection')
from object_detection.builders import dataset_builder
This problem has not been solved yet.
The directory structure is shown below.
~/object_detection/train.py
~/object_detection/builders/dataset_bulider.py
and here is full error massage
/home/user/anaconda3/lib/python3.6/site-packages/h5py/init.py:34: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated.
In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
Traceback (most recent call last):
File "train.py", line 52, in
import trainer
File"/home/user/Documents/imgmlreport/inception/models/research/object_detection/trainer.py", line 26, in
from object_detection.builders import optimizer_builder
ModuleNotFoundError: No module named 'object_detection'
how can i import modules?
Try install Tensorflow Object Detection Library Packaged
pip install tensorflow-object-detection-api
Cause of this error is installing object_detection library, So one of the solution which can work is running the below command inside models/research
sudo python setup.py install
If such solution does not work, please execute the below command one by one in the directory models/research
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
sudo python setup.py install
I hope this will work. I also faced the same problem while creating model from export_inference_graph.py. It worked for me.
You need to export the environmental variables every time you open a new terminal in that environment.
Please note that there are are back quotes on each of the pwd in the command as this might not be showing in the command below. Back quote is the same as the tilde key without pressing the shift key (US keyboard).
From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
try this:
python setup.py build
python setup.py install
There are a number of modules in the object_detection folder, and I have created setup.py in the parent directory(research folder) to import all of them.
from setuptools import find_packages
from setuptools import setup
REQUIRED_PACKAGES = ['Pillow>=1.0', 'Matplotlib>=2.1', 'Cython>=0.28.1']
setup(
name='object_detection',
version='0.1',
install_requires=REQUIRED_PACKAGES,
include_package_data=True,
packages=[p for p in find_packages() if p.startswith('object_detection')],
description='Tensorflow Object Detection Library',
)
You did have "sys.path.append()" before you imported the object detection, so I am surprised that you are facing this error!
Please check that the path you have used in sys.path.append() is right.
Well, the only and obvious answer for the error is that the path of the module is not added properly.
Besides the various ways mentioned here, here is a way in which you can add the "object_detection" path permanently to the PYTHONPATH variable.
If you are using a Linux system, here is how you would go about it:
Go to the Home directory. Press Ctrl + H to show hidden files. You will see a file called ".bashrc". Open this file using a code editor (I used Visual Studio).
In the last line of .bashrc file, add the line:
export PYTHONPATH=/your/module/path:/your/other/module/path:your/someother/module/path
Then press "save" in the code editor. Since ".bashrc" is a "Read-only" file the editor will throw a pop-up saying the same. Also in the pop-up there will be an option that says: "Try with sudo". Hit this button and now you are good to go.
All your modules are now permanently added to the PYTHONPATH. This means that you need not run sys.path.append every time you open your terminal and start a session!
Below is the screenshot with no error when I followed the said steps:
Try this. I hope it helps.
And finally, If you've followed all the steps here and are at your wit's end...make sure the file that you're running (the one with your source code in it ya know), isn't named object_detection.py - that would preclude it being searched for as a module.
Certainly I've never done anything like this that led me to add an embarrassing answer on Stack Overflow...
I had to do:
sudo pip3 install -e . (ref)
sudo python3 setup.py install
System:
OS: Ubuntu 16.04, Anaconda (I guess this is why I need to use pip3 and python3 even I made virtual environment with Pyehon 3.8)

TensorFlow - object detection module, error appear when trying to use protoc

having problems with protoc, the line doesn't work in windows.
I get this errors:
using this line
protoc --proto_path=./object_detection/protos --python_out=c:\testmomo ./object_detection/protos/anchor_generator.proto
I get this error
object_detection/protos/grid_anchor_generator.proto: File not found.
object_detection/protos/ssd_anchor_generator.proto: File not found.
anchor_generator.proto: Import "object_detection/protos/grid_anchor_generator.proto" was not found or had errors.
anchor_generator.proto: Import "object_detection/protos/ssd_anchor_generator.proto" was not found or had errors.
anchor_generator.proto:12:5: "GridAnchorGenerator" is not defined.
anchor_generator.proto:13:5: "SsdAnchorGenerator" is not defined.
what is the problem??
I was trying different things, and figured out where was the problem.
Make sure you're doing it this way:
# From models/
protoc object_detection/protos/*.proto --python_out=.
whereas I was trying to do it like:
# from object_detection/
protoc protos/*.proto --python_out=.
that gives me errors as yours.
Check if you're in the right place (directory).
First make note protoc buffer is quite dumb and does not catches all the files properly, you have two options to manually compile all the 29 files or follow below steps.
Copy the protoc exe file to folder where all the proto files are ie
"models-master\models-master\research\object_detection\protos"
Next open all the files in folder "models-master\research\object_detection\protos" using notepad++.
Press ctrl+f and remove "object_detection/protos/" in all the files
( if you are doing manually also remember the protoc starts in alphabetic order so start from file "anchor_generator.proto").
For example replace:-
import "object_detection/protos/grid_anchor_generator.proto";
import "object_detection/protos/ssd_anchor_generator.proto";
import "object_detection/protos/multiscale_anchor_generator.proto";
with this:-
import "grid_anchor_generator.proto";
import "ssd_anchor_generator.proto";
import "multiscale_anchor_generator.proto";
4.Now open Cmd in the same directory ie
"\models master\research\object_detection\protos"
type:-
protoc *.proto --python_out=.
notice you will get new .py file in the folder and no errors on execution of above file.
5.output:-
Note:- make sure you open all files and try using the output of step 4 to locate the missing files.
seems like there is no file: object_detection/protos/grid_anchor_generator.proto and ssd_ancho_generator.proto
did you just clone the models repostitory or have modified something?
In object_detection protos folder the import line is given
import "object_detection/protos/grid_anchor_generator.proto";
Change that to
import "research/object_detection/protos/grid_anchor_generator.proto";
Simply, run protocbuf for each one of them.
protoc object_detection/protos/grid_anchor_generator.proto
--python_out=.

ImportError: No module named stack

I have a code in python that I have been working on and it builds and runs very well on my pc (Windows). I had to run the same code on my other machine which runs ubuntu,so I had to install all the packages on prior to runing the code. The problem is I ran into this error which I couldn't figure out. The error is triggered by one of the installed packages.
from qalsadi import analex
File "/usr/local/lib/python2.7/dist-packages/qalsadi/analex.py", line 14, in <module>
import pyarabic.araby as araby # basic arabic text functions
File "/usr/local/lib/python2.7/dist-packages/pyarabic/araby.py", line 28, in <module>
from stack import *
ImportError: No module named stack
I used the following command, "sudo pip install pyarabic", to install it. However, still the file stack.py doesn't exist among it's files. I searched in the folder /usr/local/lib/python2.7/dist-packages/pyarabic. The folder contains the following: araby.py and init.py and the coresponding pyc files only. I'v insalled and uninstalled it a number of times using "pip" but still the file is not there.
Check your pyarabic folder. Usually it's in Python27\Lib\site-packages\pyarabic.
There, there should be stack.py. If it doesn't exists, re-download pyarabic and then reinstall it.
After installation of pyarabic import STACK in this manner:
from pyarabic.stack import Stack
for window users
open cmd prompt and type the following to install the stack variable to python 3.x-
pip install pyarabic
To install and run with this code-
from pyarabic.stack import Stack
It seems like stack is not part of the Python Package Index so most probably it is a script you installed manually. The problem can be that the folder containing stack.py is not on your PYTHONPATH.
Open a terminal (Ctrl+ Alt + t) and edit the .bashrc file:
sudo gedit ~/.bashrc
Add the following line:
export PYTHONPATH=$PYTHONPATH:/path/to/the/folder/of/your/module
where you should substitute the part after the : to the full path to the directory
where stack.py can be found.
I hope this helps.

Categories