microsoft / MMdnn

MMdnn is a set of tools to help users inter-operate among different deep learning frameworks. E.g. model conversion and visualization. Convert models between Caffe, Keras, MXNet, Tensorflow, CNTK, PyTorch Onnx and CoreML.
MIT License
5.8k stars 965 forks source link

change trace function for pytorch 1.5 #870

Closed lvyufeng closed 4 years ago

lvyufeng commented 4 years ago

use torch.onnx provided _trace function(include optimization)

ghost commented 4 years ago

CLA assistant check
All CLA requirements met.

lvyufeng commented 4 years ago

the missing scope name use workaround to fix, and the torch.onnx.utils._trace seems more suitable for conversion.

XiaoXYe commented 4 years ago

@lvyufeng, useful code! Thank you for your contribution. It will work with some addtional code on extracting state_dict keys from the scope.

XiaoXYe commented 4 years ago

@lvyufeng, we tested your code on several models but it caused some accurancy losses when converting resnet152 and vgg19_bn. Thanks for your contribution and any idea about extracting graph and scope is welcomed.

lvyufeng commented 4 years ago

@lvyufeng, we tested your code on several models but it caused some accurancy losses when converting resnet152 and vgg19_bn. Thanks for your contribution and any idea about extracting graph and scope is welcomed.

is that _optimize_graph function in torch.onnx.utils automaticly remove some useful nodes from origin graph?

XiaoXYe commented 4 years ago

@lvyufeng , According to Pytorch Tutorial

It is important to call torch_model.eval() or torch_model.train(False) before exporting the model, to turn the model to inference mode. This is required since operators like dropout or batchnorm behave differently in inference and training mode.

when using model.eval() before _trace(), we got the correct result. Thanks for your contribution.

XiaoXYe commented 4 years ago

merge in #876