Repository navigation
Description
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- [ x] I am using the latest TensorFlow Model Garden release and TensorFlow 2.
- [ x] I am reporting the issue to the correct repository. (Model Garden official or research directory)
- [ x] I checked to make sure that this issue has not been filed already.
1. The entire URL of the file you are using
https://github.com/tensorflow/models/blob/master/research/object_detection/packages/tf2/setup.py
https://github.com/tensorflow/models/blob/master/official/requirements.txt
2. Describe the bug
I'm installing the Object Detection API with Tensorflow 2 as specified in the Readme here.
However, I encountered an openCV error when trying to run model training using the script model_main_tf2.py, as below:
Traceback (most recent call last):
File "model_main_tf2.py", line 31, in <module>
File "model_main_tf2.py", line 31, in <module>
from object_detection import model_lib_v2from object_detection import model_lib_v2
File "/usr/local/lib/python3.8/dist-packages/object_detection/model_lib_v2.py", line 29, in <module>
File "/usr/local/lib/python3.8/dist-packages/object_detection/model_lib_v2.py", line 29, in <module>
from object_detection import eval_util
from object_detection import eval_util File "/usr/local/lib/python3.8/dist-packages/object_detection/eval_util.py", line 36, in <module>
File "/usr/local/lib/python3.8/dist-packages/object_detection/eval_util.py", line 36, in <module>
from object_detection.metrics import lvis_evaluationfrom object_detection.metrics import lvis_evaluation
File "/usr/local/lib/python3.8/dist-packages/object_detection/metrics/lvis_evaluation.py", line 23, in <module>
File "/usr/local/lib/python3.8/dist-packages/object_detection/metrics/lvis_evaluation.py", line 23, in <module>
from lvis import results as lvis_results
File "/usr/local/lib/python3.8/dist-packages/lvis/__init__.py", line 5, in <module>
from lvis import results as lvis_results
File "/usr/local/lib/python3.8/dist-packages/lvis/__init__.py", line 5, in <module>
from lvis.vis import LVISVisfrom lvis.vis import LVISVis
File "/usr/local/lib/python3.8/dist-packages/lvis/vis.py", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/lvis/vis.py", line 1, in <module>
import cv2import cv2
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 181, in <module>
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 181, in <module>
bootstrap()bootstrap()
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 175, in bootstrap
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 175, in bootstrap
if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
File "/usr/local/lib/python3.8/dist-packages/cv2/__init__.py", line 28, in __load_extra_py_code_for_module
py_module = importlib.import_module(module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
py_module = importlib.import_module(module_name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.8/dist-packages/cv2/mat_wrapper/__init__.py", line 33, in <module>
File "/usr/local/lib/python3.8/dist-packages/cv2/mat_wrapper/__init__.py", line 33, in <module>
cv._registerMatType(Mat)cv._registerMatType(Mat)
AttributeErrorAttributeError: : partially initialized module 'cv2' has no attribute '_registerMatType' (most likely due to a circular import)partially initialized module 'cv2' has no attribute '_registerMatType' (most likely due to a circular import)
NOTE
I believe this is caused by this recent change in the tf-models-official's requirement for opencv-python-headless==4.5.2.52.
3. Steps to reproduce
- Install the Object Detection API with Tensorflow 2 using the Python Package Installation method.
- Run model training by calling the script
model_main_tf2.py.
4. Expected behavior
The opencv-python and opencv-python-headless versions should be the same.
5. Additional context
NOTE
I believe this is caused by this recent change in the tf-models-official's requirement for opencv-python-headless==4.5.2.52.
In the Object Detection API setup.py, the requirements did not specify the version for opencv-python nor for opencv-python-headless. So when the lvis package is installed, the dependant opencv-python version is installed, for which the latest one currently is 4.6.0.66. However, when the tf-models-official is installed, the opencv-python-headless version is pinned to 4.5.2.52. This causes the subsequent import of lvis in the model_main_tf2.py to fail, due to the version mismatch.
Activity
wickeat commentedon Oct 4, 2022
I believe #10791 is also related to this issue.
sineeli commentedon Oct 4, 2022
Hi @wickeat,
I was able to see the mismatch in the colab as well, the gist can be found here. Please provide a gist of next step used for training model using
model_main_tf2.py.in colab so that I can reproduce the same error and expedite the process of rectifying the mismatch.bplotnick commentedon Oct 5, 2022
The bigger issue here is that a library is hard-pinning a dependency version, which makes version resolution practically impossible. If it didn't hard-pin, then you could ensure that those versions matched (though ideally you'd be able to pick one of the two opencv-python packages)
google-ml-butler commentedon Oct 12, 2022
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you.
google-ml-butler commentedon Oct 19, 2022
Closing as stale. Please reopen if you'd like to work on this further.
google-ml-butler commentedon Oct 19, 2022
Are you satisfied with the resolution of your issue?
Yes
No
saberkun commentedon Oct 20, 2022
Reopen: this is an issue that we need to fix.
google-ml-butler commentedon Oct 27, 2022
Closing as stale. Please reopen if you'd like to work on this further.
google-ml-butler commentedon Oct 27, 2022
Are you satisfied with the resolution of your issue?
Yes
No
Removes the version requirement for opencv-python-headless.
google-ml-butler commentedon Oct 28, 2022
Are you satisfied with the resolution of your issue?
Yes
No
wickeat commentedon Dec 9, 2022
There seems to be a regression in the
tf-models-officialversion 2.11 onwards, with theopencv-python-headlesspackage being pinned to 4.5.2.52 again. @sineeli @saberkunlaxmareddyp commentedon Dec 9, 2022
Hi @wickeat,
Opened PR
tf-models-officialversion 2.11 , once PR is merged, issue will be resolved automatically.Thanks.
saberkun commentedon Dec 9, 2022
https://pypi.org/project/tf-models-official/2.11.1/
Released a new package and updated the r2.11 branch. It was missed.
laxmareddyp commentedon Dec 9, 2022
PR is merged
google-ml-butler commentedon Dec 9, 2022
Are you satisfied with the resolution of your issue?
Yes
No