| 725 | |
| 726 | |
| 727 | class SMPLHLayer(SMPLH): |
| 728 | def __init__(self, *args, **kwargs) -> None: |
| 729 | """SMPL+H as a layer model constructor.""" |
| 730 | super(SMPLHLayer, self).__init__(create_global_orient=False, |
| 731 | create_body_pose=False, |
| 732 | create_left_hand_pose=False, |
| 733 | create_right_hand_pose=False, |
| 734 | create_betas=False, |
| 735 | create_transl=False, |
| 736 | *args, |
| 737 | **kwargs) |
| 738 | |
| 739 | def forward(self, |
| 740 | betas: Optional[Tensor] = None, |
| 741 | global_orient: Optional[Tensor] = None, |
| 742 | body_pose: Optional[Tensor] = None, |
| 743 | left_hand_pose: Optional[Tensor] = None, |
| 744 | right_hand_pose: Optional[Tensor] = None, |
| 745 | transl: Optional[Tensor] = None, |
| 746 | return_verts: bool = True, |
| 747 | return_full_pose: bool = False, |
| 748 | pose2rot: bool = True, |
| 749 | **kwargs) -> SMPLHOutput: |
| 750 | """""" |
| 751 | device, dtype = self.shapedirs.device, self.shapedirs.dtype |
| 752 | if global_orient is None: |
| 753 | batch_size = 1 |
| 754 | global_orient = torch.zeros(3, device=device, dtype=dtype).view( |
| 755 | 1, 1, 3).expand(batch_size, -1, -1).contiguous() |
| 756 | else: |
| 757 | batch_size = global_orient.shape[0] |
| 758 | if body_pose is None: |
| 759 | body_pose = torch.zeros(3, device=device, dtype=dtype).view( |
| 760 | 1, 1, 3).expand(batch_size, 21, -1).contiguous() |
| 761 | if left_hand_pose is None: |
| 762 | left_hand_pose = torch.zeros(3, device=device, dtype=dtype).view( |
| 763 | 1, 1, 3).expand(batch_size, 15, -1).contiguous() |
| 764 | if right_hand_pose is None: |
| 765 | right_hand_pose = torch.zeros(3, device=device, dtype=dtype).view( |
| 766 | 1, 1, 3).expand(batch_size, 15, -1).contiguous() |
| 767 | if betas is None: |
| 768 | betas = torch.zeros([batch_size, self.num_betas], |
| 769 | dtype=dtype, |
| 770 | device=device) |
| 771 | if transl is None: |
| 772 | transl = torch.zeros([batch_size, 3], dtype=dtype, device=device) |
| 773 | |
| 774 | # Concatenate all pose vectors |
| 775 | full_pose = torch.cat([ |
| 776 | global_orient.reshape(-1, 1, 3), |
| 777 | body_pose.reshape(-1, self.NUM_BODY_JOINTS, 3), |
| 778 | left_hand_pose.reshape(-1, self.NUM_HAND_JOINTS, 3), |
| 779 | right_hand_pose.reshape(-1, self.NUM_HAND_JOINTS, 3) |
| 780 | ], |
| 781 | dim=1) |
| 782 | |
| 783 | vertices, joints = lbs(betas, |
| 784 | full_pose, |