(assignment_weights, x, codewords)
| 40 | |
| 41 | @staticmethod |
| 42 | def aggregate(assignment_weights, x, codewords): |
| 43 | num_codes, channels = codewords.size() |
| 44 | reshaped_codewords = codewords.view((1, 1, num_codes, channels)) |
| 45 | batch_size = x.size(0) |
| 46 | |
| 47 | expanded_x = x.unsqueeze(2).expand((batch_size, x.size(1), num_codes, channels)) |
| 48 | encoded_feat = (assignment_weights.unsqueeze(3) * (expanded_x - reshaped_codewords)).sum(dim=1) |
| 49 | return encoded_feat |
| 50 | |
| 51 | def forward(self, x): |
| 52 | assert x.dim() == 4 and x.size(1) == self.channels |