Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flat hand mean #301

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions mmhuman3d/models/body_models/mano.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
convert_kps,
get_keypoint_num,
)
from mmhuman3d.utils.transforms import aa_to_rotmat, rotmat_to_aa


class MANO(_MANO):
Expand Down Expand Up @@ -203,6 +204,7 @@ def __init__(self,
self.num_verts = self.get_num_verts()
self.num_faces = self.get_num_faces()
self.num_joints = get_keypoint_num(convention=self.keypoint_dst)
self.flat_hand_mean = kwargs['flat_hand_mean']

def forward(self,
*args,
Expand All @@ -222,6 +224,12 @@ def forward(self,
"""
if 'right_hand_pose' in kwargs:
kwargs['hand_pose'] = kwargs['right_hand_pose']

if not self.flat_hand_mean:
right_hand_pose = rotmat_to_aa(kwargs['right_hand_pose'])
right_hand_pose = right_hand_pose + self.hand_mean.reshape(-1, 3)
kwargs['hand_pose'] = aa_to_rotmat(right_hand_pose)

mano_output = super(MANOLayer, self).forward(*args, **kwargs)
joints = mano_output.joints

Expand Down
13 changes: 13 additions & 0 deletions mmhuman3d/models/body_models/smplx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
get_keypoint_num,
)
from mmhuman3d.core.conventions.segmentation import body_segmentation
from mmhuman3d.utils.transforms import aa_to_rotmat, rotmat_to_aa


class SMPLX(_SMPLX):
Expand Down Expand Up @@ -315,6 +316,7 @@ def __init__(self,
self.num_verts = self.get_num_verts()
self.num_joints = get_keypoint_num(convention=self.keypoint_dst)
self.body_part_segmentation = body_segmentation('smplx')
self.flat_hand_mean = kwargs['flat_hand_mean']

def forward(self,
*args,
Expand All @@ -333,6 +335,17 @@ def forward(self,
output: contains output parameters and attributes
"""

if not self.flat_hand_mean:
right_hand_pose = rotmat_to_aa(kwargs['right_hand_pose'])
right_hand_pose = right_hand_pose + self.right_hand_mean.reshape(
-1, 3)
kwargs['right_hand_pose'] = aa_to_rotmat(right_hand_pose)

left_hand_pose = rotmat_to_aa(kwargs['left_hand_pose'])
left_hand_pose = left_hand_pose + self.left_hand_mean.reshape(
-1, 3)
kwargs['left_hand_pose'] = aa_to_rotmat(left_hand_pose)

kwargs['get_skin'] = True
smplx_output = super(SMPLXLayer, self).forward(*args, **kwargs)

Expand Down