【发布时间】:2021-04-28 18:55:29
【问题描述】:
目标:
为了减少特征,我构建了一个 LSTM 自动编码器。我的计划是对一些输入进行编码,并在将来将其提供给分类器。编码器获取[batch_size, timesteps, features_of_timesteps 形状的数据,但是在编码器部分的输出层中,我只返回[1, timesteps, features_of_timesteps] 形式的最后一个隐藏状态。
class Encoder(nn.Module):
def __init__(self, input_size, first_layer, second_layer, n_layers):
super(Encoder, self).__init__()
self.n_layers = n_layers
self.encode = nn.Sequential(nn.LSTM(input_size, first_layer, batch_first=True),
getSequence(),
nn.ReLU(True),
nn.LSTM(first_layer, second_layer),
getLast())
self.decode = nn.Sequential(nn.LSTM(second_layer, first_layer, batch_first=True),
getSequence(),
nn.ReLU(True),
nn.LSTM(first_layer, input_size),
getSequence())
def forward(self, x):
x = x.float()
x = self.encode(x)
x = x.repeat(batch_size, 1, 1)
x = self.decode(x)
return x
担心:
恐怕我的第二个 LSTM 层在模型编码部分的最后一个隐藏状态是在汇总整个批次的同时降低特征维度。这感觉不对,因为我试图将单个时间序列减少为一个较小的向量,而不是将整批时间序列减少为一个向量。我的担心正确吗?
【问题讨论】:
标签: python-3.x deep-learning pytorch recurrent-neural-network autoencoder