我已经在pytorch中训练了一个Alex网络,我想从层中提取特征向量我应该使用什么功能?
在我看来,您可以在模型类中定义一个函数,该函数接受输入并输出您喜欢的功能,例如:
class model(nn.Module):
def __init__(self):
# init codes
def forward(self, input):
# forward codes
def yourfunc(self, input):
# codes
#return feature1, feature2
这个 yourfunc 只接受您需要的输入和输出功能,它不进行反向计算。你只需要在你需要的任何地方打电话。而且我不认为 PyTorch 中的内置函数可以做到这一点,因为它很容易自己实现。