(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int, len_tokens: int)
| 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() |
| 204 | |
| 205 | out = [] |
| 206 | for _, value in attention_maps.items(): |
| 207 | |
| 208 | |
| 209 | for item in value: |
| 210 | res = int(math.sqrt(item.shape[1])) |
| 211 | cross_maps = item.reshape(len(prompts), -1, res , res, item.shape[-1])[select] |
| 212 | if res!=16: |
| 213 | continue |
| 214 | cross_maps_512 = torch.zeros((cross_maps.shape[0], 256, 256, 77)) |
| 215 | for token in range(len_tokens): |
| 216 | token_cross_map = cross_maps[:, :, :, token].reshape(1, cross_maps.shape[0], res, res) |
| 217 | token_cross_map = F.interpolate(token_cross_map, size=(256, 256), mode='bicubic').reshape(cross_maps.shape[0], 256, 256) |
| 218 | cross_maps_512[:, :, :, token] = token_cross_map[:, :, :] |
| 219 | out.append(cross_maps_512) |
| 220 | out = torch.cat(out, dim=0) |
| 221 | out = out.sum(0) / out.shape[0] |
| 222 | |
| 223 | absolute = True |
| 224 | if not absolute: |
| 225 | out = (out - out.min()) / (out.max() - out.min() + 1e-8) |
| 226 | |
| 227 | return out.cpu() |
| 228 | |
| 229 | |
| 230 | def aggregate_attention_all_step(prompts, attention_store: AttentionStore, res: int, from_where: List[str], is_cross: bool, select: int, len_tokens: int): |
no test coverage detected