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(Dnn.java:313)
at org.firstinspires.ftc.teamcode.vision.DeepNeuralNetworkProcessor.(DeepNeuralNetworkProcessor.java:28)
at org.firstinspires.ftc.teamcode.vision.OnnxPipeline.(OnnxPipeline.java:13)
at org.firstinspires.ftc.teamcode.vision.AIDetectThread.start(AIDetectThread.java:25)
at org.firstinspires.ftc.teamcode.vision.OnnxTestImplementation.init(OnnxTestImplementation.java:22)
at com.qualcomm.robotcore.eventloop.opmode.OpMode.internalRunOpMode(OpMode.java:181)
at com.qualcomm.robotcore.eventloop.opmode.OpModeInternal.lambda$internalInit$1$com-qualcomm-robotcore-eventloop-opmode-OpModeInternal(OpModeInternal.java:180)
at com.qualcomm.robotcore.eventloop.opmode.OpModeInternal$$ExternalSyntheticLambda1.run(D8$$SyntheticClass)
at com.qualcomm.robotcore.util.ThreadPool.logThreadLifeCycle(ThreadPool.java:737)
at com.qualcomm.robotcore.eventloop.opmode.OpModeInternal.lambda$internalInit$2$com-qualcomm-robotcore-eventloop-opmode-OpModeInternal(OpModeInternal.java:178)

the code:

private final String model = "vision/rubix-ball.pt";
public DeepNeuralNetworkProcessor() {
    this.net = 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