Search code examples
tensorflowmachine-learningcomputer-visionobject-detectionmodulenotfounderror

tenserflow.compact module not found


I am getting error tensorflow.compact module not found after importing the tensorflow

import tensorflow as tf
from object_detection.utils import config_util

And the error I am getting is

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

File D:\OBJECT DETECTION\TFODCourse\tfod\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\utils\config_util.py:24
     21 import os
     23 from google.protobuf import text_format
---> 24 import tensorflow.compat.v1 as tf
     26 from tensorflow.python.lib.io import file_io
     28 from object_detection.protos import eval_pb2
     ModuleNotFoundError: No module named 'tensorflow.compat'    ```


Solution

  • The reason why you see this error should be related with tensorflow version.

    import tensorflow.compat.v1 as tf
    

    It means to use module in older versions of TensorFlow to provide compatibility with TensorFlow 1.x code.

    However, for certain version of tensorflow, it may remove older support for your module.

    One solution is to downgrade your tensorflow version, or check whether related support for object_detection in your current version