Skip to content

Feature Extraction #1154

Answered by rwightman
strugoeli asked this question in Q&A
Feb 22, 2022 · 2 comments · 7 replies

You must be logged in to vote

@strugoeli there's actually some relevant discussion in this issue (feature request) #1141 .... but the creator of that issue was looking for both the embeddings and predictions.

If you just want the embeddings (the activations right before the classifier) that are shape (batch_size, num_features) the best way is

model = timm.create_model('resnet50', num_classes=0)`  # create model with no classifier (nn.Identity in place), but pooling still present

or

model = timm.create_model('resnet50')
model.reset_classifier(num_classes=0)  # remove classifier (replace with nn.Identity()) after creation

Then any model(input) will output the embedding

What you proposed will work for some of the simple…

Replies: 2 comments 7 replies

You must be logged in to vote
2 replies
@strugoeli

@rwightman

Answer selected by strugoeli

You must be logged in to vote
5 replies
@rwightman

@rwightman

@yonatanbitton

@rwightman

@rwightman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants