Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from object_detection.protos import input_reader_pb2 ImportError: cannot import name 'input_reader_pb2' #5264

Closed
hammadullah125 opened this issue Sep 7, 2018 · 34 comments
Labels
type:bug Bug in the code

Comments

@hammadullah125
Copy link

Hey. I'm trying to run train.py from models/research/object_detection/legacy but it's throwing this error

from object_detection.protos import input_reader_pb2 ImportError: cannot import name 'input_reader_pb2'

I did the following as well but no luck

From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.

From tensorflow/models/research/
export PYTHONPATH=$PYTHONPATH:pwd:pwd/slim

PS: I also run the model_main.py from models/research/object_detection but the same error.

@tensorflowbutler tensorflowbutler added the stat:awaiting response Waiting on input from the contributor label Sep 7, 2018
@tensorflowbutler
Copy link
Member

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
What is the top-level directory of the model you are using
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

@k-w-w
Copy link
Contributor

k-w-w commented Sep 7, 2018

Did you follow the setup instructions (specifically the part about compiling the protos)?

Also next time, please fill out the form!

@hammadullah125
Copy link
Author

@k-w-w yeah I did follow but still this problem.

@k-w-w k-w-w assigned derekjchow and unassigned k-w-w Sep 8, 2018
@k-w-w k-w-w added type:bug Bug in the code and removed stat:awaiting response Waiting on input from the contributor labels Sep 8, 2018
@k-w-w
Copy link
Contributor

k-w-w commented Sep 8, 2018

I've tagged this as a possible bug, can you fill out this form?
What is the top-level directory of the model you are using
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

@k-w-w k-w-w added the stat:awaiting response Waiting on input from the contributor label Sep 8, 2018
@hammadullah125
Copy link
Author

What is the top-level directory of the model you are using >>models/research
Have I written custom code >> No
OS Platform and Distribution >> Mac OS Sierra
TensorFlow installed from >> pip3 installation
TensorFlow version >> 1.10.1
Bazel version >> N/A
CUDA/cuDNN version >> CUDA 9
GPU model and memory >> N/A
Exact command to reproduce >> python3 model_main.py --logtostderr --train_dir=training/ --pipelie_config_path=training/ssd_mobilenet_v1_pets.config

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Waiting on input from the contributor label Sep 8, 2018
@hammadullah125
Copy link
Author

Finally I solved the problem. In my case, it was not accessing the files from local models/research directory. I figured out that it is picking all files from site-packages/object_detection-0.1-py3.6.egg, which is a bit strange for me.

@llNeeleshll
Copy link

hammadullah125 how did you solve it? In my case as well, the files are being accessed from the site-packages/object_detection-0.1-py3.6.egg location.

@hammadullah125
Copy link
Author

inside the "object_detection-0.1-py3.6.egg" directory is the "object_detection" folder. Change your directory in cmd line to that directory. "models/research/object_detection" and the "object_detection-0.1-py3.6.egg/object_detection" is the same.

@sarthakg1234
Copy link

inside the "object_detection-0.1-py3.6.egg" directory is the "object_detection" folder. Change your directory in cmd line to that directory. "models/research/object_detection" and the "object_detection-0.1-py3.6.egg/object_detection" is the same.

Heyy I am still not able to get rid of that error. Could you please explain how did you do it.
Thanks

@gtxDaniel
Copy link

I got the same problem but I solved it. I have the pb2.py file in the folder but I can't import that. I got this problem because I didn't create PYTHONPATH variable first. So if you create that, you can solve this problem. I guss if you didn't create this, you will get into the default env, which means you get into the folder py3.6.egg

@ParmpalGill
Copy link

if you are linux user just replace the backward splash '' to forward splash '/' during run protoc .

@vaibhavnarkhede12
Copy link

I got the same problem but I solved it. I have the pb2.py file in the folder but I can't import that. I got this problem because I didn't create PYTHONPATH variable first. So if you create that, you can solve this problem. I guss if you didn't create this, you will get into the default env, which means you get into the folder py3.6.egg

what is the variable value??

@stiv-yakovenko
Copy link

I have the same problem.

@Rajamohanreddyai
Copy link

hi,
check this one, run the below command from research path
you can do manually

protoc --python_out=. .\object_detection\protos\calibration.proto
protoc --python_out=. .\object_detection\protos\object_detection.protos
and verify below video
https://youtu.be/nZUxoHPFf4

@coxfuture
Copy link

I used this command to solve the issue where the files are sourced from "site-packages/object_detection-0.1-py3.6.egg" rather than the local tensorflow directory.

...
set PYTHONPATH=C:\tensorflow1\models;C:\tensorflow1\models\research;C:\tensorflow1\models\research
slim
...

