ncnn Model is not giving correct prediction scores after conversion

bogh5gae  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(44)

Hi,

I created a Pytorch model which is giving >80% accuracy on windows. The prediction scores are within the range of 0 and 1. However, after I convert it to NCNN, it is giving 0 and 1 as scores. I managed to solve this problem by adding a softmax layer:
out = F.softmax(out, dim=1)
Now, the prediction scores are between 0 and 1. But the accuracy is very low.

How can I make the accuracy of NCNN model same as that of Pytorch model?

I converted the model from .pth to .onnx using below method and converted .onnx to .param and .bin using convertmodel.com(without simplifying or optimising).

model=torch.load('model.pth',map_location=torch.device('cpu'))
model.eval()
input_tensor = torch.randn(1, 3, 80, 80 )
exportModel = model
torch.onnx.export(exportModel, input_tensor, 'path' +
('modelNEW.onnx'), export_params=True, input_names=["data"], output_names=["softmax"])

Kindly help. Thanks.

h7wcgrx3

h7wcgrx31#

针对onnx模型转换的各种问题,推荐使用最新的pnnx工具转换到ncnn
In view of various problems in onnx model conversion, it is recommended to use the latest pnnx tool to convert your model to ncnn

pip install pnnx
pnnx model.onnx inputshape=[1,3,224,224]

详细参考文档
Detailed reference documentation
https://github.com/pnnx/pnnx
https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx#how-to-use-pnnx

相关问题