Skip to content

Instantly share code, notes, and snippets.

@stwind
Last active February 23, 2025 07:58
Show Gist options
  • Save stwind/2aa7a9d0da91f675902f30b2fbf08d22 to your computer and use it in GitHub Desktop.
Save stwind/2aa7a9d0da91f675902f30b2fbf08d22 to your computer and use it in GitHub Desktop.
smpl.ipynb
FROM quay.io/pypa/manylinux2014_x86_64
RUN curl https://bootstrap.pypa.io/pip/2.7/get-pip.py | python && \
pip install opencv-python-headless==3.4.8.29 chumpy
# docker build --platform linux/x86_64 -t smpl .
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],
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"],
)
import sys
sys.path.insert(0, ".")
from smpl_webuser.serialization import load_model
import numpy as np
def make_verts(model, seed=0):
np.random.seed(seed)
m = load_model(model)
m.pose[:] = np.random.rand(m.pose.size) * 0.2
m.betas[:] = np.random.rand(m.betas.size) * 0.03
return m.r
verts = {
"f": make_verts("models/basicmodel_f_lbs_10_207_0_v1.1.0.pkl"),
"m": make_verts("models/basicmodel_m_lbs_10_207_0_v1.1.0.pkl"),
"n": make_verts(model="models/basicmodel_neutral_lbs_10_207_0_v1.1.0.pkl"),
}
np.savez_compressed("verts", **verts)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment