I use https://github.com/AlexeyAB/darknet to run Yolo V3 and darknet is built using OpenCV 3.4.0.
When I tried to run this command ./darknet detector train data/obj.data cfg/objyolov3.cfg darknet53.conv.74 to train my own dataset, with OPENCV = 0 training works successfully, but when I build with OPENCV=1, I got this following error :
Loading weights from darknet53.conv.74...
seen 64
Done!
Learning Rate: 0.001, Momentum: 0.9, Decay: 0.0005
If error occurs - run training with flag: -dont_show
Resizing
896 x 896
./darknet: symbol lookup error: ./darknet: undefined symbol: _ZN9_IplImageC1ERKN2cv3MatE
The chart image showed up but closed immediately, adding -dont_show also not helping. I couldn't find similar problem on the internet, any solution for this?
I know this is very rare to encounter this problem. But I managed to solve it after discussed it with the repo's author. Insted building darknet using make, it works when I built darknet using cmake.
Edit CMakeLists.txt in darknet folder and add this line : SET(OpenCV_DIR /home/<Change this to your OPENCV path installation>/OpenCV-3.4.0/share/OpenCV/)
cmake .
make
Original github issue : https://github.com/AlexeyAB/darknet/issues/2489
Related
I trained a custom YOLOv7 object detection model in Google Colab. I exported it to .onnx file using this command:
python export.py --weights runs/train/exp/weights/best.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.3 --img-size 640 640 --max-wh 640
This is my code to load the model:
import cv2
net = cv2.dnn.readNet('runs/train/exp/weights/best.onnx')
When I run the code above, I get this error:
error: OpenCV(4.6.0) /io/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'handleNode'
> Node [NonMaxSuppression#ai.onnx]:(onnx_node!NonMaxSuppression_370) parse error: OpenCV(4.6.0) /io/opencv/modules/dnn/src/layer_internals.hpp:110: error: (-2:Unspecified error) Can't create layer "onnx_node!NonMaxSuppression_370" of type "NonMaxSuppression" in function 'getLayerInstance'
However, this python code loads the model successfully:
import onnx
onnx_model = onnx.load('runs/train/exp/weights/best.onnx')
onnx.checker.check_model(onnx_model)
So seems like the issue is in OpenCV?
The .onnx file is in the correct directory.
Enviroment:
opencv-python: 4.6.0.66
torch: 1.11.0
onnx: 1.11.0
CUDA: 11.2
My PyTorch was previously version 1.12.0, but I got similar issues too. Then I read somewhere that downgrading to 1.11.0 should fix my problem. It didn't.
I downloaded a pre-exported .onnx file from google and it loaded successfully using the same code. Why can't I do it now?
I am including opencv with custom build parameters in my Yocto image. For that I have an opencv_4.1.0.bbappend recipe, in which I set custom options, specifically FFMPEG. The recipe goes something like this:
DEPENDS += "ffmpeg libpng"
EXTRA_OECMAKE_append += "-DWITH_FFMPEG=ON -DWITH_GTK=OFF" # and some other options
During configure I get cmake errors and can't seem to figure out, how to satisfy the header dependencies. The errors go like this (I assume this is the reason for do_configure to fail):
CheckIncludeFile.c:1:10: fatal error: /home/janos/dev/yocto/build/tmp/work/core2-64-poky-linux/opencv/4.1.0-r0/recipe-sysroot/usr/include/libpng/png.h: No such file or directory
1 | #include </home/janos/dev/yocto/build/tmp/work/core2-64-poky-linux/opencv/4.1.0-r0/recipe-sysroot/usr/include/libpng/png.h>
CheckIncludeFile.c:1:10: fatal error: sys/videoio.h: No such file or directory
1 | #include <sys/videoio.h>
Focusing on the missing png.h header first, I am tempted to depend libpng-dev, as I also would apt install it. But there is no package for it.
When I search oe-pkgdata-util list-pkg-files -p libpng, I can find the header in a libpng-dev package:
...
libpng-dev:
/usr/bin/libpng-config
/usr/bin/libpng16-config
/usr/include/libpng16/png.h
/usr/include/libpng16/pngconf.h
/usr/include/libpng16/pnglibconf.h
/usr/include/png.h
...
...
I can also find it in libpng-src and also ffmpeg-src package (oe-pkgdata-util find-path "*png.h" was my friend). But all of these -dev and -src packages I cannot depend on in DEPENDS.
How can I get my recipe to know those headers?
Target machine is raspberrypi4-64, on which the recipe is configuring and compiling well - it fails when I build for qemux86-64, which I use for testing. Namely, my test command is MACHINE="qemux86-64" bitbake opencv.
It doesn't really answer the question which I though was the question - but this is how the opencv recipe is easily configured:
PACKAGECONFIG = "python3 libav libv4l v4l"
Looking into the opencv 4.1.0 recipe (opencv_4.1.0.bb), I could see that FFMPEG gets enabled with the libav configurable option.
As a result of depending FFMEPG, I had to whitelist "commercial" licenses in my local.conf file:
LICENSE_FLAGS_WHITELIST = "commercial"
Looking into ./build/tmp/work/aarch64-poky-linux/opencv/4.1.0-r0/temp/log.do_configure shows that opencv is correctly configured without GUI, with v4l/v4l2:, FFMPEG, python3, etc.
And so python3 in the resulting image:
import cv2
print(cv2.getBuildInformation())
I have added meta-openembedded recipes in the Yocto project, at Jethro branch OpenCV version is 2.4.
After building while testing the sample applications provided by opencv-samples_2.4.bb gives these samples :
adaptiveskindetector contours facedetect find_obj_calonder morphology mushroom pyramid_segmentation
bgfg_codebook convert_cascade fback_c find_obj_ferns motempl one_way_sample smiledetect
blobtrack_sample delaunay find_obj latentsvmdetect mser_sample polar_transforms tree_engine
but while testing I got this error :
OpenCV Error: Unspecified error (The function is not implemented.
Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you
are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then
re-run cmake or configure script) in cvNamedWindow, file
/home/ymj/opencv/modules/highgui/src/window.cpp, line 516
I have added in local.conf:
IMAGE_INSTALL_append += " opencv opencv-samples python-opencv"
Is anything more needed to get full-fledged opencv operations.
I tried to run the Openpose on darknet with weights and cfg downloaded from this place: https://github.com/lincolnhard/openpose-darknet
This is the error when I tried to create a net in Opencv
modelConfiguration = path to cfg file
modelWeights = path to weights file
darknet = cv2.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
error Traceback (most recent call last)
in ()
----> 1 darknet = cv2.dnn.readNetFromDarknet(modelConfiguration, modelWeights)
error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\darknet\darknet_io.cpp:552: error: (-212:Parsing error) Unsupported activation: relu in function 'cv::dnn::darknet::ReadDarknetFromCfgStream'
The fix is either you install the latest master branch of openCV or OpenCV version 3.4.XX.XX Only these branches support yolo4.
You can install another version of OpenCV by the following snippet:
!pip install opencv-contrib-python==3.4.13.47 --force-reinstall
as you konw, opnecv 4.0.0 does not support the relu activation now.
I found some project faced the same problem, but he adjusted opencv for darknet, Support CNN "relu" and maxpool "VALID", you can reference it.
https://github.com/chineseocr/opencv-for-darknet
hope it will solve your problem.
I am working on Face Recognition. My code was working fine but the results were not that good so I did a little revision and along with some amendements, I updated my opencv-python from 3.4.3 to 3.4.4 and same for the opencv-contrib-python. And now I am getting syntax errors.
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Error: cv2.error: OpenCV(3.4.4) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
And also,
cv2.face.LBPHFaceRecognizer_create()
AttributeError: module 'cv2.cv2' has no attribute 'face'
I didn't get any Errors like this before but after updating, I am getting these. What's the solution.
You can go back to the previous version and try.
pip uninstall opencv-python
pip install opencv-python==3.4.3
the same as opencv-contrib-python.
Then see if your code works.