【发布时间】:2021-05-22 02:22:09
【问题描述】:
按照post 中的教程,我正在尝试训练自动编码器并从其隐藏层中提取特征。
所以这是我的问题:
-
在自动编码器类中,有一个“前进”功能。但是,我在代码中看不到调用此函数的任何地方。那么它是如何训练的呢?
-
我上面的问题是因为我觉得如果我想提取特征,我应该在自动编码器类中添加另一个函数(f“orward_hidden”):
def forward(self, features): #print("in forward") #print(type(features)) activation = self.encoder_hidden_layer(features) activation = torch.relu(activation) code = self.encoder_output_layer(activation) code = torch.relu(code) activation = self.decoder_hidden_layer(code) activation = torch.relu(activation) activation = self.decoder_output_layer(activation) reconstructed = torch.relu(activation) return reconstructed def forward_hidden(self, features): activation = self.encoder_hidden_layer(features) activation = torch.relu(activation) code = self.encoder_output_layer(activation) code = torch.relu(code) return code
那么,训练后,也就是主代码中这一行之后:
print("AE, epoch : {}/{}, loss = {:.6f}".format(epoch + 1, epochs_AE, loss))
我可以输入以下代码从隐藏层检索特征:
hidden_features = model_AE.forward_hidden(my_input)
这种方式正确吗?不过,我想知道“前进”功能是如何用于训练的。因为我在被调用的代码中的任何地方都看不到它。
【问题讨论】:
标签: python deep-learning neural-network pytorch autoencoder