MMdnn icon indicating copy to clipboard operation
MMdnn copied to clipboard

Problematic Conversion Test

Open erfan-matroid opened this issue 8 years ago • 4 comments

Platform (like ubuntu 16.04/win10): macOS High Sierra 10.13.6

Python version: 3.6.4

Source framework with version (like Tensorflow 1.4.1 with GPU): PyTorch 0.4.0

Destination framework with version (like CNTK 2.3 with GPU): TensorFlow 1.8.0

Pre-trained model path (webpath or webdisk path): All the models from torchvision


I am using MMdnn to first convert torchvision models from PyTorch to IR, and then from IR to TensorFlow, using the commands in the documentations. However, after doing the conversion I was comparing the outputs of the original PyTorch and the converted TensorFlow model and they have substantial difference. I checked test_conversion_imagenet.py to see how MMdnn compares models and I have a question about the methodology. I wonder why the outputs from the two models are sorted first before being compared in L76-L77?

From my understanding the predicted values from the original and converted models should be close in all dimensions of the output, not the ordered variables. Actually when I applied this sorting step in my comparison code the reported difference decreased substantially.

What is the reasoning behind the sorting step in the comparison code?

erfan-matroid avatar Jul 20 '18 00:07 erfan-matroid

Hi @erfan-matroid, I remember the sort is for CoreML parser testing, seems there is an offset of CoreML prediction result, which leads to a dislocated comparison. But we can't assume the offset is equal to 1, so we sort it first. @JiahaoYao should know the detail problem.

kitstar avatar Jul 20 '18 03:07 kitstar

Hi @erfan-matroid, I think you are right. As for comparison code, the reason is simple. As shown L73-L79, it is just because the lengths of original and converted models' values are not the same. As @kitstar mentioned, sort could somehow be a safe way to compare both the results due to an offset. That is why sort is added.

JiahaoYao avatar Jul 24 '18 06:07 JiahaoYao

But I still think that this method of comparison is problematic. Even if the problem is due to an offset in the outputs, then comparing the values ordered after accounting for the offset would probably be better. In my own tests I see a substantial difference in the prediction results between a model in PyTorch and the same model converted to TensorFlow.

erfan-matroid avatar Jul 24 '18 16:07 erfan-matroid

I re-checked my conversion code and compared the models again and I now can confirm that results are similar. So you can probably close this issue. Although I still think that slicing the resulting prediction due to the offset and comparing the two results will probably be more reliable than sorting first and then comparing them.

erfan-matroid avatar Aug 01 '18 16:08 erfan-matroid