My question is how to make operation of tf.nn.conv2d_transpose
in pytorch .
See the example below:
np.random.seed(42)
y_val = np.random.rand(1, 32, 32, 1024)
feats_val = np.random.rand(3, 3, 128, 1024)
y_tf = tf.Variable(y_val)
feats_tf = tf.Variable(feats_val)
y_tor = torch.tensor(y_val)
feats_tor = torch.tensor(feats_val)
y_up_tf = tf.nn.conv2d_transpose(y_tf, feats_tf, [1, 64, 64, 128], strides=[1,2,2,1])
I want to get the same result than y_up_tf
using y_tor
and feats_tor
in Pytorch.
The functional conv_tranpose2d seems to be what you are looking for. You cannot specify the output shape like you do with the tensdorflow one but rather have to tweak the output_padding
to get the shape you want, but that is the only difference I think.
import torch.nn.functional as F
y_up_tor = F.conv_transpose(y_tor, feats_tor, output_padding=(1,1), stride=(2,2))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.