(b, nb_agent_idx, local_com_mat, all_warp, device, size)
| 339 | @staticmethod |
| 340 | # FIXME: rename 'j' |
| 341 | def feature_transformation(b, nb_agent_idx, local_com_mat, all_warp, device, size): |
| 342 | nb_agent = torch.unsqueeze(local_com_mat[b, nb_agent_idx], 0) # [1 512 16 16] |
| 343 | nb_warp = all_warp[nb_agent_idx] # [4 4] |
| 344 | # normalize the translation vector |
| 345 | x_trans = (4 * nb_warp[0, 3]) / 128 |
| 346 | y_trans = -(4 * nb_warp[1, 3]) / 128 |
| 347 | |
| 348 | theta_rot = torch.tensor( |
| 349 | [[nb_warp[0, 0], nb_warp[0, 1], 0.0], [nb_warp[1, 0], nb_warp[1, 1], 0.0]]).type( |
| 350 | dtype=torch.float).to(device) |
| 351 | theta_rot = torch.unsqueeze(theta_rot, 0) |
| 352 | grid_rot = F.affine_grid(theta_rot, size=torch.Size(size)) # get grid for grid sample |
| 353 | |
| 354 | theta_trans = torch.tensor([[1.0, 0.0, x_trans], [0.0, 1.0, y_trans]]).type(dtype=torch.float).to( |
| 355 | device) |
| 356 | theta_trans = torch.unsqueeze(theta_trans, 0) |
| 357 | grid_trans = F.affine_grid(theta_trans, size=torch.Size(size)) # get grid for grid sample |
| 358 | |
| 359 | # first rotate the feature map, then translate it |
| 360 | warp_feat_rot = F.grid_sample(nb_agent, grid_rot, mode='nearest') |
| 361 | warp_feat_trans = F.grid_sample(warp_feat_rot, grid_trans, mode='nearest') |
| 362 | return torch.squeeze(warp_feat_trans, dim=0) # [512, 16, 16] |
| 363 | |
| 364 | |
| 365 | def build_neighbors_feature_list(self, b, agent_idx, all_warp, num_agent, local_com_mat, device, |
no outgoing calls
no test coverage detected