Convert pose parameters to rotation matrix Args: param_dict: smplx parameters param_type: should be one of body/head/hand Returns: param_dict: smplx parameters
(self, param_dict, param_type)
| 408 | return param_dict |
| 409 | |
| 410 | def convert_pose(self, param_dict, param_type): |
| 411 | ''' Convert pose parameters to rotation matrix |
| 412 | Args: |
| 413 | param_dict: smplx parameters |
| 414 | param_type: should be one of body/head/hand |
| 415 | Returns: |
| 416 | param_dict: smplx parameters |
| 417 | ''' |
| 418 | assert param_type in ['body', 'head', 'hand'] |
| 419 | |
| 420 | # convert pose representations: the output from network are continous repre or axis angle, |
| 421 | # while the input pose for smplx need to be rotation matrix |
| 422 | for key in param_dict: |
| 423 | if "pose" in key and 'jaw' not in key: |
| 424 | param_dict[key] = converter.batch_cont2matrix(param_dict[key]) |
| 425 | if param_type == 'body' or param_type == 'head': |
| 426 | param_dict['jaw_pose'] = converter.batch_euler2matrix(param_dict['jaw_pose'])[ |
| 427 | :, None, :, :] |
| 428 | |
| 429 | # complement params if it's not in given param dict |
| 430 | if param_type == 'head': |
| 431 | batch_size = param_dict['shape'].shape[0] |
| 432 | param_dict['abs_head_pose'] = param_dict['head_pose'].clone() |
| 433 | param_dict['global_pose'] = param_dict['head_pose'] |
| 434 | param_dict['partbody_pose'] = self.smplx.body_pose.unsqueeze(0).expand( |
| 435 | batch_size, -1, -1, -1)[:, :self.param_list_dict['body_list']['partbody_pose']] |
| 436 | param_dict['neck_pose'] = self.smplx.neck_pose.unsqueeze( |
| 437 | 0).expand(batch_size, -1, -1, -1) |
| 438 | param_dict['left_wrist_pose'] = self.smplx.neck_pose.unsqueeze( |
| 439 | 0).expand(batch_size, -1, -1, -1) |
| 440 | param_dict['left_hand_pose'] = self.smplx.left_hand_pose.unsqueeze( |
| 441 | 0).expand(batch_size, -1, -1, -1) |
| 442 | param_dict['right_wrist_pose'] = self.smplx.neck_pose.unsqueeze( |
| 443 | 0).expand(batch_size, -1, -1, -1) |
| 444 | param_dict['right_hand_pose'] = self.smplx.right_hand_pose.unsqueeze( |
| 445 | 0).expand(batch_size, -1, -1, -1) |
| 446 | elif param_type == 'hand': |
| 447 | batch_size = param_dict['right_hand_pose'].shape[0] |
| 448 | param_dict['abs_right_wrist_pose'] = param_dict['right_wrist_pose'].clone() |
| 449 | dtype = param_dict['right_hand_pose'].dtype |
| 450 | device = param_dict['right_hand_pose'].device |
| 451 | x_180_pose = torch.eye( |
| 452 | 3, dtype=dtype, device=device).unsqueeze(0).repeat(1, 1, 1) |
| 453 | x_180_pose[0, 2, 2] = -1. |
| 454 | x_180_pose[0, 1, 1] = -1. |
| 455 | param_dict['global_pose'] = x_180_pose.unsqueeze( |
| 456 | 0).expand(batch_size, -1, -1, -1) |
| 457 | param_dict['shape'] = self.smplx.shape_params.expand( |
| 458 | batch_size, -1) |
| 459 | param_dict['exp'] = self.smplx.expression_params.expand( |
| 460 | batch_size, -1) |
| 461 | param_dict['head_pose'] = self.smplx.head_pose.unsqueeze( |
| 462 | 0).expand(batch_size, -1, -1, -1) |
| 463 | param_dict['neck_pose'] = self.smplx.neck_pose.unsqueeze( |
| 464 | 0).expand(batch_size, -1, -1, -1) |
| 465 | param_dict['jaw_pose'] = self.smplx.jaw_pose.unsqueeze( |
| 466 | 0).expand(batch_size, -1, -1, -1) |
| 467 | param_dict['partbody_pose'] = self.smplx.body_pose.unsqueeze(0).expand( |