image_shape(target_sizes): input image shape
(self, outputs, target_sizes, targets, data_batch_nc, image_shape= None, not_to_xyxy=False, test=False)
| 1038 | |
| 1039 | @torch.no_grad() |
| 1040 | def forward(self, outputs, target_sizes, targets, data_batch_nc, image_shape= None, not_to_xyxy=False, test=False): |
| 1041 | """ |
| 1042 | image_shape(target_sizes): input image shape |
| 1043 | |
| 1044 | """ |
| 1045 | # import pdb; pdb.set_trace() |
| 1046 | batch_size = outputs['pred_keypoints'].shape[0] |
| 1047 | results = [] |
| 1048 | device = outputs['pred_keypoints'].device |
| 1049 | # for body_model in self.body_model.values(): |
| 1050 | # body_model.to(device) |
| 1051 | |
| 1052 | pred_kp_coco = outputs['pred_keypoints'] |
| 1053 | num_select = self.num_select |
| 1054 | out_logits, out_bbox= outputs['pred_logits'], outputs['pred_boxes'] |
| 1055 | |
| 1056 | out_body_bbox, out_lhand_bbox, out_rhand_bbox, out_face_bbox = \ |
| 1057 | outputs['pred_boxes'], outputs['pred_lhand_boxes'], \ |
| 1058 | outputs['pred_rhand_boxes'], outputs['pred_face_boxes'] |
| 1059 | |
| 1060 | out_smpl_pose, out_smpl_beta, out_smpl_expr, out_smpl_cam, out_smpl_kp3d, out_smpl_verts = \ |
| 1061 | outputs['pred_smpl_fullpose'], outputs['pred_smpl_beta'], outputs['pred_smpl_expr'], \ |
| 1062 | outputs['pred_smpl_cam'], outputs['pred_smpl_kp3d'], outputs['pred_smpl_verts'] |
| 1063 | |
| 1064 | out_smpl_kp2d = [] |
| 1065 | for bs in range(batch_size): |
| 1066 | out_kp3d_i = out_smpl_kp3d[bs] |
| 1067 | out_cam_i = out_smpl_cam[bs] |
| 1068 | out_img_shape = data_batch_nc['img_shape'][bs].flip(-1)[None] |
| 1069 | |
| 1070 | out_kp2d_i = project_points_new( |
| 1071 | points_3d=out_kp3d_i, |
| 1072 | pred_cam=out_cam_i, |
| 1073 | focal_length=5000, |
| 1074 | camera_center=out_img_shape/2 |
| 1075 | ) |
| 1076 | out_smpl_kp2d.append(out_kp2d_i.detach().cpu().numpy()) |
| 1077 | out_smpl_kp2d = torch.tensor(out_smpl_kp2d).to(device) |
| 1078 | |
| 1079 | |
| 1080 | # assert len(out_logits) == len(target_sizes) |
| 1081 | # assert target_sizes.shape[1] == 2 |
| 1082 | |
| 1083 | prob = out_logits.sigmoid() |
| 1084 | topk_values, topk_indexes = \ |
| 1085 | torch.topk(prob.view(out_logits.shape[0], -1), num_select, dim=1) |
| 1086 | scores = topk_values |
| 1087 | |
| 1088 | # bbox |
| 1089 | topk_boxes = topk_indexes // out_logits.shape[2] |
| 1090 | labels = topk_indexes % out_logits.shape[2] |
| 1091 | |
| 1092 | if not_to_xyxy: |
| 1093 | boxes = out_bbox |
| 1094 | else: |
| 1095 | boxes = box_ops.box_cxcywh_to_xyxy(out_bbox) |
| 1096 | out_body_bbox = box_ops.box_cxcywh_to_xyxy(out_body_bbox) |
| 1097 | out_lhand_bbox = box_ops.box_cxcywh_to_xyxy(out_lhand_bbox) |
nothing calls this directly
no test coverage detected