LSTM细胞从烧伤转化为keras模型

时间:2020-06-18 05:25:11

标签: python tensorflow keras pytorch lstm

我已经通过py的子类(使用__ init__,def调用方法)在pytorch中编写了LSTM单元格的代码,并编写了我想在keras中构建的相同模型。有人可以帮我解决这个问题吗?

Pytorch代码:

MyModel类(torch.nn.Module):

def __init__(self,hidden_size):
    super(MyModel,self).__init__()
    self.lstm = torch.nn.LSTMCell(10,hidden_size,bias = False)
    self.hidden_dim  = hidden_size
def forward(self,inputs):
    hx = torch.zeros(1, self.hidden_dim)
    cx = torch.zeros(1, self.hidden_dim)
    hx, cx = self.lstm(inputs,(hx,cx))
    x = hx
    return x,(hx,cx)

hidden_​​size = 512

lstm = MyModel(hidden_​​size)

print(lstm.state_dict())

输入= torch.randn(1,10) x,(hx,cx)= lstm(输入)

0 个答案:

没有答案