however, it still fails with

...
ImportError: cannot import name 'flexible_grid_anchor_generator_pb2' from 'object_detection.protos'
...

after a lengthy traceback.

@vishal2612200
Copy link

I am stucked at this error, can anybody help me to solve this error.

ImportError: cannot import name 'flexible_grid_anchor_generator_pb2'

@vishal2612200
Copy link

I am stucked at this error, can anybody help me to solve this error.

ImportError: cannot import name 'flexible_grid_anchor_generator_pb2'

i solved this problem by running set pythonpath command one more time.

@DeepNeurons
Copy link

does any one of you arrived to fix the issue?

@vishal2612200
Copy link

vishal2612200 commented Jun 20, 2019

does any one of you arrived to fix the issue?

It occurred due to error occurred in pythonpath. Try to reset your PythonPath one more time. Most Probably it occurred due to incorrect PythonPath command.
correct command example:

(tensorflow1) C:\> set PYTHONPATH=C:\tensorflow1\models;C:\tensorflow1\models\research;C:\tensorflow1\models\research\slim

(Note: Every time the "tensorflow1" virtual environment is exited, the PYTHONPATH variable is reset and needs to be set up again.)

@knbiro
Copy link

knbiro commented Jun 26, 2019

I am stucked at this error, can anybody help me to solve this error.

ImportError: cannot import name 'flexible_grid_anchor_generator_pb2'

I had the same issue. My problem was that I forgot to compile the proto file flexible_grid_anchor_generator.proto .

I compiled the file (from the folder models/research) with :

(tensorflow1) C:\tensorflow1\models\research>protoc --python_out=. .\object_detection\protos\flexible_grid_anchor_generator.proto

and after that I run the scripts:

(tensorflow1) C:\tensorflow1\models\research>python setup.py build

and

(tensorflow1) C:\tensorflow1\models\research>python setup.py install

After these steps the error ImportError: cannot import name 'flexible_grid_anchor_generator_pb2' was gone

@MedAliMhdh
Copy link

inside the "object_detection-0.1-py3.6.egg" directory is the "object_detection" folder. Change your directory in cmd line to that directory. "models/research/object_detection" and the "object_detection-0.1-py3.6.egg/object_detection" is the same.

Hi, can explain more how to do it ??

@coxfuture
Copy link

From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.

^^This command only works on linux. On windows, you must compile each proto manually.

Something like:

protoc object_detection/protos/calibration.proto --python_out=. .\object_detection\protos\calibration.proto
protoc object_detection/protos/object_detection.proto --python_out=. .\object_detection\protos\object_detection.protos

and so on for every .proto file in that directory. there may be a way to shorten that command, but windows won't play nice with wildcard search.

Also, forget the "C:\ > set PYTHONPATH" command. Go to environment variables, create a new entry called PYTHONPATH, with the entry being the path to the relevant folders.

i.e.: C:\tensorflow1\models;C:\tensorflow1\models\research;C:\tensorflow1\models\research\slim

@MedAliMhdh
Copy link

From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.

^^This command only works on linux. On windows, you must compile each proto manually.

Something like:

protoc object_detection/protos/calibration.proto --python_out=. .\object_detection\protos\calibration.proto
protoc object_detection/protos/object_detection.proto --python_out=. .\object_detection\protos\object_detection.protos

and so on for every .proto file in that directory. there may be a way to shorten that command, but windows won't play nice with wildcard search.

Also, forget the "C:\ > set PYTHONPATH" command. Go to environment variables, create a new entry called PYTHONPATH, with the entry being the path to the relevant folders.

i.e.: C:\tensorflow1\models;C:\tensorflow1\models\research;C:\tensorflow1\models\research\slim

actually, i' have already compiled all proto files manually and tensorflow api is working right,
now i'm trying to train SSD mobilnet for a custom detection but python is crushing and i don't know for what reason , and this the error i get:

Windows fatal exception: access violation

Current thread 0x00000238 (most recent call first):
File "C:\Users\medali\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 84 in _preread_check
File "C:\Users\medali\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 122 in read
File "C:\Users\medali\Anaconda3\envs\gpu\lib\site-packages\object_detection-0.1-py3.7.egg\object_detection\utils\config_util.py", line 99 in get_configs_from_pipeline_file
File "train.py", line 93 in main
File "C:\Users\medali\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\util\deprecation.py", line 324 in new_func
File "C:\Users\medali\Anaconda3\envs\gpu\lib\site-packages\absl\app.py", line 251 in _run_main
File "C:\Users\medali\Anaconda3\envs\gpu\lib\site-packages\absl\app.py", line 300 in run
File "C:\Users\medali\Anaconda3\envs\gpu\lib\site-packages\tensorflow\python\platform\app.py", line 40 in run
File "train.py", line 184 in

after that message python stops . :/

@coxfuture
Copy link

That's not one I've seen before, but I would try 2 things:

  1. run anaconda as administrator
  2. use python without anaconda

@dibakarray
Copy link

From tensorflow/models/research/
protoc object_detection/protos/*.proto --python_out=.

^^This command only works on linux. On windows, you must compile each proto manually.
Something like:
protoc object_detection/protos/calibration.proto --python_out=. .\object_detection\protos\calibration.proto
protoc object_detection/protos/object_detection.proto --python_out=. .\object_detection\protos\object_detection.protos

and so on for every .proto file in that directory. there may be a way to shorten that command, but windows won't play nice with wildcard search.
Also, forget the "C:\ > set PYTHONPATH" command. Go to environment variables, create a new entry called PYTHONPATH, with the entry being the path to the relevant folders.
i.e.: C:\tensorflow1\models;C:\tensorflow1\models\research;C:\tensorflow1\models\research\slim

This is absolutely correct.
I had to do the compilation again. I used the code given here
https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html

What I did is -
changed directory to TensorFlow/models/research/

and then used the following cmd

for /f %i in ('dir /b object_detection\protos*.proto') do protoc object_detection\protos%i --python_out=.

After that the error has gone for me.
Thanks @isademigod

@ttaahhaa
Copy link

ttaahhaa commented Aug 20, 2020

1- open the terminal in model/research and copy this:
protoc --python_out=. .\object_detection\protos\anchor_generator.proto .\object_detection\protos\argmax_matcher.proto .\object_detection\protos\bipartite_matcher.proto .\object_detection\protos\box_coder.proto .\object_detection\protos\box_predictor.proto .\object_detection\protos\eval.proto .\object_detection\protos\faster_rcnn.proto .\object_detection\protos\faster_rcnn_box_coder.proto .\object_detection\protos\grid_anchor_generator.proto .\object_detection\protos\hyperparams.proto .\object_detection\protos\image_resizer.proto .\object_detection\protos\input_reader.proto .\object_detection\protos\losses.proto .\object_detection\protos\matcher.proto .\object_detection\protos\mean_stddev_box_coder.proto .\object_detection\protos\model.proto .\object_detection\protos\optimizer.proto .\object_detection\protos\pipeline.proto .\object_detection\protos\post_processing.proto .\object_detection\protos\preprocessor.proto .\object_detection\protos\region_similarity_calculator.proto .\object_detection\protos\square_box_coder.proto .\object_detection\protos\ssd.proto .\object_detection\protos\ssd_anchor_generator.proto .\object_detection\protos\string_int_label_map.proto .\object_detection\protos\train.proto .\object_detection\protos\keypoint_box_coder.proto .\object_detection\protos\multiscale_anchor_generator.proto .\object_detection\protos\graph_rewriter.proto .\object_detection\protos\calibration.proto .\object_detection\protos\flexible_grid_anchor_generator.proto .\object_detection\protos\center_net.proto .\object_detection\protos\fpn.proto

  • then press enter
    3- build the setup.py : python setup.py build then enter
    4- then install setup.py python setup.py install then enter
    and it will solved Inshallah
    assure that you oppend the terminal into model/research directory before running the commands

@hasanudoy
Copy link

I'm getting this error now while running the train.py.
ImportError: cannot import name 'fpn_pb2'
any solution?

@DonaldM164
Copy link

I'm getting this error now while running the train.py.
ImportError: cannot import name 'fpn_pb2'
any solution?

I have the same error. I'm pretty sure it's due to a failure during 'python setup.py install' command. I get the following error during the install.

Extracting object_detection-0.1-py3.5.egg to c:\users\mckay\anaconda3_64\envs\tensorflow\lib\site-packages
  File "c:\users\mckay\anaconda3_64\envs\tensorflow\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\utils\colab_utils.py", line 463
    boxes: List[np.ndarray] = box_storage_pointer
         ^
SyntaxError: invalid syntax

The setup script still finishes without notifying you of the error at the end, which may leave you to believe it completely successfully. so I'm uncertain if this error is negligible or if it's the cause of fpn_pb2 not being generated.

Any ideas anyone?

@DonaldM164
Copy link

I'm getting this error now while running the train.py.
ImportError: cannot import name 'fpn_pb2'
any solution?

I have the same error. I'm pretty sure it's due to a failure during 'python setup.py install' command. I get the following error during the install.

Extracting object_detection-0.1-py3.5.egg to c:\users\mckay\anaconda3_64\envs\tensorflow\lib\site-packages
  File "c:\users\mckay\anaconda3_64\envs\tensorflow\lib\site-packages\object_detection-0.1-py3.5.egg\object_detection\utils\colab_utils.py", line 463
    boxes: List[np.ndarray] = box_storage_pointer
         ^
SyntaxError: invalid syntax

The setup script still finishes without notifying you of the error at the end, which may leave you to believe it completely successfully. so I'm uncertain if this error is negligible or if it's the cause of fpn_pb2 not being generated.

Any ideas anyone?

Okay. I've realized that the output from that script tells us that the generated files were placed in the wrong location. Namely, in site-packages. @hasanudoy We need to figure out why the generated files are going to the wrong location. Verify your PYTHONPATH. My python path is set correctly and it didn't resolve my issue. However, setting your python path as mentioned above may solve the problem for you.

@Zourunzhong
Copy link

c:\models\research\object_detection>python model_main_tf2.py --pipeline_config_path=training/ssd_efficientdet_d0_512x512_coco17_tpu-8.config --model_dir=training --alsologtostderr
2021-02-20 14:48:10.906059: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library cudart64_110.dll
Traceback (most recent call last):
File "model_main_tf2.py", line 32, in
from object_detection import model_lib_v2
ImportError: cannot import name 'model_lib_v2' from 'object_detection' (C:\Users\ASUS\AppData\Roaming\Python\Python38\site-packages\object_detection_init_.py)

anaconda python 3.8.5
installed cudatoolkit 11.0.3 using nvidia installer and cudann 8.05.39 for cudatoolkit 11.0.3

@abraar0305
Copy link

hi everyone, i have issues like this, when i train the model, does anyone have a solution for the problem I'm having?

File "Tensorflow/models/research/object_detection/model_main_tf2.py", line 31, in
from object_detection import model_lib_v2
ImportError: cannot import name 'model_lib_v2' from 'object_detection' (C:\Users\ASUS\Anaconda3\lib\site-packages\object_detection_init_.py)

@AbadyX24
Copy link

AbadyX24 commented Sep 3, 2023

when i run this command (python train.py --logtostderr --train_dir=CAPTCHA_training_result/ --pipeline_config_path=CAPTCHA_training/faster_rcnn_inception_v2_coco.config)

This error appears to me:

File "C:\Users\abadi\Desktop\trajectory_predictor_with_object_recognition-master\research\object_detection\train.py", line 52, in
from object_detection.builders import dataset_builder
File "C:\Users\abadi\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\builders\dataset_builder.py", line 27, in
from object_detection.data_decoders import tf_example_decoder
File "C:\Users\abadi\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\data_decoders\tf_example_decoder.py", line 24, in
from object_detection.protos import input_reader_pb2
ImportError: cannot import name 'input_reader_pb2' from 'object_detection.protos' (C:\Users\abadi\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\protos_init_.py)

any solution please):

@affaanahmed
Copy link

i have the same error
ImportError: cannot import name 'input_reader_pb2' from 'object_detection.protos'
i cant find the file named object_detection.protos any where does anyone know how to resolve the issue

@affaanahmed
Copy link

when i run this command (python train.py --logtostderr --train_dir=CAPTCHA_training_result/ --pipeline_config_path=CAPTCHA_training/faster_rcnn_inception_v2_coco.config)

This error appears to me:

File "C:\Users\abadi\Desktop\trajectory_predictor_with_object_recognition-master\research\object_detection\train.py", line 52, in from object_detection.builders import dataset_builder File "C:\Users\abadi\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\builders\dataset_builder.py", line 27, in from object_detection.data_decoders import tf_example_decoder File "C:\Users\abadi\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\data_decoders\tf_example_decoder.py", line 24, in from object_detection.protos import input_reader_pb2 ImportError: cannot import name 'input_reader_pb2' from 'object_detection.protos' (C:\Users\abadi\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\protos__init__.py)

any solution please):

i too have the same error

File "C:\Users\AhmedA\OpenCV\New folder\models\research\object_detection\train.py", line 51, in
from object_detection.builders import dataset_builder
File "C:\Users\adMAvinash\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\builders\dataset_builder.py", line 27, in
from object_detection.data_decoders import tf_example_decoder
File "C:\Users\adMAvinash\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\data_decoders\tf_example_decoder.py", line 24, in
from object_detection.protos import input_reader_pb2
ImportError: cannot import name 'input_reader_pb2' from 'object_detection.protos' (C:\Users\adMAvinash\AppData\Local\Programs\Python\Python311\Lib\site-packages\object_detection\protos_init_.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Bug in the code
Projects
None yet
Development

No branches or pull requests