1

I'm trying to install the Tensorflow Object Detection API by following this tutorial. When I got to the end, while trying the python object_detection/builders/model_builder_tf2_test.py command, I got the following error:

Traceback (most recent call last):
  File "object_detection/builders/model_builder_tf2_test.py", line 25, in <module>
    from object_detection.builders import model_builder
  File "/home/deeplearning/model_compression/TFOD-TRT/venv/lib/python3.6/site-packages/object_detection/builders/model_builder.py", line 23, in <module>
    from object_detection.builders import anchor_generator_builder
  File "/home/deeplearning/model_compression/TFOD-TRT/venv/lib/python3.6/site-packages/object_detection/builders/anchor_generator_builder.py", line 27, in <module>
    from object_detection.protos import anchor_generator_pb2
  File "/home/deeplearning/model_compression/TFOD-TRT/venv/lib/python3.6/site-packages/object_detection/protos/anchor_generator_pb2.py", line 5, in <module>
    from google.protobuf.internal import builder as _builder
ImportError: cannot import name 'builder'

These are my system settings:

  • OS: Ubuntu 18.04
  • Python: 3.6
  • Protoc: 3.12.3
  • Tensorflow: 2.6.2
  • CUDA: 11.6
  • cudNN: 8.3.2
  • TensorRT: 8.4.0

Here you can check it:

$ nvidia-smi
Fri Mar 18 15:35:30 2022       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 510.47.03    Driver Version: 510.47.03    CUDA Version: 11.6     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  On   | 00000000:01:00.0 Off |                  N/A |
| N/A   48C    P0    N/A /  N/A |    412MiB /  4096MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1144      G   /usr/lib/xorg/Xorg                 28MiB |
|    0   N/A  N/A      1371      G   /usr/bin/gnome-shell               67MiB |
|    0   N/A  N/A      1622      G   /usr/lib/xorg/Xorg                135MiB |
|    0   N/A  N/A      1798      G   /usr/bin/gnome-shell               24MiB |
|    0   N/A  N/A      2163      G   /usr/lib/firefox/firefox          149MiB |
|    0   N/A  N/A      6459      G   /usr/lib/firefox/firefox            1MiB |
+-----------------------------------------------------------------------------+

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Thu_Feb_10_18:23:41_PST_2022
Cuda compilation tools, release 11.6, V11.6.112
Build cuda_11.6.r11.6/compiler.30978841_0

$ /sbin/ldconfig -N -v $(sed 's/:/ /' <<< $LD_LIBRARY_PATH) 2>/dev/null | grep libcudnn
    libcudnn_cnn_train.so.8 -> libcudnn_cnn_train.so.8.3.2
    libcudnn_adv_train.so.8 -> libcudnn_adv_train.so.8.3.2
    libcudnn_adv_infer.so.8 -> libcudnn_adv_infer.so.8.3.2
    libcudnn_ops_infer.so.8 -> libcudnn_ops_infer.so.8.3.2
    libcudnn_ops_train.so.8 -> libcudnn_ops_train.so.8.3.2
    libcudnn.so.8 -> libcudnn.so.8.3.2
    libcudnn_cnn_infer.so.8 -> libcudnn_cnn_infer.so.8.3.2
(venv) deeplearning@deeplearning:~/model_compression/models/research$ dpkg -l | grep TensorRT
ii  graphsurgeon-tf                                             8.4.0-1+cuda11.6                                amd64        GraphSurgeon for TensorRT package
ii  libnvinfer-bin                                              8.4.0-1+cuda11.6                                amd64        TensorRT binaries
ii  libnvinfer-dev                                              8.4.0-1+cuda11.6                                amd64        TensorRT development libraries and headers
ii  libnvinfer-doc                                              8.4.0-1+cuda11.6                                all          TensorRT documentation
ii  libnvinfer-plugin-dev                                       8.4.0-1+cuda11.6                                amd64        TensorRT plugin libraries
ii  libnvinfer-plugin8                                          8.4.0-1+cuda11.6                                amd64        TensorRT plugin libraries
ii  libnvinfer-samples                                          8.4.0-1+cuda11.6                                all          TensorRT samples
ii  libnvinfer8                                                 8.4.0-1+cuda11.6                                amd64        TensorRT runtime libraries
ii  libnvonnxparsers-dev                                        8.4.0-1+cuda11.6                                amd64        TensorRT ONNX libraries
ii  libnvonnxparsers8                                           8.4.0-1+cuda11.6                                amd64        TensorRT ONNX libraries
ii  libnvparsers-dev                                            8.4.0-1+cuda11.6                                amd64        TensorRT parsers libraries
ii  libnvparsers8                                               8.4.0-1+cuda11.6                                amd64        TensorRT parsers libraries
ii  onnx-graphsurgeon                                           8.4.0-1+cuda11.6                                amd64        ONNX GraphSurgeon for TensorRT package
ii  python3-libnvinfer                                          8.4.0-1+cuda11.6                                amd64        Python 3 bindings for TensorRT
ii  python3-libnvinfer-dev                                      8.4.0-1+cuda11.6                                amd64        Python 3 development package for TensorRT
ii  tensorrt                                                    8.4.0.6-1+cuda11.6                              amd64        Meta package of TensorRT
ii  uff-converter-tf                                            8.4.0-1+cuda11.6                                amd64        UFF converter for TensorRT package

