Giter Club home page Giter Club logo

Comments (10)

Linranran avatar Linranran commented on May 26, 2024 1

@zarakikun
like this

def forward(self, x):
for name, module in self.base._modules.items():
if name == 'avgpool':
break
x = module(x)
if self.cut_at_pooling:
return x
x = F.avg_pool2d(x, x.size()[2:])
x = x.view(x.size(0), -1)
pool5=x
if self.has_embedding:
x = self.feat(x)
x = self.feat_bn(x)
if self.norm:
x = F.normalize(x)
elif self.has_embedding:
x = F.relu(x)
if self.dropout > 0:
x = self.drop(x)
if self.num_classes > 0:
x = self.classifier(x)
return x ,pool5

from open-reid.

Cysu avatar Cysu commented on May 26, 2024 1

@ahkarami No, you don't have to. Just

outs = []
x = self.feat(x)
outs.append(x)
...
return outs

from open-reid.

liangbh6 avatar liangbh6 commented on May 26, 2024

@Linranran I have the same question, too. Have you figured out that? I am new with pytorch and will be happy that if you can give me some suggestions.

from open-reid.

Linranran avatar Linranran commented on May 26, 2024

@liangbh6 you can change a little at https://github.com/Cysu/open-reid/blob/master/reid/models/resnet.py ,just return one more variable .

def forward(self, x):

    for name, module in self.base._modules.items():
        if name == 'avgpool':
            break
        x = module(x)

you can mark the x and return it a in the end. you will get two features when put images into the model ,and chose the feature you wants.
i make it by this way.and pytorch have the function hook ,but i am not clear how to use it .

from open-reid.

liangbh6 avatar liangbh6 commented on May 26, 2024

@Linranran It works. Thank you for kind help! I think it's a very simple way to achieve that~

from open-reid.

zarakikun avatar zarakikun commented on May 26, 2024

Hi, I don't really understand your method, do u mean for example i wan to extract the features from pool 5, i do this?

def forward(self, x):
    for name, module in self.base._modules.items():
        if name == 'avgpool':
             return x

from open-reid.

Linranran avatar Linranran commented on May 26, 2024

@zarakikun no ,do not do it this way.just mark the pool5 variable,and return it at the end .if you do it in your approach you will distroy the initial code and have to change a lot related code.you just marke the pool5 variable and return it in the end .and chose the returned variable that your want

from open-reid.

zarakikun avatar zarakikun commented on May 26, 2024

@Linranran would you mind showing me a snippet example of how you would retrieve for example pool5 features? thank you!

from open-reid.

ahkarami avatar ahkarami commented on May 26, 2024

Dear @Linranran,
Thank you for your answer. But I think if one want extract the correct & discriminative feature vector from a pre-trained model must return a variable after x = self.feat(x) layer. Am I correct? What do you think?

from open-reid.

ahkarami avatar ahkarami commented on May 26, 2024

Dear @Cysu,
Thank you very much for your answer.

from open-reid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.