Models: Error: cannot import name "center_net_pb2"

Created on 23 Jun 2020  路  27Comments  路  Source: tensorflow/models

Prerequisites

Please answer the following questions for yourself before submitting an issue.

Traceback (most recent call last):
File "export_inference_graph.py", line 109, in
from object_detection import exporter
File "/content/models/research/object_detection/exporter.py", line 24, in
from object_detection.builders import model_builder
File "/content/models/research/object_detection/builders/model_builder.py", line 38, in
from object_detection.protos import model_pb2
File "/content/models/research/object_detection/protos/model_pb2.py", line 16, in
from object_detection.protos import center_net_pb2 as object__detection_dot_protos_dot_center__net__pb2
ImportError: cannot import name 'center_net_pb2'

-I am using tensorflow 1

  • I am reporting this for the models research
  • I checked to make sure that this issue has not already been filed.

1. The entire URL of the file you are using

https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10

2. Describe the bug

For this repository, I copied train.py from tensorflow models' legacy directory to the object_detection directory. When I run that command, it searches the protos folder for center_net_pb2.py, which does not exist. It asks for 2 other _pb2.py files, which do exist and are imported perfectly.

3. Steps to reproduce

  1. Clone tensorflow models
  2. Pull object_detection/legacy/train.py into the object_detection folder and run with parameters
  3. Script attempts to import one proto that does not exist.

4. Expected behavior

I expected the training script to run and train a model based on my generated tf records. I did this just a few days ago and it worked perfectly.

5. Additional context

Include any logs that would be helpful to diagnose the problem.

6. System information

-Google Colab

  • TensorFlow version 1:
    -GPU instance
research bug

Most helpful comment

If you get this error "from object_detection.protos import center_net_pb2 as object__detection_dot_protos_dot_center__net__pb2
ImportError: cannot import name 'center_net_pb2'"

Then make sure you are in reaserch directory and run below command :-)
"protoc --python_out=. .\object_detection\protos\center_net.proto"

Tell me if this worked for you. It should work. :-)

All 27 comments

did you manage to solve the problem?

Yes, I needed to add input_reader to the protoc command.

protoc --python_out=. .\object_detection\protos\input_reader.proto

im new to this so i dont get ... like this? ... python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config protoc --python_out=. .\object_detection\protos\input_reader.proto

No, just the command by itself. Are you following the tutorial by Edjeelectronics?

Yes, i am

I had the same problem until I found this part in his github tutorial:

In the Anaconda Command Prompt, change directories to the \models\research directory:

(tensorflow1) C:> cd C:\tensorflow1\models\research

Then copy and paste the following command into the command line and press Enter:

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

This creates a name_pb2.py file from every name.proto file in the \object_detection\protos folder.

(Note: TensorFlow occassionally adds new .proto files to the \protos folder. If you get an error saying ImportError: cannot import name 'something_something_pb2' , you may need to update the protoc command to include the new .proto files.)

So just go into the research folder and enter:
protoc --python_out=. .\object_detection\protos\input_reader.proto

I did that and it says image_resizer.protos is unused

That's fine. It's just a warning, it will still work :)

Still getting the same error :(

I also get the same error

Try running the python setup.py build and python setup.py install commands again.

Try the following:
protoc --python_out=. .\object_detection\protos\center_net.proto

Try running the python setup.py build and python setup.py install commands again.

I ran "python setup.py build" and "python setup.py install". Again tried this "python train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config". Even though found the same error. please help @navroopsingh1 @Tylersuard

If you get this error "from object_detection.protos import center_net_pb2 as object__detection_dot_protos_dot_center__net__pb2
ImportError: cannot import name 'center_net_pb2'"

Then make sure you are in reaserch directory and run below command :-)
"protoc --python_out=. .\object_detection\protos\center_net.proto"

Tell me if this worked for you. It should work. :-)

I have a question,
@Tylersuard how could you run it in google collab?
at the moment i don't have a good machine, but i don't know how to run it there either. help me please.

@Elq-eng Here you go :) https://colab.research.google.com/drive/1qSbsfomo3GsAxq4Z4386LBtkB12GA9I2?usp=sharing

Make sure to set the runtime to GPU

Thanks man,
How long is it erased?

@Elq-eng what do you mean?

what happens is that i dont have experience in Colab, for that, i dont know how long it takes me to understand step by step, so i understand that Colab resets every day.

@Elq-eng Yes, that's true. Colab resets every 12 hours, or every 24 hours if you have Colab Pro. If you want to learn more about Colab, try using this: https://colab.research.google.com/notebooks/intro.ipynb

can anyone HELP please im still gettin the import error even tho i tried everything i could find, ive tried protoc --python_out=. .\object_detection\protos\center_net.proto this and got 'protoc' is not recognized as an internal or external command' so i added 'c:\Users\s\bin\protoc --python_out=. .\object_detection\protos\center_net.proto' and i still got the import center_net_pb2 error so i tried 'c:\Users\s\bin\protoc --python_out=. .\object_detection\protos\input_reader.proto' and i still got the import error :(((((((((((
edit:im following the edjeelectronics tutorial

@lulu-max Did you set PYTHONPATH, incase you have exited the terminal, try to reset that PATH and type protoc command again.

@anukeshi oh im an idiot and forgot about that thanks,
i just did that and ran the python legacy/train.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_pets.config and didnt get the import error but instead i got this error:

(message_descriptor.full_name, name))
google.protobuf.text_format.ParseError: 132:1 : Message type "object_detection.protos.EvalConfig" has no field named "eval_input_reader".

you must put in the comand protoc --> center_net, copy the follow code, it is modified, befor put the lines code of build and instal, you must make this in the folder research.

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

when i was read this, this is make me confuse but now I get it... this will help you guys with cannot import name "xxxxx"

  1. check folder in directory ...\object_detection\protos and count how many _pb2.py and .protos (don't count __init__.py and __pychance__), if they equal then congratulation this forum not solve that problem, but if not go to no.2

  2. type this on console
    protoc --python_out=. .\object_detection\protos\ YYYY .proto
    what is YYYY..? is the missing .py in \object_detection\protos... to know it check protos and _pb2.py if 1 of protos don't have match, change the YYYY* with that name ( example : I don't have _pb2.py match at anchor_generator.proto, so I type in console protoc --python_out=. .\object_detection\protos\anchor_generator.proto , and so all)

I run the above mentioned commands but it retirns missing input file what should I do please help

Was this page helpful?
0 / 5 - 0 ratings