我想设计一个RNN类结构,它产生与MLP类结构相同的输入和输出。
实际上我的MLP代码是
class sample(nn.Module):
def__init__(self):
super(sample, self).init()
self.linear = nn.Linear(1, 20)
def forward(self, t, is_train = False, y = None):
a = self.linear(t)
return a
我试过
class sample(nn.Module):
def __init__(self, input_size, hidden_dim, num_layer):
super(sample, self).__init__()
self.input_size = input_size
self.hidden_dim = hidden_dim
self.num_layer = num_layer
self.linear = nn.rnn(1, 20,1, batch_size = false)
def forward(self, t, is_train = False, y = None):
a = self.rnn(t)
return a
但我认为它是错误的,我应该如何修改代码?
1条答案
按热度按时间6rqinv9w1#
你是说像这样的东西吗?
但如果实在无法更改代码,您可以简单地将
sample
替换为nn.RNN
或sample = nn.RNN
torch.nn.RNN
顺便说一句,https://discuss.pytorch.org/可能是问这类问题的更好的地方...