Ask Your Question
0

Darknet-Yolo: java.lang.Exception: unknown exception (org.opencv.dnn.Net.forward_4)

asked 2018-09-05 23:18:09 -0600

updated 2018-09-06 00:14:03 -0600

berak gravatar image

In OpenCV-Yolo

I use the following function to use the (.cfg) and (.weights) file for object detection in Java

net = Dnn.readNetFromDarknet(cfg, weights);

    float scale = 1.0F / 255.0F;
    Mat inputBlob = Dnn.blobFromImage(resized, scale, sz, new Scalar(0), false, false);
    net.setInput(inputBlob, "data");

    System.out.println("Detect Classes: " + classes_names.length);

    java.util.List<Mat> result = new java.util.ArrayList<Mat>(2);
    java.util.List<java.lang.String> outBlobNames = new java.util.ArrayList<java.lang.String>(2);
    outBlobNames.add(0, "yolo_16");
    outBlobNames.add(1, "yolo_23");
    net.forward(result, outBlobNames);

    Mat result_1 = result.get(0);
    Mat result_2 = result.get(1);

    for (Mat mat : result) {
        ExtractBeanFromMat(mat, im, frame, im_copy);
    }

The following is the exception log:

Detect Classes: 2

java.lang.Exception: unknown exception
    at org.opencv.dnn.Net.forward_4(Native Method)
    at org.opencv.dnn.Net.forward(Net.java:333)
    at InheritClass.ObjectDetectionHelper.detect(ObjectDetectionHelper.java:134)
    at DetectionCar.DetectCar.detect(DetectCar.java:26)
    at InheritClass.ObjectDetectionHelper.detect(ObjectDetectionHelper.java:94)
    at InheritClass.ObjectDetectionHelper.detect_directory(ObjectDetectionHelper.java:227)
    at DetectionCar.DetectCar.main(DetectCar.java:31)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-09-05 23:51:17 -0600

berak gravatar image

updated 2018-09-06 01:05:18 -0600

that's a bug, and not your fault, have a look at this recent issue

(you need to update your opencv src to the latest 3.4 branch and rebuild)

edit flag offensive delete link more

Comments

I have been update opencv libs to the latest 3.4.3 branch and rebuild

The Error is the same

Ivan Lee gravatar imageIvan Lee ( 2018-09-06 02:03:46 -0600 )edit

sorry, but the fix went in later than the 3.4.3 release, so you need to

git pull upstream 3.4

or

git clone -b 3.4 https://github.com/opencv
berak gravatar imageberak ( 2018-09-06 02:52:16 -0600 )edit
1

actually, all you need to do is remove a (here and rebuild

berak gravatar imageberak ( 2018-09-06 02:56:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-09-05 23:16:26 -0600

Seen: 644 times

Last updated: Sep 06 '18