简体   繁体   English

在 Pytorch 中制作 tf.nn.conv2d_transpose

[英]Make tf.nn.conv2d_transpose in Pytorch

My question is how to make operation of tf.nn.conv2d_transpose in .我的问题是如何使操作tf.nn.conv2d_transpose

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.我想在y_up_tf使用y_torfeats_tor y_torfeats_tor相同的结果。

The functional conv_tranpose2d seems to be what you are looking for.功能conv_tranpose2d似乎是您正在寻找的。 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.您不能像使用 tensdorflow 那样指定输出形状,而必须调整output_padding以获得您想要的形状,但这是我认为的唯一区别。

import torch.nn.functional as F
y_up_tor = F.conv_transpose(y_tor, feats_tor, output_padding=(1,1), stride=(2,2))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM