Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intermediate tokens #398

Closed
wangyf8848 opened this issue Mar 25, 2024 · 4 comments
Closed

intermediate tokens #398

wangyf8848 opened this issue Mar 25, 2024 · 4 comments

Comments

@wangyf8848
Copy link

Hi,

I have got the mdoel using : 'dinov2_vitl14 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vitl14')'.
And how can I get the output tokens of specific intermediate layers when inferencing.

@aeinsara
Copy link

aeinsara commented Apr 2, 2024

hi, do you find a solution?

@barbolo
Copy link

barbolo commented Apr 12, 2024

x = torch.rand((1, 3, 224, 224))
dinov2 = torch.hub.load('facebookresearch/dinov2', 'dinov2_vits14_reg')
features = dinov2.forward_features(x)

features is a dict with keys:

['x_norm_clstoken', 'x_norm_regtokens', 'x_norm_patchtokens', 'x_prenorm', 'masks']

@paulgay
Copy link

paulgay commented Apr 24, 2024

x = torch.rand(1, 3, 224, 224)
x = dinov2_vitb14_reg_lc.backbone.patch_embed(x)
blocks = []
with torch.no_grad():
for m in dinov2_vitb14_reg_lc.backbone.blocks:
x = m(x)
blocks.append(x)

See also get_intermediate_layers function in dinov2/models/vision_transformer.py

@qasfb
Copy link
Contributor

qasfb commented May 13, 2024

get_intermediate_layers is indeed what you need !

@qasfb qasfb closed this as completed May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants