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

get cls block #275

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
dino.egg-info
9 changes: 8 additions & 1 deletion vision_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import torch
import torch.nn as nn

from utils import trunc_normal_
from .utils import trunc_normal_


def drop_path(x, drop_prob: float = 0., training: bool = False):
Expand Down Expand Up @@ -213,6 +213,13 @@ def forward(self, x):
x = self.norm(x)
return x[:, 0]

def get_last_block(self, x):
x = self.prepare_tokens(x)
for blk in self.blocks:
x = blk(x)
x = self.norm(x)
return x[0]

def get_last_selfattention(self, x):
x = self.prepare_tokens(x)
for i, blk in enumerate(self.blocks):
Expand Down
3 changes: 2 additions & 1 deletion visualize_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
from PIL import Image

import utils
import vision_transformer as vits

from . import vision_transformer as vits


def apply_mask(image, mask, color, alpha=0.5):
Expand Down