Cannot import name 'model_lib_v2' from 'object_detection'

Viewed 10649

I'm trying to train TF2 for object detection. When I run model_main_tf2.py, I get the following error:

Traceback (most recent call last):
  File "C:\Python_venv\trained_models\model_main_tf2.py", line 32, in <module>
    from object_detection import model_lib_v2
ImportError: cannot import name 'model_lib_v2' from 'object_detection' (c:\Python_venv\tensorflow\lib\site-packages\object_detection\__init__.py)

How do I install model_lib_v2?

I tried reinstalling TF and reinstalling TensorFlow-object-detection-API but no luck. I went all over the internet looking for answers.

I found: https://github.com/tensorflow/models/issues/7920 But they don't say how to install model_lib_v2

Unfortunately I cannot use TF1, the goal is to use TF2.

2 Answers

You should be able to just go to line 32 in "C:\Python_venv\trained_models\model_main_tf2.py" and remove "from object_detection", since you are already inside the package.

replace:

"from object_detection import model_lib_v2"

by:

"import model_lib_v2"

Related