airctic / icevision

An Agnostic Computer Vision Framework - Pluggable to any Training Library: Fastai, Pytorch-Lightning with more to come
https://airctic.github.io/icevision/
Apache License 2.0
843 stars 149 forks source link

Import Error running colab tutorial notebooks #1012

Closed potipot closed 2 years ago

potipot commented 2 years ago

🐛 Bug

We get an import error when running icevision tutorial notebooks in colab.

ImportError                               Traceback (most recent call last)

<ipython-input-2-8386f003167a> in <module>()
----> 1 from icevision.all import *
      2 
      3 _ = icedata.ochuman.load_data()

7 frames

/usr/local/lib/python3.7/dist-packages/icevision/__init__.py in <module>()
----> 1 from icevision.utils import *
      2 from icevision.core import *
      3 from icevision import parsers
      4 from icevision import tfms
      5 from icevision.data import *

/usr/local/lib/python3.7/dist-packages/icevision/utils/__init__.py in <module>()
----> 1 from icevision.utils.utils import *
      2 from icevision.utils.io import *
      3 from icevision.utils.indexable_dict import *
      4 from icevision.utils.torch_utils import *
      5 from icevision.utils.imageio import *

/usr/local/lib/python3.7/dist-packages/icevision/utils/utils.py in <module>()
     19 ]
     20 
---> 21 from icevision.imports import *
     22 
     23 

/usr/local/lib/python3.7/dist-packages/icevision/imports.py in <module>()
      1 import sys, os, re, shutil, typing, itertools, operator, math, warnings, json, random
----> 2 import functools, io, cv2, mimetypes, torch, torchvision, dataclasses, zipfile, pickle
      3 import PIL
      4 from copy import copy, deepcopy
      5 

/usr/local/lib/python3.7/dist-packages/google/colab/_import_hooks/_cv2.py in load_module(self, name)
     79 
     80     module_info = imp.find_module(name, self.path)
---> 81     cv_module = imp.load_module(name, *module_info)
     82 
     83     if not previously_loaded:

/usr/lib/python3.7/imp.py in load_module(name, file, filename, details)
    242             return load_dynamic(name, filename, file)
    243     elif type_ == PKG_DIRECTORY:
--> 244         return load_package(name, filename)
    245     elif type_ == C_BUILTIN:
    246         return init_builtin(name)

/usr/lib/python3.7/imp.py in load_package(name, path)
    214         return _exec(spec, sys.modules[name])
    215     else:
--> 216         return _load(spec)
    217 
    218 

/usr/local/lib/python3.7/dist-packages/cv2/__init__.py in <module>()
      7 
      8 from .cv2 import *
----> 9 from .cv2 import _registerMatType
     10 from . import mat_wrapper
     11 from . import gapi

ImportError: cannot import name '_registerMatType' from 'cv2.cv2' (/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so)

To Reproduce Try and run installation and import in the notebook https://colab.research.google.com/github/airctic/icevision/blob/master/notebooks/negative_samples.ipynb

Desktop (please complete the following information):

potipot commented 2 years ago

Apparently the issue comes from opencv-python versions mismatch. When discovering isntalled packages:

pip list | grep "opencv"

output:

opencv-contrib-python         4.1.2.30
opencv-python                 4.1.2.30
opencv-python-headless        4.5.5.62

opencv-python is required by many packages but most recent version is needed by yolov5-icevision: opencv-python>=4.1.2

source

opencv-python-headless is only required by albumentations and possibly thats when it gets installed.
In setup.py of version 1.0.3 we find:

CHOOSE_INSTALL_REQUIRES = [
    (
        ("opencv-python>=4.1.1", "opencv-contrib-python>=4.1.1", "opencv-contrib-python-headless>=4.1.1"),
        "opencv-python-headless>=4.1.1",
    )
]

Not sure what is the actual cause of the problem. opencv-python-headless is not installed in the pure colab environment.

workaround

A current workaround I've found is to manually install opencv-python-headless to the coherent version:

pip install opencv-python-headless==4.1.2.30
fstroth commented 2 years ago

Should we add the workaround to the notebooks or to the install script? Btw do we still need the colab_install script?

FraPochetti commented 2 years ago

I'd say to the install script? And no, I don't think we need the colab_install script, do we?

potipot commented 2 years ago

As Farid noted we can delete install_colab.sh so add that workaround to the script it is then.