Python 重塑LSTM输出以获得所需的输出形状
我有一个noob问题:我构建了一个非常简单的LSTM,它以Python 重塑LSTM输出以获得所需的输出形状,python,pytorch,lstm,Python,Pytorch,Lstm,我有一个noob问题:我构建了一个非常简单的LSTM,它以的形式(批量大小、n个时间步长、n个功能)将时间序列数据窗口作为输入 这是LSTM: class LSTM(nn.Module): def __init__(self, input_dim, hidden_dim, num_classes): super(LSTM, self).__init__() self.hidden_dim = hidden_dim self.lstm_lay
的形式(批量大小、n个时间步长、n个功能)将时间序列数据窗口作为输入
这是LSTM:
class LSTM(nn.Module):
def __init__(self, input_dim, hidden_dim, num_classes):
super(LSTM, self).__init__()
self.hidden_dim = hidden_dim
self.lstm_layer = nn.LSTM(input_dim, hidden_dim, batch_first=True)
self.fc = nn.Linear(hidden_dim, num_classes)
def forward(self, x):
out, _ = self.lstm_layer(x)
x = self.fc(out.squeeze())
x = nn.functional.softmax(x, dim=2)
return x
因此,我希望输出(x
在代码中)是(批大小,num\u类)
,因为我想知道每个数据窗口的类。但是,现在的输出形状是(批大小、n时间步长、num类)
。如何修复此问题?只需在最后一行之前添加此行即可
x = np.delete(x, 1)