From 8f632fa0fa99050a062f01f76604eb8ba7cfaa7c Mon Sep 17 00:00:00 2001 From: Shoval Date: Tue, 26 Dec 2023 14:36:15 +0200 Subject: [PATCH 1/4] get cls block --- vision_transformer.py | 9 ++++++++- visualize_attention.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/vision_transformer.py b/vision_transformer.py index f69a7ad05..bd5902de3 100644 --- a/vision_transformer.py +++ b/vision_transformer.py @@ -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): @@ -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): diff --git a/visualize_attention.py b/visualize_attention.py index 4288265b9..7b9492267 100644 --- a/visualize_attention.py +++ b/visualize_attention.py @@ -31,8 +31,8 @@ import numpy as np from PIL import Image -import utils -import vision_transformer as vits +from . import utils +from . import vision_transformer as vits def apply_mask(image, mask, color, alpha=0.5): From 22d911e2dd0ad31fc23e57634fab3ed9ab724c25 Mon Sep 17 00:00:00 2001 From: Shoval Mishal Date: Wed, 10 Apr 2024 15:44:22 +0300 Subject: [PATCH 2/4] backup --- vision_transformer.py | 2 +- visualize_attention.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vision_transformer.py b/vision_transformer.py index f69a7ad05..80af63f9a 100644 --- a/vision_transformer.py +++ b/vision_transformer.py @@ -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): diff --git a/visualize_attention.py b/visualize_attention.py index 4288265b9..59849c817 100644 --- a/visualize_attention.py +++ b/visualize_attention.py @@ -32,7 +32,7 @@ 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): From 302c7c6274193e53517bcc1d7e5c08f7cee6890e Mon Sep 17 00:00:00 2001 From: Shoval Mishal Date: Wed, 10 Apr 2024 15:54:07 +0300 Subject: [PATCH 3/4] minor --- visualize_attention.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/visualize_attention.py b/visualize_attention.py index 59849c817..876431f12 100644 --- a/visualize_attention.py +++ b/visualize_attention.py @@ -31,7 +31,8 @@ import numpy as np from PIL import Image -import utils +import utilsgit status + from . import vision_transformer as vits From bbb42ade1a85f210b90e2f94b44a51689095c8b9 Mon Sep 17 00:00:00 2001 From: Shoval Date: Wed, 3 Jul 2024 19:21:54 +0300 Subject: [PATCH 4/4] minor changes --- .gitignore | 2 ++ visualize_attention.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..e80976c92 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +dino.egg-info diff --git a/visualize_attention.py b/visualize_attention.py index 876431f12..8b45840e7 100644 --- a/visualize_attention.py +++ b/visualize_attention.py @@ -31,7 +31,7 @@ import numpy as np from PIL import Image -import utilsgit status +import utils from . import vision_transformer as vits