[英]How can I extract the feature vector of the last hidden layer of the Alex net in pytorch?
我已经在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内置的功能可以做到这一点,因为它很容易自己实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.