PoseLLM / eval /vis.py
ZiyuG's picture
Upload folder using huggingface_hub
f5fb865 verified
import torch
import smplx
import trimesh
import numpy as np
# 安装库
# pip install numpy trimesh smplx
# 加载 SMPL 模型
model_path = '/data7tb/gzy/PoseLLM/Data/eval/SMPL_python_v.1.1.0' # 替换为你的 SMPL 模型文件路径
model = smplx.create(model_path, model_type='smpl')
# # 示例参数 - 替换为你的实际参数
# pose = torch.randn(1, 72) # 示例姿势参数(轴角格式旋转)
# betas = torch.randn(1, 10) # 示例形状参数
# trans = torch.randn(1, 3) # 示例平移
# # 21*3, 1*3, 10
# 应用参数并生成网格
root = torch.tensor([-2.6874380111694336, -0.26389217376708984, 0.6374585032463074])
body = torch.tensor([-0.1735587865114212, 0.2535969018936157, 0.4451696276664734, -0.5266498923301697, -0.0028357410337775946, 0.12463252246379852, 0.4283740520477295, -0.06844133138656616, -0.13476136326789856, 0.1729201376438141, -0.062212057411670685, 0.04943773150444031, 0.3267636299133301, -0.032275665551424026, 0.0645369365811348, -0.12863649427890778, -0.04785856604576111, -0.05788196995854378, 0.09533862769603729, 0.29959753155708313, -0.2018682360649109, 0.0469140000641346, -0.16524836421012878, 0.06885715574026108, 0.050303954631090164, -0.11038987338542938, -0.0415954552590847, 0.023014595732092857, -0.0007983183022588491, 0.0015443722950294614, 0.013331297785043716, 0.005405330564826727, -0.0066509065218269825, 0.058911826461553574, 0.1269962191581726, 0.0142764151096344, -0.19498211145401, -0.3386516869068146, 0.2458631545305252, 0.030865710228681564, -0.25391557812690735, -0.061386071145534515, -0.22564950585365295, 0.15015938878059387, -0.10208533704280853, -0.2481042742729187, -0.49667108058929443, -0.07719802856445312, -0.07735060155391693, -0.3313570022583008, 0.30943772196769714, -0.2494557797908783, -0.6694778800010681, 0.10317020863294601, -0.19080935418605804, 0.7026188969612122, -0.2931462228298187, -0.24473963677883148, -0.12221227586269379, 0.029570525512099266, -0.2172621339559555, 0.12078158557415009, -0.1681288480758667])
shape = torch.tensor([0.4458031952381134, 0.7807534337043762, -0.34519198536872864, -0.5425407886505127, 0.07042225450277328, -0.5529958605766296, -0.04845510050654411, 0.04505615308880806, 0.256156325340271, -0.2634725868701935])
output = model(betas=shape, body_pose=body, global_orient=root)
mesh = output.vertices[0].detach().cpu().numpy()
# 创建网格对象并保存为 OBJ 文件
faces = model.faces
export_mesh = trimesh.Trimesh(vertices=mesh, faces=faces)
export_mesh.export('output_mesh.obj')