(self, inputs)
| 371 | return histograms_normalized |
| 372 | |
| 373 | def forward(self, inputs): |
| 374 | x = self.compute_color_histograms(inputs) |
| 375 | |
| 376 | batch_size, time_window = x.shape[0], x.shape[1] |
| 377 | y = x.permute(dims=[0, 2, 1]) |
| 378 | similarities = torch.matmul(x, y) # [batch_size, time_window, time_window] |
| 379 | # note that it operates on dimensions of the input tensor in a backward fashion (from last dimension to the first dimension) |
| 380 | similarities_padded = F.pad(similarities, |
| 381 | pad=[(self.lookup_window - 1) // 2, (self.lookup_window - 1) // 2, 0, 0, 0, 0]) |
| 382 | |
| 383 | batch_indices = torch.arange(0, batch_size, device=self.device). \ |
| 384 | reshape(shape=[batch_size, 1, 1]). \ |
| 385 | repeat([1, time_window, self.lookup_window]) |
| 386 | time_indices = torch.arange(0, time_window, device=self.device). \ |
| 387 | reshape(shape=[1, time_window, 1]). \ |
| 388 | repeat([batch_size, 1, self.lookup_window]) |
| 389 | lookup_indices = torch.arange(0, self.lookup_window, device=self.device). \ |
| 390 | reshape(shape=[1, 1, self.lookup_window]). \ |
| 391 | repeat([batch_size, time_window, 1]) + time_indices |
| 392 | |
| 393 | indices = torch.stack([batch_indices, time_indices, lookup_indices], dim=-1) |
| 394 | |
| 395 | similarities = gather_nd(similarities_padded, indices) |
| 396 | |
| 397 | if self.fc is not None: |
| 398 | return self.fc(similarities) |
| 399 | return similarities |
| 400 | |
| 401 | |
| 402 | class ConvexCombinationRegularization(nn.Module): |
nothing calls this directly
no test coverage detected