Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -160,13 +160,13 @@ def generate_similiarity_map(images, attn_map, all_bpe_strings, vis_list, target
|
|
| 160 |
attn_norm = get_similarity_map(attn_map.unsqueeze(0), (target_height, target_width), min_max=True, threshold=0.15)
|
| 161 |
print("attn_norm ",attn_norm.shape) # 有问题attn_norm torch.Size([1, 4, 448, 448])
|
| 162 |
print('all_bpe_strings:{:}'.format(all_bpe_strings))
|
| 163 |
-
indexes_without_space = torch.tensor([index for index, string in enumerate(all_bpe_strings) if ' ' is not string])
|
| 164 |
|
| 165 |
# Draw similarity map
|
| 166 |
# print(images_vis.shape)
|
| 167 |
images_vis = (images_vis.permute(1,2,0).cpu().numpy() * 125).astype('uint8')
|
| 168 |
for b in range(attn_norm.shape[0]):
|
| 169 |
-
for n in range(attn_norm.shape[1]
|
| 170 |
vis = (attn_norm[b, n, :, :].float().detach().cpu().numpy() * 255).astype('uint8')
|
| 171 |
vis = cv2.applyColorMap(vis, cv2.COLORMAP_JET)
|
| 172 |
print("images_vis",images_vis.shape)
|
|
@@ -176,17 +176,17 @@ def generate_similiarity_map(images, attn_map, all_bpe_strings, vis_list, target
|
|
| 176 |
vis = cv2.resize(vis, src_iamge_size)
|
| 177 |
vis_list.append(vis) # Add each visualization to the list
|
| 178 |
|
| 179 |
-
without_space_norm = attn_norm[b, indexes_without_space, :, :].max(0)[0]
|
| 180 |
-
space_norm = attn_norm[b, -1, :, :]
|
| 181 |
-
all_attn_norm = without_space_norm - space_norm
|
| 182 |
-
print(f'min:{all_attn_norm.min()};max:{all_attn_norm.max()}')
|
| 183 |
-
all_attn_norm = (all_attn_norm - all_attn_norm.min()) / (all_attn_norm.max() - all_attn_norm.min())
|
| 184 |
-
all_attn_norm = (all_attn_norm.float().detach().cpu().numpy() * 255).astype('uint8')
|
| 185 |
-
vis = cv2.applyColorMap(all_attn_norm, cv2.COLORMAP_JET)
|
| 186 |
-
vis = images_vis * 0.5 + vis * 0.5
|
| 187 |
-
vis = cv2.cvtColor(vis.astype('uint8'), cv2.COLOR_BGR2RGB)
|
| 188 |
-
vis = cv2.resize(vis, src_iamge_size)
|
| 189 |
-
vis_list.append(vis) # Add each visualization to the list
|
| 190 |
|
| 191 |
return vis_list
|
| 192 |
|
|
|
|
| 160 |
attn_norm = get_similarity_map(attn_map.unsqueeze(0), (target_height, target_width), min_max=True, threshold=0.15)
|
| 161 |
print("attn_norm ",attn_norm.shape) # 有问题attn_norm torch.Size([1, 4, 448, 448])
|
| 162 |
print('all_bpe_strings:{:}'.format(all_bpe_strings))
|
| 163 |
+
# indexes_without_space = torch.tensor([index for index, string in enumerate(all_bpe_strings) if ' ' is not string])
|
| 164 |
|
| 165 |
# Draw similarity map
|
| 166 |
# print(images_vis.shape)
|
| 167 |
images_vis = (images_vis.permute(1,2,0).cpu().numpy() * 125).astype('uint8')
|
| 168 |
for b in range(attn_norm.shape[0]):
|
| 169 |
+
for n in range(attn_norm.shape[1]):
|
| 170 |
vis = (attn_norm[b, n, :, :].float().detach().cpu().numpy() * 255).astype('uint8')
|
| 171 |
vis = cv2.applyColorMap(vis, cv2.COLORMAP_JET)
|
| 172 |
print("images_vis",images_vis.shape)
|
|
|
|
| 176 |
vis = cv2.resize(vis, src_iamge_size)
|
| 177 |
vis_list.append(vis) # Add each visualization to the list
|
| 178 |
|
| 179 |
+
# without_space_norm = attn_norm[b, indexes_without_space, :, :].max(0)[0]
|
| 180 |
+
# space_norm = attn_norm[b, -1, :, :]
|
| 181 |
+
# all_attn_norm = without_space_norm - space_norm
|
| 182 |
+
# print(f'min:{all_attn_norm.min()};max:{all_attn_norm.max()}')
|
| 183 |
+
# all_attn_norm = (all_attn_norm - all_attn_norm.min()) / (all_attn_norm.max() - all_attn_norm.min())
|
| 184 |
+
# all_attn_norm = (all_attn_norm.float().detach().cpu().numpy() * 255).astype('uint8')
|
| 185 |
+
# vis = cv2.applyColorMap(all_attn_norm, cv2.COLORMAP_JET)
|
| 186 |
+
# vis = images_vis * 0.5 + vis * 0.5
|
| 187 |
+
# vis = cv2.cvtColor(vis.astype('uint8'), cv2.COLOR_BGR2RGB)
|
| 188 |
+
# vis = cv2.resize(vis, src_iamge_size)
|
| 189 |
+
# vis_list.append(vis) # Add each visualization to the list
|
| 190 |
|
| 191 |
return vis_list
|
| 192 |
|