How to transfer pretained model from Tensorflow to PyTorch?

I have build exactly same model in both TF and Pytorch. And I trained in TF. For some reason, I have to transfer the pretrained weight to Pytorch.

The network is like:

In TF, Conv2d filter shape is [filter_height, filter_width, in_channels, out_channels], while in Pytorch is (out_channels, in_channels, kernel_size[0], kernel_size[1]).

So I have done below in TF:

and I transfer to pytorch like:

It turns out that the DQN in pytorch is not working well as in TF!

Hey i wanna do the same kind of thing too did you find a solution. or is there a document from which i can take inspiration .

1 Like

See for some hints / mechanisms.


In case someone else gets here and has the same issue, I think that the problem is using reshape before transpose.
I have loaded TF weights with PyTorch by permuting the weight Tensor, and it worked fine.


This was very helpful tip, thanks :slight_smile: