From b2bcc9210425b7c1e98d055b2e7c7963a554cfcb Mon Sep 17 00:00:00 2001 From: shuaiqing Date: Sat, 21 Sep 2019 12:03:37 +0800 Subject: [PATCH 1/7] :hammer: modify body_models --- smplx/body_models.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/smplx/body_models.py b/smplx/body_models.py index 4f14328..7c9823a 100644 --- a/smplx/body_models.py +++ b/smplx/body_models.py @@ -10,7 +10,8 @@ # # Copyright©2019 Max-Planck-Gesellschaft zur Förderung # der Wissenschaften e.V. (MPG). acting on behalf of its Max Planck Institute -# for Intelligent Systems. All rights reserved. +# for Intelligent Systems and the Max Planck Institute for Biological +# Cybernetics. All rights reserved. # # Contact: ps-license@tuebingen.mpg.de @@ -872,24 +873,25 @@ def forward(self, betas=None, global_orient=None, body_pose=None, # If no shape and pose parameters are passed along, then use the # ones from the module - global_orient = (global_orient if global_orient is not None else - self.global_orient) + body_pose = body_pose if body_pose is not None else self.body_pose - betas = betas if betas is not None else self.betas + bn = body_pose.shape[0] + global_orient = (global_orient if global_orient is not None else + self.global_orient[:bn]) + betas = betas if betas is not None else self.betas[:bn] left_hand_pose = (left_hand_pose if left_hand_pose is not None else self.left_hand_pose) right_hand_pose = (right_hand_pose if right_hand_pose is not None else self.right_hand_pose) - jaw_pose = jaw_pose if jaw_pose is not None else self.jaw_pose - leye_pose = leye_pose if leye_pose is not None else self.leye_pose - reye_pose = reye_pose if reye_pose is not None else self.reye_pose - expression = expression if expression is not None else self.expression - + jaw_pose = jaw_pose if jaw_pose is not None else self.jaw_pose[:bn] + leye_pose = leye_pose if leye_pose is not None else self.leye_pose[:bn] + reye_pose = reye_pose if reye_pose is not None else self.reye_pose[:bn] + expression = expression if expression is not None else self.expression[:bn] apply_trans = transl is not None or hasattr(self, 'transl') if transl is None: if hasattr(self, 'transl'): - transl = self.transl + transl = self.transl[:bn] if self.use_pca: left_hand_pose = torch.einsum( @@ -897,10 +899,10 @@ def forward(self, betas=None, global_orient=None, body_pose=None, right_hand_pose = torch.einsum( 'bi,ij->bj', [right_hand_pose, self.right_hand_components]) - full_pose = torch.cat([global_orient, body_pose, - jaw_pose, leye_pose, reye_pose, - left_hand_pose, - right_hand_pose], dim=1) + full_pose = torch.cat([global_orient[:bn], body_pose[:bn], + jaw_pose[:bn], leye_pose[:bn], reye_pose[:bn], + left_hand_pose[:bn], + right_hand_pose[:bn]], dim=1) # Add the mean pose of the model. Does not affect the body, only the # hands when flat_hand_mean == False @@ -923,7 +925,7 @@ def forward(self, betas=None, global_orient=None, body_pose=None, lmk_faces_idx = self.lmk_faces_idx.unsqueeze( dim=0).expand(batch_size, -1).contiguous() lmk_bary_coords = self.lmk_bary_coords.unsqueeze(dim=0).repeat( - self.batch_size, 1, 1) + batch_size, 1, 1) if self.use_face_contour: dyn_lmk_faces_idx, dyn_lmk_bary_coords = find_dynamic_lmk_idx_and_bcoords( vertices, full_pose, self.dynamic_lmk_faces_idx, @@ -935,7 +937,6 @@ def forward(self, betas=None, global_orient=None, body_pose=None, lmk_bary_coords = torch.cat( [lmk_bary_coords.expand(batch_size, -1, -1), dyn_lmk_bary_coords], 1) - landmarks = vertices2landmarks(vertices, self.faces_tensor, lmk_faces_idx, lmk_bary_coords) From 83aa34ae949d71fb768b57cf249db45314a88fae Mon Sep 17 00:00:00 2001 From: shuaiqing Date: Sat, 21 Sep 2019 20:06:01 +0800 Subject: [PATCH 2/7] :hammer: add bias for smplx to fit with smpl --- smplx/body_models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/smplx/body_models.py b/smplx/body_models.py index 7c9823a..0dc9789 100644 --- a/smplx/body_models.py +++ b/smplx/body_models.py @@ -269,7 +269,10 @@ def __init__(self, model_path, data_struct=None, self.register_buffer('v_template', to_tensor(to_np(data_struct.v_template), dtype=dtype)) - + # add bias + if self.v_template.shape[0] == 10475: + bias = torch.Tensor(np.array([[0, 0.1728, 0.0218]])) + self.v_template = self.v_template + bias # The shape components shapedirs = data_struct.shapedirs # The shape components From 623478da867407e6cda97b61f0184875891efa86 Mon Sep 17 00:00:00 2001 From: shuaiqing Date: Sat, 21 Sep 2019 20:13:29 +0800 Subject: [PATCH 3/7] :hammer: adapt the batchsize --- smplx/body_models.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/smplx/body_models.py b/smplx/body_models.py index 0dc9789..cf70685 100644 --- a/smplx/body_models.py +++ b/smplx/body_models.py @@ -356,21 +356,18 @@ def forward(self, betas=None, body_pose=None, global_orient=None, ''' # If no shape and pose parameters are passed along, then use the # ones from the module - global_orient = (global_orient if global_orient is not None else - self.global_orient) body_pose = body_pose if body_pose is not None else self.body_pose - betas = betas if betas is not None else self.betas + bn = body_pose.shape[0] + global_orient = (global_orient if global_orient is not None else + self.global_orient[:bn]) + betas = betas if betas is not None else self.betas[:bn] apply_trans = transl is not None or hasattr(self, 'transl') if transl is None and hasattr(self, 'transl'): - transl = self.transl + transl = self.transl[:bn] full_pose = torch.cat([global_orient, body_pose], dim=1) - if betas.shape[0] != self.batch_size: - num_repeats = int(self.batch_size / betas.shape[0]) - betas = betas.expand(num_repeats, -1) - vertices, joints = lbs(betas, full_pose, self.v_template, self.shapedirs, self.posedirs, self.J_regressor, self.parents, From e6c8b8830060dddc8f3f89893e6b70073e040cd3 Mon Sep 17 00:00:00 2001 From: shuaiqing Date: Tue, 24 Sep 2019 10:54:26 +0800 Subject: [PATCH 4/7] :hammer: modify betas shape --- .gitignore | 1 + smplx/body_models.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7e842be..e5b944e 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,4 @@ venv.bak/ # mypy .mypy_cache/ +smplx/models \ No newline at end of file diff --git a/smplx/body_models.py b/smplx/body_models.py index cf70685..2ce35fb 100644 --- a/smplx/body_models.py +++ b/smplx/body_models.py @@ -361,7 +361,8 @@ def forward(self, betas=None, body_pose=None, global_orient=None, global_orient = (global_orient if global_orient is not None else self.global_orient[:bn]) betas = betas if betas is not None else self.betas[:bn] - + if betas.shape[0] < bn: + betas = betas.expand(bn, -1) apply_trans = transl is not None or hasattr(self, 'transl') if transl is None and hasattr(self, 'transl'): transl = self.transl[:bn] @@ -879,7 +880,6 @@ def forward(self, betas=None, global_orient=None, body_pose=None, global_orient = (global_orient if global_orient is not None else self.global_orient[:bn]) betas = betas if betas is not None else self.betas[:bn] - left_hand_pose = (left_hand_pose if left_hand_pose is not None else self.left_hand_pose) right_hand_pose = (right_hand_pose if right_hand_pose is not None else From b3f647ae60ff1626bcb5ee296f38ec91fed42537 Mon Sep 17 00:00:00 2001 From: shuaiqing Date: Mon, 4 Nov 2019 21:40:11 +0800 Subject: [PATCH 5/7] compatible with python3 --- tools/clean_ch.py | 2 +- tools/merge_smplh_mano.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/clean_ch.py b/tools/clean_ch.py index 56874b3..6a49904 100644 --- a/tools/clean_ch.py +++ b/tools/clean_ch.py @@ -31,7 +31,7 @@ def clean_fn(fn, output_folder='output'): with open(fn, 'rb') as body_file: - body_data = pickle.load(body_file) + body_data = pickle.load(body_file, encoding='latin1') output_dict = {} for key, data in body_data.iteritems(): diff --git a/tools/merge_smplh_mano.py b/tools/merge_smplh_mano.py index eab9d1e..8c473e3 100644 --- a/tools/merge_smplh_mano.py +++ b/tools/merge_smplh_mano.py @@ -30,13 +30,13 @@ def merge_models(smplh_fn, mano_left_fn, mano_right_fn, output_folder='output'): with open(smplh_fn, 'rb') as body_file: - body_data = pickle.load(body_file) + body_data = pickle.load(body_file, encoding='latin1') with open(mano_left_fn, 'rb') as lhand_file: - lhand_data = pickle.load(lhand_file) + lhand_data = pickle.load(lhand_file, encoding='latin1') with open(mano_right_fn, 'rb') as rhand_file: - rhand_data = pickle.load(rhand_file) + rhand_data = pickle.load(rhand_file, encoding='latin1') out_fn = osp.split(smplh_fn)[1] @@ -50,7 +50,7 @@ def merge_models(smplh_fn, mano_left_fn, mano_right_fn, output_data['hands_meanl'] = lhand_data['hands_mean'] output_data['hands_meanr'] = rhand_data['hands_mean'] - for key, data in output_data.iteritems(): + for key, data in output_data.items(): if 'chumpy' in str(type(data)): output_data[key] = np.array(data) else: From 3b6fffe11fc406c614342d1d9585159ceb913664 Mon Sep 17 00:00:00 2001 From: shuaiqing Date: Wed, 6 Nov 2019 12:20:08 +0800 Subject: [PATCH 6/7] batchsize adapt for smplh --- smplx/body_models.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/smplx/body_models.py b/smplx/body_models.py index 2ce35fb..448f20e 100644 --- a/smplx/body_models.py +++ b/smplx/body_models.py @@ -576,19 +576,21 @@ def forward(self, betas=None, global_orient=None, body_pose=None, ''' # If no shape and pose parameters are passed along, then use the # ones from the module - global_orient = (global_orient if global_orient is not None else - self.global_orient) body_pose = body_pose if body_pose is not None else self.body_pose - betas = betas if betas is not None else self.betas + bn = body_pose.shape[0] + global_orient = (global_orient if global_orient is not None else + self.global_orient[:bn]) + + betas = betas if betas is not None else self.betas[:bn] left_hand_pose = (left_hand_pose if left_hand_pose is not None else - self.left_hand_pose) + self.left_hand_pose[:bn]) right_hand_pose = (right_hand_pose if right_hand_pose is not None else - self.right_hand_pose) + self.right_hand_pose[:bn]) apply_trans = transl is not None or hasattr(self, 'transl') if transl is None: if hasattr(self, 'transl'): - transl = self.transl + transl = self.transl[:bn] if self.use_pca: left_hand_pose = torch.einsum( @@ -596,12 +598,12 @@ def forward(self, betas=None, global_orient=None, body_pose=None, right_hand_pose = torch.einsum( 'bi,ij->bj', [right_hand_pose, self.right_hand_components]) - full_pose = torch.cat([global_orient, body_pose, - left_hand_pose, - right_hand_pose], dim=1) - full_pose += self.pose_mean - - vertices, joints = lbs(self.betas, full_pose, self.v_template, + full_pose = torch.cat([global_orient[:bn], body_pose[:bn], + left_hand_pose[:bn], + right_hand_pose[:bn]], dim=1) + full_pose += self.pose_mean[:bn] + import ipdb; ipdb.set_trace() + vertices, joints = lbs(betas, full_pose, self.v_template, self.shapedirs, self.posedirs, self.J_regressor, self.parents, self.lbs_weights, From 4fc18d4f1b70ec940e7d6cd4259a5b4b536b8913 Mon Sep 17 00:00:00 2001 From: shuaiqing Date: Wed, 6 Nov 2019 14:45:35 +0800 Subject: [PATCH 7/7] fix smplh --- smplx/body_models.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/smplx/body_models.py b/smplx/body_models.py index 448f20e..a72f98d 100644 --- a/smplx/body_models.py +++ b/smplx/body_models.py @@ -597,12 +597,10 @@ def forward(self, betas=None, global_orient=None, body_pose=None, 'bi,ij->bj', [left_hand_pose, self.left_hand_components]) right_hand_pose = torch.einsum( 'bi,ij->bj', [right_hand_pose, self.right_hand_components]) - full_pose = torch.cat([global_orient[:bn], body_pose[:bn], left_hand_pose[:bn], right_hand_pose[:bn]], dim=1) - full_pose += self.pose_mean[:bn] - import ipdb; ipdb.set_trace() + full_pose += self.pose_mean vertices, joints = lbs(betas, full_pose, self.v_template, self.shapedirs, self.posedirs, self.J_regressor, self.parents,