$ protoc --version
libprotoc 3.12.3

pip list
Package                       Version
----------------------------- ---------
absl-py                       0.12.0
apache-beam                   2.37.0
appdirs                       1.4.4
astunparse                    1.6.3
attrs                         21.4.0
avro-python3                  1.10.2
beautifulsoup4                4.10.0
cached-property               1.5.2
cachetools                    4.2.4
certifi                       2021.10.8
charset-normalizer            2.0.12
clang                         5.0
cloudpickle                   2.0.0
colorama                      0.4.4
contextlib2                   21.6.0
crcmod                        1.7
cycler                        0.11.0
Cython                        0.29.28
dataclasses                   0.8
decorator                     5.1.1
dill                          0.3.1.1
dm-tree                       0.1.6
docopt                        0.6.2
fastavro                      1.4.7
flatbuffers                   1.12
gast                          0.4.0
gin-config                    0.5.0
google                        3.0.0
google-api-core               2.7.1
google-api-python-client      2.41.0
google-auth                   1.35.0
google-auth-httplib2          0.1.0
google-auth-oauthlib          0.4.6
google-cloud                  0.34.0
google-pasta                  0.2.0
googleapis-common-protos      1.56.0
grpcio                        1.44.0
h5py                          3.1.0
hdfs                          2.6.0
httplib2                      0.19.1
idna                          3.3
importlib-metadata            4.8.3
importlib-resources           5.4.0
joblib                        1.1.0
kaggle                        1.5.12
keras                         2.6.0
Keras-Preprocessing           1.1.2
kiwisolver                    1.3.1
lvis                          0.5.3
lxml                          4.8.0
Mako                          1.1.6
Markdown                      3.3.6
MarkupSafe                    2.0.1
matplotlib                    3.3.4
neural-structured-learning    1.3.1
numpy                         1.19.5
oauth2client                  4.1.3
oauthlib                      3.2.0
object-detection              0.1
onnx                          1.8.1
onnxruntime                   1.8.0
opencv-python                 4.5.5.64
opencv-python-headless        4.5.5.64
opt-einsum                    3.3.0
orjson                        3.6.1
pandas                        1.1.5
Pillow                        8.2.0
pip                           21.3.1
pkg_resources                 0.0.0
platformdirs                  2.4.0
portalocker                   2.4.0
promise                       2.3
proto-plus                    1.20.3
protobuf                      3.19.4
psutil                        5.9.0
py-cpuinfo                    8.0.0
pyarrow                       6.0.1
pyasn1                        0.4.8
pyasn1-modules                0.2.8
pycocotools                   2.0
pycuda                        2021.1
pydot                         1.4.2
pymongo                       3.12.3
pyparsing                     2.4.7
python-dateutil               2.8.2
python-slugify                6.1.1
pytools                       2022.1.2
pytz                          2021.3
PyYAML                        6.0
regex                         2022.3.15
requests                      2.27.1
requests-oauthlib             1.3.1
rsa                           4.8
sacrebleu                     2.0.0
scikit-learn                  0.24.2
scipy                         1.5.4
sentencepiece                 0.1.96
seqeval                       1.2.2
setuptools                    59.6.0
six                           1.15.0
soupsieve                     2.3.1
tabulate                      0.8.9
tensorboard                   2.6.0
tensorboard-data-server       0.6.1
tensorboard-plugin-wit        1.8.1
tensorflow                    2.6.2
tensorflow-addons             0.14.0
tensorflow-datasets           4.5.2
tensorflow-estimator          2.6.0
tensorflow-hub                0.12.0
tensorflow-io                 0.21.0
tensorflow-io-gcs-filesystem  0.21.0
tensorflow-metadata           1.2.0
tensorflow-model-optimization 0.7.1
tensorflow-text               2.6.0
termcolor                     1.1.0
text-unidecode                1.3
tf-models-official            2.7.1
tf-slim                       1.1.0
tf2onnx                       1.8.1
threadpoolctl                 3.1.0
tqdm                          4.63.0
typeguard                     2.13.3
typing-extensions             3.7.4.3
uritemplate                   4.1.1
urllib3                       1.26.9
Werkzeug                      2.0.3
wheel                         0.37.1
wrapt                         1.12.1
zipp                          3.6.0

What's missing? I've tried reinstalling everything, installing protobuf from source and so on. Tensorflow works, this doesn't.

Thanks for your time, Fran.

EDIT 1

A bit of information that may be important.

I've tried to switch python versions and reinstalling all the NVIDIA/CUDA environment. It seems to have nothing to do with that.

The package named builder should be here:

~/model_compression/TFOD-TRT/venv/lib/python3.8/site-packages/google/protobuf/internal$ ls
_api_implementation.cpython-38-x86_64-linux-gnu.so  __init__.py
api_implementation.py                               message_listener.py
containers.py                                       __pycache__
decoder.py                                          python_message.py
encoder.py                                          type_checkers.py
enum_type_wrapper.py                                well_known_types.py
extension_dict.py                                   wire_format.py

But it's not. Shouldn't the feature resolver do this on it's own?

Edit 2

Add tag for tensorflow-model-garden

  • Same thing happen to me about 'ImportError: cannot import name 'builder''. I noticed that the installation of protobuf was wrong in my case. What I did to this was, installing it to /usr/local as following site says. http://google.github.io/proto-lens/installing-protoc.html And then, adding environment path to .bashrc as this site says like 'export PATH="$PATH:$HOME/.local/bin"' https://grpc.io/docs/protoc-installation/ I hope this will help you too. – Ihmon Apr 10 '22 at 06:55

1 Answers1

0

Got same error msg.

Fortunately, solved after a few tries but i can't point it out exactly. Hope you can solve the issue.

try conda install protobuf==3.14 and check if conda dependencies has libprotobuf and pip dependencies has protobuf.

Below is my case (environment);

# environment.yaml

name: tfod
channels:
  - defaults
dependencies:
  - ca-certificates=2022.07.19=haa95532_0
  - certifi=2022.6.15=py39haa95532_0
  - libprotobuf=3.14.0=h23ce68f_0 ##### this one and (below↓)#####
  - openssl=1.1.1q=h2bbff1b_0
  - pip=22.1.2=py39haa95532_0
  - python=3.9.12=h6244533_0
  - setuptools=61.2.0=py39haa95532_0
  - six=1.16.0=pyhd3eb1b0_1
  - sqlite=3.39.2=h2bbff1b_0
  - tzdata=2022a=hda174b7_0
  - vc=14.2=h21ff451_1
  - vs2015_runtime=14.27.29016=h5e58377_2
  - wheel=0.37.1=pyhd3eb1b0_0
  - wincertstore=0.2=py39haa95532_2
  - zlib=1.2.12=h8cc25b3_2
  - pip:
    - apache-beam==2.40.0
    - astunparse==1.6.3
    - avro-python3==1.10.2
    - cloudpickle==2.1.0
    - contextlib2==21.6.0
    - crcmod==1.7
    - dill==0.3.1.1
    - docopt==0.6.2
    - fastavro==1.5.4
    - flatbuffers==1.12
    - gast==0.4.0
    - google-auth-oauthlib==0.4.6
    - google-pasta==0.2.0
    - grpcio==1.47.0
    - h5py==3.7.0
    - hdfs==2.7.0
    - importlib-metadata==4.12.0
    - keras==2.9.0
    - keras-preprocessing==1.1.2
    - libclang==14.0.6
    - lvis==0.5.3
    - markdown==3.4.1
    - markupsafe==2.1.1
    - numpy==1.22.4
    - oauthlib==3.2.0
    - object-detection==0.1
    - opencv-python==4.6.0.66
    - opt-einsum==3.3.0
    - orjson==3.7.11
    - proto-plus==1.22.0
    - protobuf==3.19.4 ##### this one #####
    - pyarrow==7.0.0
    - pydot==1.4.2
    - pymongo==3.12.3
    - pyparsing==2.4.7
    - requests-oauthlib==1.3.1
    - tensorboard==2.9.1
    - tensorboard-data-server==0.6.1
    - tensorboard-plugin-wit==1.8.1
    - tensorflow==2.9.1
    - tensorflow-estimator==2.9.0
    - tensorflow-io==0.26.0
    - tensorflow-io-gcs-filesystem==0.26.0
    - tensorflow-text==2.9.0
    - tf-models-official==2.9.2
    - werkzeug==2.2.2
    - wrapt==1.14.1
prefix: C:\Users\user\anaconda3\envs\tfod
Henry Lee
  • 1
  • 2