Ask Your Question

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

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

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

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(
    at InheritClass.ObjectDetectionHelper.detect(
    at DetectionCar.DetectCar.detect(
    at InheritClass.ObjectDetectionHelper.detect(
    at InheritClass.ObjectDetectionHelper.detect_directory(
    at DetectionCar.DetectCar.main(
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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

berak gravatar image

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

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


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 -0500 )edit

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

git pull upstream 3.4


git clone -b 3.4
berak gravatar imageberak ( 2018-09-06 02:52:16 -0500 )edit

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

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

Question Tools

1 follower


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

Seen: 341 times

Last updated: Sep 06 '18