# Opencv DNN yolov8 error

**URL:** <https://forum.opencv.org/t/opencv-dnn-yolov8-error/14053>\
**Category:** Android/Java\
**Tags:** dnn\
**Created:** [July 29, 2023, 10:39pm UTC](https://forum.opencv.org/t/opencv-dnn-yolov8-error/14053 "2023-07-29T22:39:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samson\_Kempiak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/samson_kempiak/32/8419_2.png) [@Samson\_Kempiak](https://forum.opencv.org/u/Samson_Kempiak)\
**Post date:** [July 29, 2023, 10:39pm UTC](https://forum.opencv.org/t/opencv-dnn-yolov8-error/14053/1 "2023-07-29T22:39:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 30, 2023, 6:19am UTC](https://forum.opencv.org/t/opencv-dnn-yolov8-error/14053/2 "2023-07-30T06:19:27Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Samson\_Kempiak](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/samson_kempiak/32/8419_2.png) [@Samson\_Kempiak](https://forum.opencv.org/u/Samson_Kempiak)\
**Post date:** [August 7, 2023, 12:41am UTC](https://forum.opencv.org/t/opencv-dnn-yolov8-error/14053/3 "2023-08-07T00:41:28Z")

</div>

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.
