(self, x)
| 37 | |
| 38 | |
| 39 | def forward(self, x): |
| 40 | B, C = x.shape[:2] |
| 41 | h = x |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | q = self.q(h).reshape(B,C,-1) |
| 47 | k = self.k(h).reshape(B,C,-1) |
| 48 | v = self.v(h).reshape(B,C,-1) |
| 49 | |
| 50 | qk = torch.matmul(q.permute(0, 2, 1), k) #* (int(C) ** (-0.5)) |
| 51 | |
| 52 | w = self.sm(qk) |
| 53 | |
| 54 | h = torch.matmul(v, w.permute(0, 2, 1)).reshape(B,C,*x.shape[2:]) |
| 55 | |
| 56 | h = self.out(h) |
| 57 | |
| 58 | x = h + x |
| 59 | |
| 60 | x = self.nonlin(self.norm(x)) |
| 61 | |
| 62 | return x |
| 63 | |
| 64 | class PVConv(nn.Module): |
| 65 | def __init__(self, in_channels, out_channels, kernel_size, resolution, attention=False, |
nothing calls this directly
no outgoing calls
no test coverage detected