sowson / darknet

Darknet on OpenCL Convolutional Neural Networks on OpenCL on Intel & NVidia & AMD & Mali GPUs for macOS & GNU/Linux & Windows & FreeBSD
http://pjreddie.com/darknet/
Other
187 stars 31 forks source link

cv::Exception matrix_wrap.cpp:771: error: (-215:Assertion failed) (flags & FIXED_TYPE) != 0 in function 'type' #40

Closed Grench6 closed 3 years ago

Grench6 commented 3 years ago

The error can be reproduced by following the setup commands in a fresh and clean installation of Ubuntu 20.04.1 LTS.

After compiling and building everything, nothing seems wrong at all... until you try to use darknet:

user@user-pc:~/github/darknet$ ./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
Device IDs: 1
Device ID: 0
Device name: Ellesmere
Device vendor: Advanced Micro Devices, Inc.
Device opencl availability: OpenCL 1.2 AMD-APP (3180.7)
Device opencl used: 3180.7
Device double precision: YES
Device max group size: 256
Device address bits: 64
layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   608 x 608 x   3   ->   608 x 608 x  32  0.639 BFLOPs
    1 conv     64  3 x 3 / 2   608 x 608 x  32   ->   304 x 304 x  64  3.407 BFLOPs
   [...]
  105 conv    255  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 255  0.754 BFLOPs
  106 yolo
Loading weights from yolov3.weights...Done!
data/dog.jpg: Predicted in 1.640484 seconds.
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.12) /home/user/opencv-3.4.12/modules/core/src/matrix_wrap.cpp:771: error: (-215:Assertion failed) (flags & FIXED_TYPE) != 0 in function 'type'

Aborted (core dumped)
user@user-pc:~/github/darknet$

I already tried downgrading opencv to 3.4.0 as @AlexeyAB proposed for his repo in an issue:

This is a bug in OpenCV 3.4.1 C API Use OpenCV 3.4.0

Also found this similar issue:

I can see you are using OpenCV 3.4.1, there is currently a bug in C API Use OpenCV 3.4.0 or lower

but it threw another error (which had something to do with an unimplemented method of a cvWindow or something like that).

I don't know a thing about the OpenCV API, however, your project seems to be using the good C++ API and not the C deprecated one (read from here), so I just don't get what its wrong...

Grench6 commented 3 years ago

Some changes I suggest to the setup for Ubuntu:

  1. Add sudo apt install gfortran
  2. Replace ./amdgpu-install –pro –opencl=pal,legacy -y with ./amdgpu-pro-install -y --opencl=pal,legacy
  3. Replace sudo cp cp library/libclBLAS.so.2.12.0 /usr/lib/x86_64-linux-gnu/libclBLAS.so.2.12.0 with sudo cp library/libclBLAS.so.2.12.0 /usr/lib/x86_64-linux-gnu/libclBLAS.so.2.12.0
  4. Add sudo ldconfig
  5. Fix cat Makefile.bak | sed ‘s/NVIDIA=1/NVIDIA=0/g’ | sed ‘s/AMD=0/AMD=1/g’ > Makefile not working, had to change the Makefile with gedit.

Cheers

sowson commented 3 years ago

@Grench6 Thank you very much, overall it works or not? Thx!

Grench6 commented 3 years ago

Hello! To be able to determine if darknet works in the "overall" meaning of the word I decided to do the following:

Grench6 commented 3 years ago

PS: Now I see the error in

Fix cat Makefile.bak | sed ‘s/NVIDIA=1/NVIDIA=0/g’ | sed ‘s/AMD=0/AMD=1/g’ > Makefile not working, had to change the Makefile with gedit.

For some reason the command has instead of '. The correct one is: cat Makefile.bak | sed 's/NVIDIA=1/NVIDIA=0/g' | sed 's/AMD=0/AMD=1/g' > Makefile

Grench6 commented 3 years ago

Okay, I found a way to make it work:

  1. Install the following packages before building OpenCV: sudo apt install libgtk2.0-dev libcanberra-gtk-module libcanberra-gtk0
  2. Downgrade OpenCV (use 3.4.0 instead of 3.4.12) wget https://github.com/opencv/opencv/archive/3.4.0.tar.gz

And then OpenCV should work as expected with darknet. The main issue with 3.4.0 version was the Gimp Toolkit components missing.


I could not find a way to make it work with OpenCV3.4.12 as I kept getting the exact same error:

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(3.4.12) /home/user/clBLAS-2.12-sowson/src/build/opencv-3.4.12/modules/core/src/matrix_wrap.cpp:771: error: (-215:Assertion failed) (flags & FIXED_TYPE) != 0 in function 'type'

Aborted (core dumped)

I suggest to include the installation of the Gimp Toolkit packages (described at the beginning) and use OpenCV 3.4.0 in the setup instructions.