Convert model Pytorch->ONNX->NCNN

2.4k Views Asked by At

Trying to run this example on your custom trained Yolov8 model.

Field of study I have a model best.pt

ncnn exporting Insturction

  1. I do the export to ONNX format

pip install ultralytics yolo mode=export model={HOME}/best.pt format=onnx

  1. simplify onnx model

pip install onnxsim pip install onnxruntime python -m onnxsim {HOME}/best.onnx {HOME}/best-sim.onnx

Error: [1] 67272 segmentation fault python -m onnxsim best.onnx best-sim.onnx But I found a solution

  1. onnx to ncnn

onnx2ncnn best-sim.onnx best.param best.bin

  1. I changing a new model path and CLASS_NAME in the example (file yoloV8.cpp)

yolo.load_param("best.param"); yolo.load_model("best.bin");

const char *class_names[] = {"bus", "car", "truck"};

  1. I changing layer name (file yoloV8.cpp). I looked at the structural model https://netron.app/

ex.extract("output0", out); ... std::vector<int> strides = {32};

  1. Run Test image

I get house, but in the process of training the model, it is working.

0

There are 0 best solutions below