ncnn trouble with converted a custom yolov5s.pt

7fhtutme  于 2022-10-22  发布在  其他
关注(0)|答案(2)|浏览(235)

Hi, I am having trouble with a converted custom yolov5s.pt to ncnn:

I have trained a custom yolov5s.pt object detector with two classes, say my_yolov5s.pt. Then, I converted it to my_yolov5s.onnx using the yolov5/export.py:

python export.py --weights my_yolov5s.pt --include onnx --simplify

Later, I tried to convert the model into ncnn using onnx2ncnn.exe:
onnx2ncnn.exe my_yolov5s.onnx my_yolov5s.param my_yolov5s.bin

Up to this point, everything went smoothly. However, while I am trying to inference using ncnn version of my model, it crashes at ex.extract("output0", out)

I am attaching the screenshot of the Exception message. I appreciate any help or suggestions.

ztigrdn8

ztigrdn81#

ncnn is open source, you can debug with source code.
And if your model is trained by pytorch, please use pnnx to convert it to ncnn.

ldfqzlk8

ldfqzlk82#

I tried pnnx as follows:
pnnx.exe my_yolov5s.pt inputshape=[1,3,640,640]

But I got the following messages:

pnnxparam = my_yolov5s.pnnx.param
pnnxbin = my_yolov5s.pnnx.bin
pnnxpy = my_yolov5s_pnnx.py
ncnnparam = my_yolov5s.ncnn.param
ncnnbin = my_yolov5s.ncnn.bin
ncnnpy = my_yolov5s_ncnn.py
optlevel = 2
device = cpu
inputshape = [1,3,640,640]f32
inputshape2 =
customop =
moduleop =
Load torchscript failed: PytorchStreamReader failed locating file constants.pkl: file not found
Exception raised from valid at ..\..\caffe2\serialize\inline_container.cc:158 (most recent call first):
00007FFE9A2BA29200007FFE9A2BA230 c10.dll!c10::Error::Error [<unknown file> @ <unknown line number>]
00007FFE9A2B9D1E00007FFE9A2B9CD0 c10.dll!c10::detail::torchCheckFail [<unknown file> @ <unknown line number>]
00007FFE2F1D08A300007FFE2F1D0810 torch_cpu.dll!caffe2::serialize::PyTorchStreamReader::valid [<unknown file> @ <unknown line number>]
00007FFE2F1CF4AD00007FFE2F1CF3F0 torch_cpu.dll!caffe2::serialize::PyTorchStreamReader::getRecordID [<unknown file> @ <unknown line number>]
00007FFE2F1CF30200007FFE2F1CF2B0 torch_cpu.dll!caffe2::serialize::PyTorchStreamReader::getRecord [<unknown file> @ <unknown line number>]
00007FFE303FF68600007FFE303FF490 torch_cpu.dll!torch::jit::readArchiveAndTensors [<unknown file> @ <unknown line number>]
00007FFE303FDC1F00007FFE303FD4C0 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FFE303FB98900007FFE303F9400 torch_cpu.dll!torch::jit::CallStackDebugInfoUnpickler::unpickle [<unknown file> @ <unknown line number>]
00007FFE303FD6CB00007FFE303FD4C0 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FFE303FD16300007FFE303FD040 torch_cpu.dll!torch::jit::load [<unknown file> @ <unknown line number>]
00007FF69E5F6DFE00007FF69E5F5420 pnnx.exe!c10::ivalue::Future::waitAndThrow [<unknown file> @ <unknown line number>]
00007FF69E72347C00007FF69E5F5420 pnnx.exe!c10::ivalue::Future::waitAndThrow [<unknown file> @ <unknown line number>]
00007FFEC5A7703400007FFEC5A77020 KERNEL32.DLL!BaseThreadInitThunk [<unknown file> @ <unknown line number>]
00007FFEC61226A100007FFEC6122680 ntdll.dll!RtlUserThreadStart [<unknown file> @ <unknown line number>]

Please export model to torchscript as follows
------------------------------------------
import torch
import torchvision.models as models

net = models.resnet18(pretrained=True)
net = net.eval()

x = torch.rand(1, 3, 224, 224)
mod = torch.jit.trace(net, x)
mod.save("resnet18.pt")
------------------------------------------

**BTW:**I trained my model using the main repository of yolov5 ([https://github.com/ultralytics/yolov5])

相关问题