This module converts the model's output into the format expected by the coco api
| 1002 | |
| 1003 | |
| 1004 | class PostProcess_SMPLX_Multi_Infer(nn.Module): |
| 1005 | """ This module converts the model's output into the format expected by the coco api""" |
| 1006 | def __init__( |
| 1007 | self, |
| 1008 | num_select=100, |
| 1009 | nms_iou_threshold=-1, |
| 1010 | num_body_points=17, |
| 1011 | body_model= dict( |
| 1012 | type='smplx', |
| 1013 | keypoint_src='smplx', |
| 1014 | num_expression_coeffs=10, |
| 1015 | num_betas=10, |
| 1016 | gender='neutral', |
| 1017 | keypoint_dst='smplx_137', |
| 1018 | model_path='data/body_models/smplx', |
| 1019 | use_pca=False, |
| 1020 | use_face_contour=True) |
| 1021 | ) -> None: |
| 1022 | super().__init__() |
| 1023 | self.num_select = num_select |
| 1024 | self.nms_iou_threshold = nms_iou_threshold |
| 1025 | self.num_body_points=num_body_points |
| 1026 | |
| 1027 | # -1 for neutral; 0 for male; 1 for femal |
| 1028 | gender_body_model = {} |
| 1029 | gender_body_model[-1] = build_body_model(body_model) |
| 1030 | |
| 1031 | body_model['gender']='male' |
| 1032 | gender_body_model[0] = build_body_model(body_model) |
| 1033 | |
| 1034 | body_model['gender']='female' |
| 1035 | gender_body_model[1] = build_body_model(body_model) |
| 1036 | |
| 1037 | self.body_model = gender_body_model |
| 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'], \ |