4

I'm trying to use OpenCV in some function which I annotate with some Numba decorators (e.g. nopython=True, parallel=True). I run this on Jetson Xavier which was flashed with Nvidia SDK Manager.

Code is this:

@jit(nopython=True, cache=True, parallel=True)
def decompress(data):
  result = list()
  for d in data:
    cv2_image = cv2.imdecode(d, cv2.IMREAD_COLOR)
    image = np.array(cv2_image)
    result.append(image)
 return result

But I get an error:

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Unknown attribute 'resize' of type Module(<module 'cv2' from '/usr/lib/python2.7/dist-packages/cv2.so'>)

File "./my-script.py", line 297:
            def decompress(data):
                <source elided>
                    cv2_image = cv2.imdecode(d, cv2.IMREAD_COLOR)
                    ^

[1] During: typing of get attribute at /ssd/catkin_workspace/src/semantics-ros-wrapper/src/semseg.py (297)

File "./my-script.py", line 297:
            def decompress(data):
                <source elided>
                    cv2_image = cv2.imdecode(d, cv2.IMREAD_COLOR)
                    ^

This is not usually a problem with Numba itself but instead often caused by
the use of unsupported features or an issue in resolving types.

To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/dev/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html

For more information about typing errors and how to debug them visit:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile

If you think your code should work with Numba, please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new

Is it even possible to use OpenCV with Numba?

I'm using: python2.7 and numba-0.44.0.

Antonio Jurić
  • 541
  • 4
  • 15

1 Answers1

5

Numba does not support OpenCV yet. If you still want it to run on the numpy arrays in your functions you could set nopython=False

This means you will also not be able to set parallel=True

This is from the Numba User Manual:

Numba has two compilation modes: nopython mode and object mode. The former produces much faster code, but has limitations that can force Numba to fall back to the latter. To prevent Numba from falling back, and instead raise an error, pass nopython=True.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Raja
  • 71
  • 1
  • 4