【发布时间】:2020-07-31 09:40:40
【问题描述】:
我有一些需要转换为 Pytorch 的 keras 代码。我已经做了一些研究,但到目前为止我无法重现我从 keras 获得的结果。我在这方面花了很多时间,非常感谢任何提示或帮助。
这是我正在处理的 keras 代码。输入形状是 (None, 105, 768) 其中 None 是批量大小,我想将 Conv1D 应用于输入。 keras 中的期望输出为 (None, 105)
x = tf.keras.layers.Dropout(0.2)(input)
x = tf.keras.layers.Conv1D(1,1)(x)
x = tf.keras.layers.Flatten()(x)
x = tf.keras.layers.Activation('softmax')(x)
我试过了,但结果更糟:
self.conv1d = nn.Conv1d(768, 1, 1)
self.dropout = nn.Dropout(0.2)
self.softmax = nn.Softmax()
def forward(self, input):
x = self.dropout(input)
x = x.view(x.shape[0],x.shape[2],x.shape[1])
x = self.conv1d(x)
x = torch.squeeze(x, 1)
x = self.softmax(x)
【问题讨论】:
标签: machine-learning keras deep-learning pytorch