【发布时间】:2020-03-28 18:33:58
【问题描述】:
我试图使用 PyTorch 框架重新实现 TensorFlow 代码。下面我包含了 TF 示例代码和我的 PyT 解释。
TensorFlow 实现:
W1 = tf.Variable(xavier_init([135, 128]))
b1 = tf.Variable(tf.zeros(shape=[128]))
def fcn(x):
z = tf.reshape(x, (-1, 135))
out1 = leaky_relu( tf.matmul(z, W1) + b1 )
return out1
PyTorch 实现:
class decoder(nn.Module):
def __init__(self):
super(decoder, self).__init__()
self.layer_10 = nn.Linear(135, 128, bias=True)
self.leaky = nn.LeakyReLU(0.2, inplace=False)
init.xavier_uniform(self.layer_10.weight)
def forward(self, x):
z = x.view(-1, 135)
h30 = self.leaky(self.layer_10(z))
return h30
我想知道实现 matmul 部分的正确方法是什么,因为 pytorch 中的权重没有像 TF 中那样明确定义(或者如果我错了,请纠正我)。
【问题讨论】:
标签: tensorflow pytorch