(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int)
| 187 | # display(pil_img) |
| 188 | |
| 189 | def aggregate_attention(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int): |
| 190 | out = [] |
| 191 | attention_maps = attention_store.get_average_attention() |
| 192 | num_pixels = res ** 2 |
| 193 | for location in from_where: |
| 194 | for item in attention_maps[f"{location}_{'cross' if is_cross else 'self'}"]: |
| 195 | if item.shape[1] == num_pixels: |
| 196 | cross_maps = item.reshape(len(prompts), -1, res, res, item.shape[-1])[select] |
| 197 | out.append(cross_maps) |
| 198 | out = torch.cat(out, dim=0) |
| 199 | out = out.sum(0) / out.shape[0] |
| 200 | return out.cpu() |
| 201 | |
| 202 | def aggregate_attention_all(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int, len_tokens: int): |
| 203 | attention_maps = attention_store.get_average_attention() |
nothing calls this directly
no test coverage detected