From a31bca95372d4dd0c15f3b74b2f816713a8566f2 Mon Sep 17 00:00:00 2001 From: YifuXu1127 <2020xyf@sjtu.edu.cn> Date: Tue, 22 Oct 2024 23:34:02 +0800 Subject: [PATCH] Left Hand --- manotorch/axislayer.py | 15 +++++++++++---- scripts/simple_anatomy_loss.py | 3 ++- scripts/simple_app.py | 4 ++-- scripts/simple_compose.py | 3 ++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/manotorch/axislayer.py b/manotorch/axislayer.py index a3679b9..2ed9e40 100644 --- a/manotorch/axislayer.py +++ b/manotorch/axislayer.py @@ -12,11 +12,15 @@ class AxisAdaptiveLayer(torch.nn.Module): - def __init__(self): + def __init__(self, side: str = "right"): super(AxisAdaptiveLayer, self).__init__() self.joints_mapping = [5, 6, 7, 9, 10, 11, 17, 18, 19, 13, 14, 15, 1, 2, 3] self.parent_joints_mappings = [0, 5, 6, 0, 9, 10, 0, 17, 18, 0, 13, 14, 0, 1, 2] - up_axis_base = np.vstack((np.array([[0, 1, 0]]).repeat(13, axis=0), np.array([[1, 1, 1]]).repeat(3, axis=0))) + self.side = side + if side == "right": + up_axis_base = np.vstack((np.array([[0, 1, 0]]).repeat(13, axis=0), np.array([[1, 1, 1]]).repeat(3, axis=0))) + elif side == "left": + up_axis_base = np.vstack((np.array([[0, 1, 0]]).repeat(13, axis=0), np.array([[-1, 1, 1]]).repeat(3, axis=0))) self.register_buffer("up_axis_base", torch.from_numpy(up_axis_base).float().unsqueeze(0)) def forward(self, hand_joints, transf): @@ -34,7 +38,10 @@ def forward(self, hand_joints, transf): # b_axis = hand_joints[:, self.joints_mapping] - hand_joints[:, [i + 1 for i in self.joints_mapping]] b_axis = hand_joints[:, self.parent_joints_mappings] - hand_joints[:, self.joints_mapping] b_axis = (transf[:, 1:, :3, :3].transpose(2, 3) @ b_axis.unsqueeze(-1)).squeeze(-1) - b_axis_init = torch.tensor([1, 0, 0]).float().unsqueeze(0).unsqueeze(0).repeat(bs, 1, 1).to(b_axis.device) + if self.side == "right": + b_axis_init = torch.tensor([1, 0, 0]).float().unsqueeze(0).unsqueeze(0).repeat(bs, 1, 1).to(b_axis.device) + elif self.side == "left": + b_axis_init = torch.tensor([-1, 0, 0]).float().unsqueeze(0).unsqueeze(0).repeat(bs, 1, 1).to(b_axis.device) b_axis = torch.cat((b_axis_init, b_axis), dim=1) # (B, 16, 3) l_axis = torch.cross(b_axis, self.up_axis_base.expand(bs, 16, 3)) @@ -60,7 +67,7 @@ def __init__(self, side: str = "right", mano_assets_root: str = "assets/mano"): tmpl_joints = tmpl_mano.joints tmpl_transf_abs = tmpl_mano.transforms_abs # tmpl_T_g_p - tmpl_b_axis, tmpl_u_axis, tmpl_l_axis = AxisAdaptiveLayer()(tmpl_joints, tmpl_transf_abs) # (1, 16, 3) + tmpl_b_axis, tmpl_u_axis, tmpl_l_axis = AxisAdaptiveLayer(side=side)(tmpl_joints, tmpl_transf_abs) # (1, 16, 3) tmpl_R_p_a = torch.cat((tmpl_b_axis.unsqueeze(-1), tmpl_u_axis.unsqueeze(-1), tmpl_l_axis.unsqueeze(-1)), dim=3) zero_tsl = torch.zeros(1, 16, 3, 1) zero_pad = torch.tensor([[[[0, 0, 0, 1]]]]).repeat(*zero_tsl.shape[0:2], 1, 1) diff --git a/scripts/simple_anatomy_loss.py b/scripts/simple_anatomy_loss.py index f69e888..cc4ee1b 100644 --- a/scripts/simple_anatomy_loss.py +++ b/scripts/simple_anatomy_loss.py @@ -25,10 +25,11 @@ def main(): center_idx=9, mano_assets_root="assets/mano", use_pca=False, + side="right", flat_hand_mean=True) hand_faces = mano_layer.th_faces # (NF, 3) - axisFK = AxisLayerFK(mano_assets_root="assets/mano") + axisFK = AxisLayerFK(side=mano_layer.side,mano_assets_root="assets/mano") anatomyLoss = AnatomyConstraintLossEE() anatomyLoss.setup() diff --git a/scripts/simple_app.py b/scripts/simple_app.py index 289c1c8..bf10ea2 100644 --- a/scripts/simple_app.py +++ b/scripts/simple_app.py @@ -19,7 +19,7 @@ def main(args): mano_assets_root="assets/mano", flat_hand_mean=False, ) - axis_layer = AxisLayerFK(mano_assets_root="assets/mano") + axis_layer = AxisLayerFK(side=mano_layer.side, mano_assets_root="assets/mano") anchor_layer = AnchorLayer(anchor_root="assets/anchor") BS = 1 @@ -42,7 +42,7 @@ def main(args): bul_axes_loc = torch.eye(3).reshape(1, 1, 3, 3).repeat(BS, 16, 1, 1).to(verts.device) bul_axes_glb = torch.matmul(T_g_a[:, :, :3, :3], bul_axes_loc) # (B, 16, 3, 3) - b_axes_dir = bul_axes_glb[:, :, :, 0].numpy() # bend direction (B, 16, 3) + b_axes_dir = bul_axes_glb[:, :, :, 0].numpy() # back direction (B, 16, 3) u_axes_dir = bul_axes_glb[:, :, :, 1].numpy() # up direction (B, 16, 3) l_axes_dir = bul_axes_glb[:, :, :, 2].numpy() # left direction (B, 16, 3) diff --git a/scripts/simple_compose.py b/scripts/simple_compose.py index c3948c9..c81bb0e 100644 --- a/scripts/simple_compose.py +++ b/scripts/simple_compose.py @@ -13,10 +13,11 @@ def main(): center_idx=9, mano_assets_root="assets/mano", use_pca=False, + side="right", flat_hand_mean=True) hand_faces = mano_layer.th_faces # (NF, 3) - axisFK = AxisLayerFK(mano_assets_root="assets/mano") + axisFK = AxisLayerFK(side=mano_layer.side,mano_assets_root="assets/mano") composed_ee = torch.zeros((1, 16, 3)) # transform order of right hand