Extraction of class token #2446
-
For vision transformer models that have a class token option enabled, how can I extract the class token for intermediate layers? For example, if I use the model - |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@vedantdalimkar assuming you're using pytorch-image-models/timm/models/vision_transformer.py Lines 722 to 743 in e44f14d |
Beta Was this translation helpful? Give feedback.
-
@vedantdalimkar oh, and there are ways to get the features w/o using intermediates, but only the last hidden state ... using forward_features or normal forward but with pooling and no classifier... it returns the flat sequence so class token is [0] and the 4 register tokens are [1:5].
|
Beta Was this translation helpful? Give feedback.
@vedantdalimkar assuming you're using
forward_intermediates()
,return_prefix_tokens=True
will give you another list of the class tokens beside the spatial tokenspytorch-image-models/timm/models/vision_transformer.py
Lines 722 to 743 in e44f14d