Forward function. Args: sweep_imgs(Tensor): Input images with shape of (B, num_sweeps, num_cameras, 3, H, W). mats_dict(dict): sensor2ego_mats(Tensor): Transformation matrix from camera to ego with shape of (B, num_s
(self,
img,
img_metas,
timestamps=None,
is_return_depth=False)
| 635 | |
| 636 | @auto_fp16() |
| 637 | def forward(self, |
| 638 | img, |
| 639 | img_metas, |
| 640 | timestamps=None, |
| 641 | is_return_depth=False): |
| 642 | """Forward function. |
| 643 | Args: |
| 644 | sweep_imgs(Tensor): Input images with shape of (B, num_sweeps, |
| 645 | num_cameras, 3, H, W). |
| 646 | mats_dict(dict): |
| 647 | sensor2ego_mats(Tensor): Transformation matrix from |
| 648 | camera to ego with shape of (B, num_sweeps, |
| 649 | num_cameras, 4, 4). |
| 650 | intrin_mats(Tensor): Intrinsic matrix with shape |
| 651 | of (B, num_sweeps, num_cameras, 4, 4). |
| 652 | ida_mats(Tensor): Transformation matrix for ida with |
| 653 | shape of (B, num_sweeps, num_cameras, 4, 4). |
| 654 | sensor2sensor_mats(Tensor): Transformation matrix |
| 655 | from key frame camera to sweep frame camera with |
| 656 | shape of (B, num_sweeps, num_cameras, 4, 4). |
| 657 | timestamps(Tensor): Timestamp for all images with the shape of(B, |
| 658 | num_sweeps, num_cameras). |
| 659 | |
| 660 | Return: |
| 661 | Tensor: bev feature map. |
| 662 | """ |
| 663 | if img.dim() == 5: |
| 664 | img = img.unsqueeze(1) |
| 665 | |
| 666 | batch_size, num_sweeps, num_cams, num_channels, img_height, \ |
| 667 | img_width = img.shape |
| 668 | |
| 669 | intrins, ida, sensor2ego = [], [], [] |
| 670 | for b in range(len(img_metas)): |
| 671 | _intrins, _ida, _sensor2ego = [], [], [] |
| 672 | for sweep_idx in range(len(img_metas[0])): |
| 673 | mats = img_metas[b][sweep_idx] |
| 674 | intrinsic_mat = torch.zeros((num_cams,4,4)) |
| 675 | intrinsic_mat[:,:3,:3] = mats['cam_intrinsic'] |
| 676 | intrinsic_mat[:,3,3] = 1 |
| 677 | _intrins.append(intrinsic_mat) |
| 678 | _ida.append(mats['ida_mats']) # Nx4x4 |
| 679 | _sensor2ego.append(mats['currlidar2keycam'].permute(0,2,1)) # cam2lidar |
| 680 | intrins.append(torch.stack(_intrins)) |
| 681 | sensor2ego.append(torch.stack(_sensor2ego)) |
| 682 | ida.append(torch.stack(_ida)) |
| 683 | intrins, ida, sensor2ego = torch.stack(intrins), torch.stack(ida), torch.stack(sensor2ego) |
| 684 | |
| 685 | old_img_metas = img_metas |
| 686 | img_metas = {} |
| 687 | img_metas['intrin_mats'] = intrins.to(img.device) |
| 688 | img_metas['sensor2ego_mats'] = sensor2ego.to(img.device) |
| 689 | img_metas['ida_mats'] = ida.to(img.device) |
| 690 | |
| 691 | key_frame_res = self._forward_single_sweep( |
| 692 | -1, |
| 693 | img[:, -1:, ...], |
| 694 | img_metas, |
nothing calls this directly
no test coverage detected