maomao88 commited on
Commit
574e06d
·
1 Parent(s): c19dba1

more updates

Browse files
__pycache__/main.cpython-313.pyc CHANGED
Binary files a/__pycache__/main.cpython-313.pyc and b/__pycache__/main.cpython-313.pyc differ
 
main.py CHANGED
@@ -79,7 +79,7 @@ def compute_cls_rollout_and_raw_others(attentions, start_layer=0):
79
  cls_rollout = rollout[0] # shape: [num_tokens]
80
 
81
  # Get raw attention from last layer (no rollout) for other tokens
82
- last_attention = attentions[-1][0].mean(dim=0) # [tokens, tokens]
83
 
84
  # Replace CLS row in last_attention with rollout
85
  last_attention[0] = cls_rollout
@@ -99,7 +99,7 @@ def attention_rollout(attentions, start_layer=0):
99
 
100
  for attention in attentions[start_layer:]:
101
  # Average over heads
102
- attn_heads_fused = attention[-1].mean(dim=0) # [tokens, tokens]
103
 
104
  # Add identity matrix to account for residual connections
105
  attn_heads_fused = attn_heads_fused + torch.eye(attn_heads_fused.size(0))
 
79
  cls_rollout = rollout[0] # shape: [num_tokens]
80
 
81
  # Get raw attention from last layer (no rollout) for other tokens
82
+ last_attention = attentions[0][0].mean(dim=0) # [tokens, tokens]
83
 
84
  # Replace CLS row in last_attention with rollout
85
  last_attention[0] = cls_rollout
 
99
 
100
  for attention in attentions[start_layer:]:
101
  # Average over heads
102
+ attn_heads_fused = attention[0].mean(dim=0) # [tokens, tokens]
103
 
104
  # Add identity matrix to account for residual connections
105
  attn_heads_fused = attn_heads_fused + torch.eye(attn_heads_fused.size(0))
static/index.html CHANGED
@@ -8,28 +8,28 @@
8
  <body>
9
  <div class="container">
10
  <h2>ViT Image Classification with Attention Visualization</h2>
11
- <div class="desc">
12
- <p>Upload an image to classify its content and visualize the attention map on the right.</p>
13
- <p>By default, the attention from the <b>[CLS]</b> token, representing the model’s overall summary, is highlighted, showing which image regions contributed most to the classification.</p>
14
- <p>Click on any region of the image on the right to explore how the model attends to that specific area.</p>
15
- </div>
16
  <div class="content-container">
17
  <div class="upload-container">
18
  <form id="upload-form">
19
- <div id="drop-zone" class="drop-zone">
20
- <span id="drop-zone-text">Drop image here or <button type="button" id="browse-btn">Browse</button></span>
21
- <input type="file" id="image-input" accept="image/*" style="display: none;" required />
22
- </div>
23
- <button type="submit" id="submit-btn">Classify Image</button>
24
  </form>
25
  <div id="local-images" class="examples">
26
  <span>Examples: </span>
27
  </div>
 
28
  </div>
29
  <div id="attn"></div>
30
  </div>
31
 
32
- <div id="result"></div>
33
  <div id="preview"></div>
34
  </div>
35
  <script src="app.js"></script>
 
8
  <body>
9
  <div class="container">
10
  <h2>ViT Image Classification with Attention Visualization</h2>
11
+ <div class="desc">
12
+ <p>Upload an image to classify its content and visualize the attention map on the right.</p>
13
+ <p>By default, the attention from the <b>[CLS]</b> token, representing the model’s overall summary, is highlighted, showing which image regions contributed most to the classification.</p>
14
+ <p>Click on any region of the image on the right to explore how the model attends to that specific area.</p>
15
+ </div>
16
  <div class="content-container">
17
  <div class="upload-container">
18
  <form id="upload-form">
19
+ <div id="drop-zone" class="drop-zone">
20
+ <span id="drop-zone-text">Drop image here or <button type="button" id="browse-btn">Browse</button></span>
21
+ <input type="file" id="image-input" accept="image/*" style="display: none;" required />
22
+ </div>
23
+ <button type="submit" id="submit-btn">Classify Image</button>
24
  </form>
25
  <div id="local-images" class="examples">
26
  <span>Examples: </span>
27
  </div>
28
+ <div id="result"></div>
29
  </div>
30
  <div id="attn"></div>
31
  </div>
32
 
 
33
  <div id="preview"></div>
34
  </div>
35
  <script src="app.js"></script>
static/style.css CHANGED
@@ -155,7 +155,10 @@ button[type="submit"]:disabled {
155
  }
156
 
157
  #result {
158
- margin-top: 16px;
159
  font-weight: bold;
160
  color: #333;
 
 
 
161
  }
 
155
  }
156
 
157
  #result {
158
+ margin-top: 2.5rem;
159
  font-weight: bold;
160
  color: #333;
161
+ padding: 1.3rem 0;
162
+ border: solid 3px #f97316;
163
+ border-radius: 6px;
164
  }