tanny bhai gamerz
tanny bhai gamerz

Reputation: 1

ImportError: cannot import name 'runtime_version' from 'google.protobuf' in TensorFlow Object Detection API

I'm encountering an ImportError when trying to run the TensorFlow Object Detection API's test script. The error message is:

(tfod) dev@dev:/media/dev/96E0A5D3E0A5BA3F/tfod/models/research$ python object_detection/builders/model_builder_tf2_test.py2024-08-16 17:00:09.356862: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.2024-08-16 17:00:09.397716: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.2024-08-16 17:00:09.398205: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.2024-08-16 17:00:10.211931: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRTTraceback (most recent call last):File "object_detection/builders/model_builder_tf2_test.py", line 24, in <module>from object_detection.builders import model_builderFile "/media/dev/96E0A5D3E0A5BA3F/tfod/models/research/object_detection/builders/model_builder.py", line 23, in <module>from object_detection.builders import anchor_generator_builderFile "/media/dev/96E0A5D3E0A5BA3F/tfod/models/research/object_detection/builders/anchor_generator_builder.py", line 26, in <module>from object_detection.protos import anchor_generator_pb2File "/media/dev/96E0A5D3E0A5BA3F/tfod/models/research/object_detection/protos/anchor_generator_pb2.py", line 9, in <module>from google.protobuf import runtime_version as _runtime_versionImportError: cannot import name 'runtime_version' from 'google.protobuf' (/home/dev/anaconda3/envs/tfod/lib/python3.8/site-packages/google/protobuf/init.py)

Steps to Reproduce:

  1. Clone the TensorFlow models repository:

    git clone https://github.com/tensorflow/models.git
    cd models/research/
    
  2. pip install tensorflow==2.11.0
    pip install protobuf==3.20.3
    
  3. python object_detection/builders/model_builder_tf2_test.py
    

Expected Result: The script should execute without errors.

Actual Result: I receive the following ImportError:

ImportError: cannot import name 'runtime_version' from 'google.protobuf' (/home/dev/anaconda3/envs/tfod/lib/python3.8/site-packages/google/protobuf/__init__.py)

Environment:

What I Have Tried:

Question: How can I resolve this ImportError with google.protobuf? Are there specific compatibility issues between TensorFlow and protobuf versions that I need to address, or is there a known fix for this error?

Upvotes: 0

Views: 2586

Answers (1)

DazWilkin
DazWilkin

Reputation: 40326

Generally you should permit dependencies (tensorflow depends on protobuf) to be resolved by the tooling.

Thanks to your comprehensive question, I was able to repro your issue with one difference:

python3 -m venv venv
source venv/bin/activate

python3 -m pip install tensorflow==2.11.0

And then:

python3 -m pip freeze | grep protobuf
protobuf==3.19.6

I looked but was unable to find a change that would throw the runtime_version error but Python protobuf has changed quite significantly over time (before 3.19.6 but see Changes announced 6th May 2022.

I think the code will work if you don't pip install protobuf==3.20.3

I don't understand why different versions were released on the same day (29-Sep-2022):

Release GitHub PyPi
3.20.3 X X
3.19.6 X X

Upvotes: 0

Related Questions