Last active
February 23, 2025 08:08
-
-
Save stwind/ab87dd3948d0954bd670844917c09415 to your computer and use it in GitHub Desktop.
smplh.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import argparse | |
import pickle | |
import numpy as np | |
def csc_cols(m): | |
col_start = m.indptr[:-1] | |
col_end = m.indptr[1:] | |
return np.concatenate( | |
[ | |
np.full(end - start, i, dtype=int) | |
for i, (start, end) in enumerate(zip(col_start, col_end)) | |
] | |
) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("file", type=str) | |
args = parser.parse_args() | |
with open(args.file, "rb") as f: | |
data = pickle.load(f) | |
output = {} | |
for key, data in data.iteritems(): | |
if "chumpy" in str(type(data)): | |
output[key] = np.array(data) | |
else: | |
output[key] = data | |
np.savez_compressed( | |
os.path.splitext(args.file)[0], | |
hands_components=output["hands_components"], | |
hands_mean=output["hands_mean"], | |
shapedirs=output["shapedirs"], | |
v_template=output["v_template"], | |
J_regressor_data=output["J_regressor"].data, | |
J_regressor_rows=output["J_regressor"].indices, | |
J_regressor_cols=csc_cols(output["J_regressor"]), | |
kintree_table=output["kintree_table"], | |
posedirs=output["posedirs"], | |
weights=output["weights"], | |
f=output["f"], | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import argparse | |
import pickle | |
import numpy as np | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("file", type=str) | |
args = parser.parse_args() | |
with open(args.file, "rb") as f: | |
data = pickle.load(f) | |
output = {} | |
for key, data in data.iteritems(): | |
if "chumpy" in str(type(data)): | |
output[key] = np.array(data) | |
else: | |
output[key] = data | |
np.savez_compressed( | |
os.path.splitext(args.file)[0], | |
shapedirs=output["shapedirs"], | |
v_template=output["v_template"], | |
J_regressor_data=output["J_regressor"].data, | |
J_regressor_rows=output["J_regressor"].row, | |
J_regressor_cols=output["J_regressor"].col, | |
kintree_table=output["kintree_table"], | |
posedirs=output["posedirs"], | |
weights=output["weights"], | |
f=output["f"], | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.path.insert(0, ".") | |
from webuser.smpl_handpca_wrapper_HAND_only import load_model as load_model_mano | |
from webuser.smpl_handpca_wrapper import load_model | |
import numpy as np | |
def make_verts_mano(model, seed=0): | |
m = load_model_mano(model) | |
np.random.seed(seed) | |
m.betas[:] = np.random.rand(m.betas.size) * 0.03 | |
# m.pose[:] = np.random.rand(m.pose.size) * 1.0 | |
m.pose[:3] = [0.0, 0.0, 0.0] | |
m.pose[3:] = [ | |
-0.42671473, | |
-0.85829819, | |
-0.50662164, | |
+1.97374622, | |
-0.84298473, | |
-1.29958491, | |
] | |
return m.r | |
def make_verts_smplh(model, seed=0): | |
m = load_model(model) | |
np.random.seed(seed) | |
m.betas[:] = np.random.rand(m.betas.size) * 0.03 | |
# m.pose[:] = np.random.rand(m.pose.size) * 1.0 | |
m.pose[:] = [ | |
-0.17192541, | |
+0.36310464, | |
+0.05572387, | |
-0.42836206, | |
-0.00707548, | |
+0.03556427, | |
+0.18696896, | |
-0.22704364, | |
-0.39019834, | |
+0.20273526, | |
+0.07125099, | |
+0.07105988, | |
+0.71328310, | |
-0.29426986, | |
-0.18284189, | |
+0.72134655, | |
+0.07865227, | |
+0.08342645, | |
+0.00934835, | |
+0.12881420, | |
-0.02610217, | |
-0.15579594, | |
+0.25352553, | |
-0.26097519, | |
-0.04529948, | |
-0.14718626, | |
+0.52724564, | |
-0.07638319, | |
+0.03324086, | |
+0.05886086, | |
-0.05683995, | |
-0.04069042, | |
+0.68593617, | |
-0.75870686, | |
-0.08579930, | |
-0.55086359, | |
-0.02401033, | |
-0.46217096, | |
-0.03665799, | |
+0.12397343, | |
+0.10974685, | |
-0.41607569, | |
-0.26874970, | |
+0.40249335, | |
+0.21223768, | |
+0.03365140, | |
-0.05243080, | |
+0.16074013, | |
+0.13433811, | |
+0.10414972, | |
-0.98688595, | |
-0.17270103, | |
+0.29374368, | |
+0.61868383, | |
+0.00458329, | |
-0.15357027, | |
+0.09531648, | |
-0.10624117, | |
+0.94679869, | |
-0.26851003, | |
+0.58547889, | |
-0.13735695, | |
-0.39952280, | |
-0.16598853, | |
-0.14982575, | |
-0.27937399, | |
+0.12354536, | |
-0.55101035, | |
-0.41938681, | |
+0.52238684, | |
-0.23376718, | |
-0.29814804, | |
-0.42671473, | |
-0.85829819, | |
-0.50662164, | |
+1.97374622, | |
-0.84298473, | |
-1.29958491, | |
] | |
return m.r | |
verts = { | |
"left": make_verts_mano("models/MANO_LEFT.pkl"), | |
"right": make_verts_mano("models/MANO_RIGHT.pkl"), | |
"female": make_verts_smplh("models/SMPLH_female.pkl"), | |
"male": make_verts_smplh("models/SMPLH_male.pkl"), | |
} | |
np.savez_compressed("verts", **verts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment