-
Notifications
You must be signed in to change notification settings - Fork 965
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
Convert Model from MXNet to PyTorch #6
Comments
Hi @ahkarami , |
Dear @kitstar, |
I will follow up and tell you if there is any progress. Thanks. |
Hi @ahkarami , please check the newest code. mxnet -> pytorch resnet152 with 11K tested. |
Dear @kitstar, 2- 3- I think I have converted the model correctly. After that, I have tested the results of two models (i.e., the original MXNet one and converted PyTorch one (i.e., the resnet152Full.pth)) via my implemented scripts. However, the results were different from each other. Have you ever tested the results of these two models by yourself? and Would you please help me? |
I tested the conversion with python -m mmdnn.conversion.examples.pytorch.imagenet_test -n kit_imagenet.py -w kit_pytorch.npy -i mmdnn/conversion/examples/data/seagull.jpg which use seagull.jpg to test the inference result. mxnet inference result of top-5: converted pytorch inference result of top-5: Since the difference is not so significant, I didn't look into it. (Different implementation leads to difference result).
Thanks. |
Dear @kitstar,
Nevertheless, I will share my tested scripts on both frameworks (i.e., MXNet and PyTorch) in the next comment. |
Sorry for the lack argument python -m mmdnn.conversion.examples.pytorch.imagenet_test -n kit_imagenet.py -w kit_pytorch.npy -i mmdnn/conversion/examples/data/seagull.jpg -p resnet152-11k -s mxnet -s mxnet and the image is in the git repo. |
Dear @kitstar,
Unfortunately, I got error again! and another amazing thing that the produced results on my machine is a little different from your reported results!! My System Results: |
my mxnet version is '0.12.0' maybe it matters? |
Dear @kitstar, Now, I want to compare the results of the original MXNet Model (i.e., resnet-152-symbol.json & resnet-152-0000.params) vs the converted PyTorch one (i.e., resnet152Full.pth model) visually.
And this is the produced Results:
And this my used PyTorch script:
And this is the PyTorch produced Results:
So It is obviously clear that the results are significantly different from each other. It is worth noting that I want to use the resnet152Full.pth model on PyTorch. And I also tested some other images, but the results are very different. |
From your code, mxnet uses the original graph for training. But your pytorch code normalizes the input image with std and mean array. If you want to get the same result, you could try to remove the normalize part of preprocess. And not quite sure about the transforms.Scale(256) part, maybe you can try to remove it too. You can refer our testing method to implement your inference code. |
Dear @kitstar, |
Possible. I am not familiar with PyTorch preprocess method. Have you also removed the scale part? from tensorflow.contrib.keras.api.keras.preprocessing import image
img = image.load_img(path, target_size = (224, 224))
x = image.img_to_array(img)
x = x[..., ::-1] # In my test, I transform image from RGB --> BGR in both mxnet and pytorch
x = np.transpose(x, (2, 0, 1))
x = np.expand_dims(x, 0).copy()
x = torch.from_numpy(x)
x = torch.autograd.Variable(x, requires_grad = False)
output = model(x) |
Dear @kitstar, |
Glad I could help. |
Hi, @kitstar Besides, does running the following script need tensorflow?
since the following module use the image processing module in Keras
|
Hi @yuzcccc,
|
I use the the mmconvert and successfully transform the mxnet model to caffe, however, I find a very strange phenomenon in the generated caffe's prototxt
Why there is such a crop operation? In the original caffe's implementation, not such part, and also I could not find this part in the MxNet's json file |
The command I use is
|
It is for eliminating the padding algorithm difference between caffe and other frameworks. |
Oh, I find the difference. Caffe's ResNet usually do not introduce pad in this pooling layer. However, I am wondering that whether I can remove the dummydata and crop layer, and simple remove the padding(pad=1) param manually from the prototxt? Would this influence the results? ps. Do I have to worry about the RGB and BGR problem for the generated caffemodel? |
|
thanks a lot! |
I followed the instructions and it worked very well. Great thanks! |
I think this link would be helpful: |
Dear @kitstar,
Thank you for your nice repository. I have a pre-trained ResNet152 model on MXNet and I want to convert it to PyTorch. Would you please kindly guide me to do that?
The text was updated successfully, but these errors were encountered: