简体   繁体   中英

How can I extract the feature vector of the last hidden layer of the Alex net in pytorch?

我已经在pytorch中训练了Alex网络,并且想从图层中提取特征向量。我应该使用什么函数?

In my opinion, you can define a function in the model class which takes input and output the features you like, for example:

class model(nn.Module):
    def __init__(self):
        # init codes
    def forward(self, input):
        # forward codes
    def yourfunc(self, input):
        # codes
        #return feature1, feature2

This yourfunc only takes your input and outputs features you need, it does no backward computation. You just need to call it wherever you need. And I don't think there are built-in functions in PyTorch can do that since it is easy to implement by yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM