Replace 2 transpose() with 1 permute in TransformerBlock()` (#5645)

This commit is contained in:
Ding Yiwei 2021-11-15 17:06:18 +08:00 committed by GitHub
parent 540ef0dd30
commit c2523be634
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -86,8 +86,8 @@ class TransformerBlock(nn.Module):
if self.conv is not None:
x = self.conv(x)
b, _, w, h = x.shape
p = x.flatten(2).unsqueeze(0).transpose(0, 3).squeeze(3)
return self.tr(p + self.linear(p)).unsqueeze(3).transpose(0, 3).reshape(b, self.c2, w, h)
p = x.flatten(2).permute(2, 0, 1)
return self.tr(p + self.linear(p)).permute(1, 2, 0).reshape(b, self.c2, w, h)
class Bottleneck(nn.Module):