Skip to content

Mismatch in opencv-python and opencv-python-headless versions #10800

Closed

Description

@wickeat

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

  1. Install the Object Detection API with Tensorflow 2 using the Python Package Installation method.
  2. 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

  1. added
    models:official
    type:bug
    on Oct 4, 2022
  2. wickeat commented on Oct 4, 2022

    @wickeat
    Author

    I believe #10791 is also related to this issue.

  3. self-assigned this
    on Oct 4, 2022
  4. sineeli commented on Oct 4, 2022

    @sineeli
    Contributor

    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.

  5. added
    stat:awaiting response
    on Oct 4, 2022
  6. bplotnick commented on Oct 5, 2022

    @bplotnick

    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)

  7. google-ml-butler commented on Oct 12, 2022

    @google-ml-butler

    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.

  8. google-ml-butler commented on Oct 19, 2022

    @google-ml-butler

    Closing as stale. Please reopen if you'd like to work on this further.

  9. google-ml-butler commented on Oct 19, 2022

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

  10. saberkun commented on Oct 20, 2022

    @saberkun
    Member

    Reopen: this is an issue that we need to fix.

  11. google-ml-butler commented on Oct 27, 2022

    @google-ml-butler

    Closing as stale. Please reopen if you'd like to work on this further.

  12. google-ml-butler commented on Oct 27, 2022

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

  13. google-ml-butler commented on Oct 28, 2022

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

  14. wickeat commented on Dec 9, 2022

    @wickeat
    Author

    There seems to be a regression in the tf-models-official version 2.11 onwards, with the opencv-python-headless package being pinned to 4.5.2.52 again. @sineeli @saberkun

  15. self-assigned this
    on Dec 9, 2022
  16. laxmareddyp commented on Dec 9, 2022

    @laxmareddyp
    Collaborator

    Hi @wickeat,

    Opened PR tf-models-official version 2.11 , once PR is merged, issue will be resolved automatically.

    Thanks.

  17. saberkun commented on Dec 9, 2022

    @saberkun
    Member

    https://pypi.org/project/tf-models-official/2.11.1/
    Released a new package and updated the r2.11 branch. It was missed.

  18. laxmareddyp commented on Dec 9, 2022

    @laxmareddyp
    Collaborator

    PR is merged

  19. google-ml-butler commented on Dec 9, 2022

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

models:officialstalestat:awaiting responsetype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions