How to transfer a trained model from Matlab to Pytorch?

Any ideas about how to transfer a trained model from Matlab to Pytorch?

Here is the discussion about how to transfer from Pytorch to Matlab. However, I need the inverse thing…

Thanks in advance for any suggestions.

You could try to save the MATLAB model parameters as .mat files.
After re-building the model in PyTorch, you could load these parameters using and assign them to your PyTorch model.
Make sure you check the shaped and also possible flipped kernels, since some frameworks flip the conv kernels to use a convolution instead of the correlation.


Thanks for the suggestion. I’ll try. By the way, for the pytorch, do we use the convolution or correlation? It seems that we are using the correlation, right?

Yep, is the correlation, since the kernels are not flipped again.

Cool. It is much clear now. Thanks a lot.

@Jimmy_Xiaoke_Shen, I’m trying to do the same thing. Did you able to do this?

Sorry for the late reply as I haven’t login for a long time. I gave up using the Matlab weights so I don’t know whether there is a good way to do that.