Skip to content

Commit

Permalink
Concise TransformerBlock() (#3821)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Jun 29, 2021
1 parent 5ea771d commit 57c5d02
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,8 @@ def forward(self, x):
if self.conv is not None:
x = self.conv(x)
b, _, w, h = x.shape
p = x.flatten(2)
p = p.unsqueeze(0)
p = p.transpose(0, 3)
p = p.squeeze(3)
e = self.linear(p)
x = p + e

x = self.tr(x)
x = x.unsqueeze(3)
x = x.transpose(0, 3)
x = x.reshape(b, self.c2, w, h)
return x
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)


class Bottleneck(nn.Module):
Expand Down

0 comments on commit 57c5d02

Please sign in to comment.