PFLD-pytorch icon indicating copy to clipboard operation
PFLD-pytorch copied to clipboard

使用onnx模型时得到的结果不相同/不一致 Result is different between using pytorch-model and onnx-model

Open zuozhen opened this issue 3 years ago • 4 comments

python 3.7 + torch 1.8.1 ---中文--- 使用相同的输入,对pytorch模型 和 转换后的onnx模型进行测试,结果两个输出不一致,差别很大。 请问是什么原因,或者有人遇到相同问题吗? 谢谢。

---English--- I convert the pytorch model to onnx model using 'pytorch2onnx.py', then test the output of these two models. But the ouput of these two model on same input img is different. Very strange, can anyone help? Thanks.

zuozhen avatar Aug 19 '21 02:08 zuozhen

code is as following: `from models.pfld import PFLDInference import torch

img = get_test_img() # here is input checkpoint = torch.load('test_model.pth.tar') pfld_backbone = PFLDInference() pfld_backbone.load_state_dict(checkpoint['pfld_backbone']) _, landmarks1 = pfld_backbone(img)

import onnxruntime as rt sess = rt.InferenceSession('test_model.onnx') input_name = sess.get_inputs()[0].name img_n = img.cpu().detach().numpy() # convert tensor to numpy array onnx_output = sess.run(None, {input_name:img_n}) landmarks2 = onnx_output[1]`

the landmarks is quite different with landmarks2...

zuozhen avatar Aug 19 '21 03:08 zuozhen

Hi @zuozhen, can you please share your requirements.txt? I am getting the following error. Thanks!

RuntimeError: ./checkpoint/snapshot/checkpoint.pth.tar is a zip archive (did you mean to use torch.jit.load()?)

arch-raven avatar Jun 01 '22 07:06 arch-raven

Using python=3.7 along with the following package versions worked for me.

numpy==1.17.2
torch==1.7.0
opencv_python==4.1.0.25
tensorboardX==1.8
torchvision==0.8.0

arch-raven avatar Jun 01 '22 07:06 arch-raven

Thanks for your reply. I forget how or whether I fixed it and now I do not take such research anymore though...

zuozhen avatar Jun 13 '22 07:06 zuozhen