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

Method forward

detrsmpl/models/body_models/mano.py:207–256  ·  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

205 self.num_joints = get_keypoint_num(convention=self.keypoint_dst)
206
207 def forward(self,
208 *args,
209 return_verts: bool = True,
210 return_full_pose: bool = False,
211 **kwargs) -> dict:
212 """Forward function.
213
214 Args:
215 *args: extra arguments for MANO
216 return_verts: whether to return vertices
217 return_full_pose: whether to return full pose parameters
218 **kwargs: extra arguments for MANO
219
220 Returns:
221 output: contains output parameters and attributes
222 """
223 if 'right_hand_pose' in kwargs:
224 kwargs['hand_pose'] = kwargs['right_hand_pose']
225 mano_output = super(MANOLayer, self).forward(*args, **kwargs)
226 joints = mano_output.joints
227
228 joints = self.get_keypoints_from_mesh(mano_output.vertices, joints)
229
230 joints, joint_mask = convert_kps(joints,
231 src=self.keypoint_src,
232 dst=self.keypoint_dst,
233 approximate=self.keypoint_approximate)
234 if isinstance(joint_mask, np.ndarray):
235 joint_mask = torch.tensor(joint_mask,
236 dtype=torch.uint8,
237 device=joints.device)
238
239 batch_size = joints.shape[0]
240 joint_mask = joint_mask.reshape(1, -1).expand(batch_size, -1)
241
242 output = dict(
243 global_orient=mano_output.global_orient,
244 hand_pose=mano_output.hand_pose,
245 joints=joints,
246 joint_mask=joint_mask,
247 keypoints=torch.cat([joints, joint_mask[:, :, None]], dim=-1),
248 betas=mano_output.betas,
249 )
250
251 if return_verts:
252 output['vertices'] = mano_output.vertices
253 if return_full_pose:
254 output['full_pose'] = mano_output.full_pose
255
256 return output
257
258 def get_keypoints_from_mesh(self, mesh_vertices, keypoints_regressed):
259 """Assembles the full 21 keypoint set from the 16 Mano Keypoints and 5

Callers

nothing calls this directly

Calls 3

convert_kpsFunction · 0.90
forwardMethod · 0.45

Tested by

no test coverage detected