Cannot import name 'config_util_tfod' from 'object_detection.utils'

I’m running the code:

import tensorflow as tf
from object_detection.utils import config_util_tfod
from object_detection.protos import pipeline_pb2
from google.protobuf import text_format

But I get the following error:

ImportError Traceback (most recent call last)
Cell In[61], line 2
1 import tensorflow as tf
----> 2 from object_detection.utils import config_util_tfod
3 from object_detection.protos import pipeline_pb2
4 from google.protobuf import text_format

ImportError: cannot import name ‘config_util_tfod’ from ‘object_detection.utils’ (C:\Users\Rysa\Coding\TFODCourse\tfod\lib\site-packages\object_detection-0.1-py3.8.egg\object_detection\utils_init_.py)

How would I be able to solve it?

@Rysa_Batas,

Welcome to the Tensorflow Forum!

ImportError: cannot import name ‘config_util_tfod’ from ‘object_detection.utils’

Here the module name has changed or if the version of the object detection library you are using does not have that specific module.

It seems you are not using an officially supported object detection model. I recommend using the ‘tf-models-official’ library and following the tutorial at Object detection with Model Garden  |  TensorFlow Core.

Thank you!

1 Like

Thanks for the warm welcome!

I’m actually using the official object detection model following nicknochnack’s tutorial.

nicknochnack/TFODCourse (github.com)
Here’s the code it uses to install the object detection model:

if not os.path.exists(os.path.join(paths['APIMODEL_PATH'], 'research', 'object_detection')):
    !git clone https://github.com/tensorflow/models {paths['APIMODEL_PATH']}
# Install Tensorflow Object Detection 
if os.name=='posix':  
    !apt-get install protobuf-compiler
    !cd Tensorflow/models/research && protoc object_detection/protos/*.proto --python_out=. && cp object_detection/packages/tf2/setup.py . && python -m pip install . 
    
if os.name=='nt':
    url="https://github.com/protocolbuffers/protobuf/releases/download/v3.15.6/protoc-3.15.6-win64.zip"
    wget.download(url)
    !move protoc-3.15.6-win64.zip {paths['PROTOC_PATH']}
    !cd {paths['PROTOC_PATH']} && tar -xf protoc-3.15.6-win64.zip
    os.environ['PATH'] += os.pathsep + os.path.abspath(os.path.join(paths['PROTOC_PATH'], 'bin'))   
    !cd Tensorflow/models/research && protoc object_detection/protos/*.proto --python_out=. && copy object_detection\\packages\\tf2\\setup.py setup.py && python setup.py build && python setup.py install
    !cd Tensorflow/models/research/slim && pip install -e .

But I get lost whenever I’m installing it. Here’s another error I’m frequently encountering:

Traceback (most recent call last):
File “Tensorflow\models\research\object_detection\builders\model_builder_tf2_test.py”, line 21, in
import tensorflow.compat.v1 as tf
ModuleNotFoundError: No module named ‘tensorflow.compat’

I would really appreciate it if you could help. I’m still new to Tensorflow and would like to enhance my understanding of it. Thank you!

@Rysa_Batas,

We are not supporting research models at this point of time.

As mentioned above, we have come up with a new collection of official models with improved speed and performance. For more details please refer to TensorFlow Official Models.

If you are still looking for instructions on how to setup research models

import os
import pathlib

# Clone the tensorflow models repository if it doesn't already exist
if "models" in pathlib.Path.cwd().parts:
  while "models" in pathlib.Path.cwd().parts:
    os.chdir('..')
elif not pathlib.Path('models').exists():
  !git clone --depth 1 https://github.com/tensorflow/models

# Install the Object Detection API
%%bash
cd models/research/
protoc object_detection/protos/*.proto --python_out=.
cp object_detection/packages/tf2/setup.py .
python -m pip install .

Thank you!

where you able to find the solution for this ? i am exactly facing the same issue, please help me out