(self, height=8, width=8, channels=64)
| 126 | """ |
| 127 | |
| 128 | def __init__(self, height=8, width=8, channels=64): |
| 129 | h, w, d = height, width, channels |
| 130 | |
| 131 | p_h = torch.mul(torch.arange(1, h + 1).unsqueeze(1).float(), torch.ones(1, w).float()) * (np.pi / h) |
| 132 | p_w = torch.mul(torch.ones(h, 1).float(), torch.arange(1, w + 1).unsqueeze(0).float()) * (np.pi / w) |
| 133 | |
| 134 | # NOTE: I didn't quite see how U,V = 4 made sense given that the authors form the spatial |
| 135 | # basis by taking the outer product of the values. Still, I think what I have is aligned with what |
| 136 | # they did, but I am less confident in this step. |
| 137 | U = V = 8 # size of U, V. |
| 138 | u_basis = v_basis = torch.arange(1, U + 1).unsqueeze(0).float() |
| 139 | a = torch.mul(p_h.unsqueeze(2), u_basis) |
| 140 | b = torch.mul(p_w.unsqueeze(2), v_basis) |
| 141 | out = torch.einsum('hwu,hwv->hwuv', torch.cos(a), torch.cos(b)).reshape(h, w, d) |
| 142 | self.S = out |
| 143 | |
| 144 | def __call__(self, X): |
| 145 | # Stack the spatial bias (for each batch) and concat to the input. |
nothing calls this directly
no outgoing calls
no test coverage detected