Opencv DNN yolov8 error

Hello! I was trying to use the onnx model frame work with the DNN reader however it was unable to read the file. This is on android. Here is the code and the error:

CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.7.0-dev) /home/ci/opencv/modules/dnn/src/torch/THDiskFile.cpp:496: error: (-2:Unspecified error) cannot open in mode r in function ‘THDiskFile_new’
at org.opencv.dnn.Dnn.readNetFromTorch_2(Native Method)
at org.opencv.dnn.Dnn.readNetFromTorch(
at com.qualcomm.robotcore.eventloop.opmode.OpMode.internalRunOpMode(
at com.qualcomm.robotcore.eventloop.opmode.OpModeInternal.lambda$internalInit$1$com-qualcomm-robotcore-eventloop-opmode-OpModeInternal(
at com.qualcomm.robotcore.eventloop.opmode.OpModeInternal$$$$SyntheticClass)
at com.qualcomm.robotcore.util.ThreadPool.logThreadLifeCycle(
at com.qualcomm.robotcore.eventloop.opmode.OpModeInternal.lambda$internalInit$2$com-qualcomm-robotcore-eventloop-opmode-OpModeInternal(

the code:

private final String model = "vision/";
public DeepNeuralNetworkProcessor() { = Dnn.readNetFromTorch(model);

Is it a compatibility issue with yolov8?

opencv’s dnn cannot read *.pt files, you have to export it to *.onnx before loading

also, where do you try to load this from ?
(you can’t simply put this into assets or similar compressed folders inside your apk)

I believe this was my issue. I tried running onnx but I need to load it to the sdcard so I can get access. I will try that next.

1 Like