'Problem about Copying deconvolution weights from pytorch model to tensorflow model
I convert weights from a pytorch model to tf2 model. To verify the result, I compare the output from both pytorch original model and tf2 model. However, the output from tf2 model has black bars on the top and left hand side of the map, whereas the pytorch output does not have these black bars. The output of tf2 model. https://i.stack.imgur.com/OXkm6.png
The pytorch code is
nn.convtranspose2d(d, num_channels, kernel_size=9, stride=scale_factor, padding=9//2, output_padding=scale_factor-1)
The tf2 code is
conv2dtranspose(num_channels, 9, strides=scale_factor, padding='same')(x)
For the converting process for pytorch weights to tensorflow weights is as follow:
onnx_1_w_num = onnx_l.weight.data.permute(2,3,1,0).numpy()
onnx_1_b_num = onnx_l.bias.data.numpy()
tf_l.set_weights([onnx_1_w_num,onnx_1_b_num])
Thanks for help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
