Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model is not giving correct prediction scores after conversion #5523

Open
nahla-naz opened this issue Jun 20, 2024 · 1 comment
Open

Model is not giving correct prediction scores after conversion #5523

nahla-naz opened this issue Jun 20, 2024 · 1 comment

Comments

@nahla-naz
Copy link

nahla-naz commented Jun 20, 2024

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.

@nihui
Copy link
Member

nihui commented Aug 5, 2024

针对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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants