tensorflow / models

Models and examples built with TensorFlow
Other
77.22k stars 45.75k forks source link

Error: cannot import name "center_net_pb2" #8721

Closed Tylersuard closed 4 years ago

Tylersuard commented 4 years ago

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 objectdetection_dot_protos_dot_centernet__pb2 ImportError: cannot import name 'center_net_pb2'

-I am using tensorflow 1

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

11PedroMiguel commented 4 years ago

did you manage to solve the problem?

Tylersuard commented 4 years ago

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

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

11PedroMiguel commented 4 years ago

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

Tylersuard commented 4 years ago

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

11PedroMiguel commented 4 years ago

Yes, i am

Tylersuard commented 4 years ago

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.)

Tylersuard commented 4 years ago

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

11PedroMiguel commented 4 years ago

I did that and it says image_resizer.protos is unused

Tylersuard commented 4 years ago

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

11PedroMiguel commented 4 years ago

Still getting the same error :(

rahul21rajendran commented 4 years ago

I also get the same error

Tylersuard commented 4 years ago

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

navroopsingh1 commented 4 years ago

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

mdjunaidahmed0123 commented 4 years ago

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

mdjunaidahmed0123 commented 4 years ago

If you get this error "from object_detection.protos import center_net_pb2 as objectdetection_dot_protos_dot_centernet__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. :-)

Elq-eng commented 4 years ago

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.

Tylersuard commented 4 years ago

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

Make sure to set the runtime to GPU

Elq-eng commented 4 years ago

Thanks man, How long is it erased?

Tylersuard commented 4 years ago

@Elq-eng what do you mean?

Elq-eng commented 4 years ago

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.

SudoPseudo commented 4 years ago

@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

BringMeyourteeth commented 4 years ago

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

anukeshi commented 4 years ago

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

BringMeyourteeth commented 4 years ago

@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".

emilio1195 commented 4 years ago

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

neversgb commented 4 years ago

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)

akshilsharma003 commented 4 years ago

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

sanaz-rasti commented 3 years ago

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

This solved the issue! THANK YOU!

swapnilghule commented 2 years ago

@Tylersuard Hey can u plz share the setup.py file.

SudoPseudo commented 2 years ago

Hello Swapnil. I did not change the setup.py file, I just used the one that came with the repo. A little tip: it’s a good idea to use PyTorch instead of Tensorflow, and to only try projects that were updated in the last 6 months to 1 year. That is because software changes so fast, a program that is 2 years old probably will not work anymore.

On Wed, Feb 2, 2022 at 7:47 AM, Swapnil Ghule @.***> wrote:

@.***(https://github.com/Tylersuard) Hey can u plz share the setup.py file.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>

swapnilghule commented 2 years ago

I getting thus kind of error while running python setup.py install

`` ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print('path not found, image_id = ', self._cur_world, self._cur_image_id)?

File "build\bdist.win-amd64\egg\cognitive_planning\train_supervised_active_vision.py", line 185 print inputs ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(inputs)?

File "build\bdist.win-amd64\egg\cognitive_planning\viz_active_vision_dataset_main.py", line 98 print world ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(world)? ``