MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / forward

Method forward

detrsmpl/models/body_models/mano.py:76–125  ·  view source on GitHub ↗

Forward function. Args: *args: extra arguments for MANO return_verts: whether to return vertices return_full_pose: whether to return full pose parameters **kwargs: extra arguments for MANO Returns: output: contains output

(self,
                *args,
                return_verts: bool = True,
                return_full_pose: bool = False,
                **kwargs)

Source from the content-addressed store, hash-verified

74 self.num_joints = get_keypoint_num(convention=self.keypoint_dst)
75
76 def forward(self,
77 *args,
78 return_verts: bool = True,
79 return_full_pose: bool = False,
80 **kwargs) -> dict:
81 """Forward function.
82
83 Args:
84 *args: extra arguments for MANO
85 return_verts: whether to return vertices
86 return_full_pose: whether to return full pose parameters
87 **kwargs: extra arguments for MANO
88
89 Returns:
90 output: contains output parameters and attributes
91 """
92 if 'right_hand_pose' in kwargs:
93 kwargs['hand_pose'] = kwargs['right_hand_pose']
94 mano_output = super(MANO, self).forward(*args, **kwargs)
95 joints = mano_output.joints
96
97 joints = self.get_keypoints_from_mesh(mano_output.vertices, joints)
98
99 joints, joint_mask = convert_kps(joints,
100 src=self.keypoint_src,
101 dst=self.keypoint_dst,
102 approximate=self.keypoint_approximate)
103 if isinstance(joint_mask, np.ndarray):
104 joint_mask = torch.tensor(joint_mask,
105 dtype=torch.uint8,
106 device=joints.device)
107
108 batch_size = joints.shape[0]
109 joint_mask = joint_mask.reshape(1, -1).expand(batch_size, -1)
110
111 output = dict(
112 global_orient=mano_output.global_orient,
113 hand_pose=mano_output.hand_pose,
114 joints=joints,
115 joint_mask=joint_mask,
116 keypoints=torch.cat([joints, joint_mask[:, :, None]], dim=-1),
117 betas=mano_output.betas,
118 )
119
120 if return_verts:
121 output['vertices'] = mano_output.vertices
122 if return_full_pose:
123 output['full_pose'] = mano_output.full_pose
124
125 return output
126
127 def get_keypoints_from_mesh(self, mesh_vertices, keypoints_regressed):
128 """Assembles the full 21 keypoint set from the 16 Mano Keypoints and 5

Callers 1

forwardMethod · 0.45

Calls 2

convert_kpsFunction · 0.90

Tested by

no test coverage detected