tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

PytorchCaffe2SuperResolution caffe result dismatch pytorch result

Open cswwp opened this issue 7 years ago • 3 comments

i had tested this demo on my cpu machine, and i modify the model_zoo.load_url(model_url, map_location='cpu') with cpu model load, but the reuslt np.testing.assert_almost_equal(torch_out.data.cpu().numpy(), c2_out, decimal=3) shows: (mismatch 99.89082872732426%) x: array([-0.047, 0.17 , 0.84 , ..., 0.204, 0.15 , 0.142], dtype=float32) y: array([-0.047, 1.371, 1.373, ..., 0.577, 0.355, 0.142], dtype=float32) I don't know what happen, and how fix it? anyone help?

cswwp avatar Oct 31 '18 06:10 cswwp

I have a similar issue. I do not know if the UserWarning is related to the accuracy problem or not.

/home/developer/anaconda3/envs/PyTorch/lib/python3.6/site-packages/onnx_caffe2/backend.py:521: UserWarning: This version of onnx-caffe2 targets ONNX operator set version 2, but the model we are trying to import uses version 9. We will try to import it anyway, but if the model uses operators which had BC-breaking changes in the intervening versions, import will fail. warnings.warn("This version of onnx-caffe2 targets ONNX operator set version {}, but the model we are trying to import uses version {}. We will try to import it anyway, but if the model uses operators which had BC-breaking changes in the intervening versions, import will fail.".format(cls._known_opset_version, imp.version))

AssertionError Traceback (most recent call last) in 22 23 # Verify the numerical correctness upto 3 decimal places ---> 24 np.testing.assert_almost_equal(torch_out.data.cpu().numpy(), c2_out, decimal=3) 25 26 print("Exported model has been executed on Caffe2 backend, and the result looks good!")

~/.local/lib/python3.6/site-packages/numpy/testing/_private/utils.py in assert_almost_equal(actual, desired, decimal, err_msg, verbose) 566 if isinstance(actual, (ndarray, tuple, list))
567 or isinstance(desired, (ndarray, tuple, list)): --> 568 return assert_array_almost_equal(actual, desired, decimal, err_msg) 569 try: 570 # If one of desired/actual is not finite, handle it specially here:

~/.local/lib/python3.6/site-packages/numpy/testing/_private/utils.py in assert_array_almost_equal(x, y, decimal, err_msg, verbose) 971 assert_array_compare(compare, x, y, err_msg=err_msg, verbose=verbose, 972 header=('Arrays are not almost equal to %d decimals' % decimal), --> 973 precision=decimal) 974 975

~/.local/lib/python3.6/site-packages/numpy/testing/_private/utils.py in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan, equal_inf) 787 verbose=verbose, header=header, 788 names=('x', 'y'), precision=precision) --> 789 raise AssertionError(msg) 790 except ValueError: 791 import traceback

AssertionError: Arrays are not almost equal to 3 decimals

(mismatch 99.87975659013605%) x: array([0.484, 0.482, 0.51 , ..., 0.317, 0.28 , 0.208], dtype=float32) y: array([0.484, 0.403, 2.066, ..., 0.451, 0.39 , 0.208], dtype=float32)

phalexo avatar Nov 24 '18 12:11 phalexo

We run the conversion of Super Resolution in CI: https://github.com/pytorch/pytorch/blob/master/test/onnx/test_pytorch_onnx_caffe2.py#L429

And we compare the results, it should be fine

houseroad avatar Dec 04 '18 20:12 houseroad

Any update on this? Same error, the predictions doesn't match.

pankajvshrma avatar Jun 11 '19 11:06 pankajvshrma