tensorflow / models

Models and examples built with TensorFlow
Other
76.92k stars 45.81k forks source link

ImportError: cannot import name 'anchor_generator_pb2'. Protobuf doesn't work here. #7890

Open aracnema opened 4 years ago

aracnema commented 4 years ago

when I run this on google colab !python object_detection/builders/model_builder_test.py

I get: Traceback (most recent call last): File "object_detection/builders/model_builder_test.py", line 23, in from object_detection.builders import model_builder File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/builders/model_builder.py", line 20, in from object_detection.builders import anchor_generator_builder File "/usr/local/lib/python3.6/dist-packages/object_detection-0.1-py3.6.egg/object_detection/builders/anchor_generator_builder.py", line 22, in from object_detection.protos import anchor_generator_pb2 ImportError: cannot import name 'anchor_generator_pb2'

when I enter protoc object_detection/protos/*.proto --python_out=. no error occures. What should I do?

thecaffeinedev commented 4 years ago

Can you please share your notebook link?

jarvis-owl commented 4 years ago

are there any *.py files in models/research/object_detection/protos/ ? protoc is quiet calm there. Did you set your $PYTHONPATH correctly?

This guy seemed to have a similar issue and wrote a python script for converting .protos to .py. [Video]

import os
import sys
args = sys.argv
directory = args[1]
protoc_path = args[2]
for file in os.listdir(directory):
    if file.endswith(".proto"):
        os.system(protoc_path+" "+directory+"/"+file+" --python_out=.")

Usage: python use_protobuf.py <path to directory> <path to protoc file> Example: python use_protobuf.py object_detection/protos C:/Users/Gilbert/Downloads/bin/protoc

udithhaputhanthri commented 3 years ago

Here https://github.com/tensorflow/models/tree/master/research/object_detection/protos there is no file called anchor_generator_pb2.py ???

ramunask commented 3 years ago

You can download protoc executable from https://github.com/protocolbuffers/protobuf/releases/tag/v3.14.0, extract somewhere (for example C:/tools/protoc-3.14.0-win64) and in ./models/research folder run following command:

C:/tools/protoc-3.14.0-win64/bin/protoc.exe -I=./ --python_out=./ ./object_detection/protos/*.proto

After this, missing files appears.

tmbenhura commented 3 years ago

You need to generate the *.py files from the protobufs BEFORE you install the object detection package. If you already installed it, just re-run the installation command.