simplified flatten

This commit is contained in:
Jong Wook Kim 2022-07-21 12:51:00 -07:00
parent 5eb1828ead
commit 2fc776c0f9
1 changed files with 1 additions and 1 deletions

View File

@ -66,7 +66,7 @@ class AttentionPool2d(nn.Module):
self.num_heads = num_heads
def forward(self, x):
x = x.reshape(x.shape[0], x.shape[1], x.shape[2] * x.shape[3]).permute(2, 0, 1) # NCHW -> (HW)NC
x = x.flatten(start_dim=2).permute(2, 0, 1) # NCHW -> (HW)NC
x = torch.cat([x.mean(dim=0, keepdim=True), x], dim=0) # (HW+1)NC
x = x + self.positional_embedding[:, None, :].to(x.dtype) # (HW+1)NC
x, _ = F.multi_head_attention_forward(