Skip to content

How to translate SMPLX model to SMPLH model #87

@soddday

Description

@soddday

I get the npz file of SMPLX,but I only want SMPLH model
`import os
from os import makedirs

import numpy as np
import open3d as o3d
import torch
import json

from tools.utils.build_layer import build_smplh_mesh, Pelvis_norm, create_mesh
import sys

def get_mesh(npz_data):
device = torch.device("cuda:0")
smplh_param = {}

param_data = npz_data

# 转换参数为Tensor
smplh_param['shape'] = torch.tensor(param_data['betas']).unsqueeze(0)  # 形状参数 (1, 10)
smplh_param['transl'] = torch.tensor(param_data['transl']).unsqueeze(0)  # 平移 (1, 3)
smplh_param['body_pose'] = torch.tensor(param_data['body_pose']).reshape(1, 21, 3, 3)  # 身体姿势 (21个关节的旋转矩阵)
smplh_param['left_hand_pose'] = torch.tensor(param_data['left_hand_pose']).reshape(1, 15, 3, 3)  # 左手姿势
smplh_param['right_hand_pose'] = torch.tensor(param_data['right_hand_pose']).reshape(1, 15, 3, 3)  # 右手姿势
smplh_param['global_orient'] = torch.tensor(param_data['global_orient']).reshape(1, 3, 3)  # 全局旋转

# 构建SMPL-H网格(通过外部函数`build_smplh_mesh`)
vertices, face = build_smplh_mesh(smplh_param)
vertices = vertices.to(device)

# 归一化顶点(通过外部函数`Pelvis_norm`)
H, pelvis = Pelvis_norm(vertices, device)
vert = H.detach().cpu().numpy()

# 创建Open3D网格(通过外部函数`create_mesh`)
mesh = create_mesh(vertices=vert[0], faces=face)

return mesh, H[0], face

def visual_contact(npz_data,filename,save_path):
# 加载接触数据(每个顶点是否接触的标记)

colors = np.array([255.0, 255.0, 255.0])[None, :].repeat(6890, axis=0)  # 6890个顶点初始为白色
colors = colors / 255.0  # 归一化到[0,1]范围

# 获取SMPL模型网格(通过外部函数`get_mesh`)

smpl, _, _ = get_mesh(npz_data)

ply_save = os.path.join(save_path, filename.replace(".npz",".ply"))


# 应用颜色并保存
smpl.vertex_colors = o3d.utility.Vector3dVector(colors)
o3d.io.write_triangle_mesh(ply_save, smpl)

if name == 'main':
npz_path = "mycreateMesh/Bicycle/pull"
save_path = r"mycreateMesh/Bicycle/pull"
os,makedirs(save_path,exist_ok=True)
for filename in os.listdir(npz_path):
if filename.endswith(".npz"):
npz_path = os.path.join(npz_path, filename)
if not os.path.exists(npz_path):
print(f"not found {npz_path}")
sys.exit(1)
npz_data = np.load(npz_path)
visual_contact(npz_data,filename,save_path)

E:\PyCharm 2025.1.2\plugins\python-ce\helpers\pydev\pydevd_plugins_init_.py:2: UserWarning:

pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.

已连接到 pydev 调试器(内部版本号 251.26094.141)print(npz_data["betas"])
PyDev console: using IPython 9.4.0

[[ 0.82817674 0.6526434 0.4085177 -0.2684117 -1.0917997 -0.76369494
-0.09565452 0.14748831 0.04955668 -0.10091463]]
Traceback (most recent call last):
File "E:\PyCharm 2025.1.2\plugins\python-ce\helpers\pydev\pydevd.py", line 1570, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\PyCharm 2025.1.2\plugins\python-ce\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "E:\lemon_3d-main\lemon_3d-main\smpler-x.py", line 70, in
visual_contact(npz_data,filename,save_path)
File "E:\lemon_3d-main\lemon_3d-main\smpler-x.py", line 50, in visual_contact
smpl, _, _ = get_mesh(npz_data)
^^^^^^^^^^^^^^^^^^
File "E:\lemon_3d-main\lemon_3d-main\smpler-x.py", line 23, in get_mesh
smplh_param['body_pose'] = torch.tensor(param_data['body_pose']).reshape(1, 21, 3, 3) # 身体姿势 (21个关节的旋转矩阵)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: shape '[1, 21, 3, 3]' is invalid for input of size 63
python-BaseException
` But I don't know how to use the right smplx params

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions