How to fix this Import error problem when training a model in google colab

Traceback (most recent call last):
File “model_main_tf2.py”, line 31, in
from object_detection import model_lib_v2
File “/content/drive/MyDrive/ Tf2/object_detection/object_detection/model_lib_v2.py”, line 29, in
from object_detection import eval_util
File “/content/drive/MyDrive/ Tf2/object_detection/object_detection/eval_util.py”, line 35, in
from object_detection.metrics import coco_evaluation
File “/content/drive/MyDrive/ Tf2/object_detection/object_detection/metrics/coco_evaluation.py”, line 28, in
from object_detection.utils import object_detection_evaluation
File “/content/drive/MyDrive/ Tf2/object_detection/object_detection/utils/object_detection_evaluation.py”, line 46, in
from object_detection.utils import label_map_util
File “/content/drive/MyDrive/ Tf2/object_detection/object_detection/utils/label_map_util.py”, line 29, in
from object_detection.protos import string_int_label_map_pb2
File “/content/drive/MyDrive/ Tf2/object_detection/object_detection/protos/string_int_label_map_pb2.py”, line 5, in
from google.protobuf.internal import builder as _builder
ImportError: cannot import name ‘builder’ from ‘google.protobuf.internal’ (/usr/local/lib/python3.7/dist-packages/google/protobuf/internal/init.py)

You need to upgrade to the latest version of the protobuf package as shown below

!pip install --upgrade protobuf

I have the same Error and It doesn’t work

@Mohamed_Amr, Please share standalone code to replicate your issue? Thank you.

Traceback (most recent call last):
File “Tensorflow\models\research\object_detection\model_main_tf2.py”, line 31, in
from object_detection import model_lib_v2
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\model_lib_v2.py”, line 29, in
from object_detection import eval_util
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\eval_util.py”, line 35, in
from object_detection.metrics import coco_evaluation
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\metrics\coco_evaluation.py”, line 25, in
from object_detection.metrics import coco_tools
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\object_detection-0.1-py3.6.egg\object_detection\metrics\coco_tools.py”, line 51, in
from pycocotools import coco
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\pycocotools\coco.py”, line 49, in
import matplotlib.pyplot as plt
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\pyplot.py”, line 2336, in
switch_backend(rcParams[“backend”])
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\pyplot.py”, line 276, in switch_backend
class backend_mod(matplotlib.backend_bases.Backend):
File “C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\pyplot.py”, line 277, in backend_mod
locals().update(vars(importlib.import_module(backend_name)))
File "C:\Users\C.m™\AppData\Local\Programs\Python\Python36\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named ‘matplotlib_inline’

Please try to install matplotlib-inline

pip install matplotlib-inline

Thanks for sharing the error stack trace. For quick troubleshooting please share the complete standalone code to replicate your issue reported above.

Greetings! I’m also unable to start training with the module.
Can you suggest a solution?

Traceback (most recent call last):
File “/content/models/research/object_detection/model_main_tf2.py”, line 30, in
import tensorflow.compat.v2 as tf
File “/usr/local/lib/python3.7/dist-packages/tensorflow/init.py”, line 37, in
from tensorflow.python.tools import module_util as _module_util
File “/usr/local/lib/python3.7/dist-packages/tensorflow/python/init.py”, line 37, in
from tensorflow.python.eager import context
File “/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/context.py”, line 29, in
from tensorflow.core.framework import function_pb2
File “/usr/local/lib/python3.7/dist-packages/tensorflow/core/framework/function_pb2.py”, line 16, in
from tensorflow.core.framework import attr_value_pb2 as tensorflow_dot_core_dot_framework_dot_attr__value__pb2
File “/usr/local/lib/python3.7/dist-packages/tensorflow/core/framework/attr_value_pb2.py”, line 16, in
from tensorflow.core.framework import tensor_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__pb2
File “/usr/local/lib/python3.7/dist-packages/tensorflow/core/framework/tensor_pb2.py”, line 16, in
from tensorflow.core.framework import resource_handle_pb2 as tensorflow_dot_core_dot_framework_dot_resource__handle__pb2
File “/usr/local/lib/python3.7/dist-packages/tensorflow/core/framework/resource_handle_pb2.py”, line 16, in
from tensorflow.core.framework import tensor_shape_pb2 as tensorflow_dot_core_dot_framework_dot_tensor__shape__pb2
File “/usr/local/lib/python3.7/dist-packages/tensorflow/core/framework/tensor_shape_pb2.py”, line 42, in
serialized_options=None, file=DESCRIPTOR),
File “/usr/local/lib/python3.7/dist-packages/google/protobuf/descriptor.py”, line 560, in new
_message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:

  1. Downgrade the protobuf package to 3.20.x or lower.
  2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
1 Like

Please provide standalone code to reproduce the issue reported above? Thank you.