0

I'm new to opencv.js and have a trouble with is as below:

let utils = new Utils('errorMessage');
    let cfg = 'yolo_file/test.cfg';
    let weights = 'yolo_file/test.weights';
    utils.createFileFromUrl('cfg', cfg, () => {
      utils.createFileFromUrl('weights', weights, () => {
        let img=cv.imread('imageSrc');
        let blob = cv.blobFromImage(img, 1/255, new cv.Size(800, 800), new cv.Scalar(0, 0, 0),true,false);
        let net = cv.readNet('cfg','weights');
        net.setInput(blob);
        let prob = net.forward();
        console.log(prob);
        //console.log(blob);
        //net.setInput(blob);
        //outs = net.forward(['yolo_82', 'yolo_94', 'yolo_106']);

      });
});

This code will get an error on this line let prob = net.forward();. The error detail is "Uncaught 6575912".

Can you suggest me how to resolve it?

Itiel Maimon
  • 834
  • 2
  • 9
  • 26

1 Answers1

0

In Yolo, each layer has an output so you need to specify the layers you want to forward. In your case it'd be something like this:

let outs = new cv.MatVector()
net.forward2(outs, ['yolo_82', 'yolo_94', 'yolo_106'])

Unfortunately, though, you cannot get the layer names from JavaScript as getUnconnectedOutLayersNames is not exported, so you either have to hard code it or change the source code and compile from source.

  • I tried this with YOLOv4 (though with the `layer_names = ["yolo_139", "yolo_150", "yolo_161"]`), and I'm still getting the Uncaught error. Any ideas what might be wrong? – Nathan Jun 24 '22 at 22:25
  • I posted a question about it here: https://stackoverflow.com/questions/72749914/yolov4-detection-in-opencv-js-causing-uncaught-exception – Nathan Jun 24 '22 at 22:25
  • I know this answer was a while ago, so this is a long shot, but do you know how to leverage the outs MatVector? I extracted a few Mats from them, but not sure how to get information about the dnn results from the Mat. – Nathan Jul 04 '22 at 21:35