Skip to main content

smpl-kit

smplkit is a versatile library that simplifies SMPL body model usage with automatic model path search, different body models support, adjustable batch size support, and useful utility functions for data processing and visualization.

The left figure utilizes smplx for creating an SMPL body mesh with random translation, while smplkit achieves the same functionality with a more concise code implementation.

Features

  • Automatic model path search in the workspace or home folder.
  • Support SMPL, SMPL+H, SMPL-X body models.
  • Support adjustable batch size of the SMPL parameters.
  • Provide numerous utility functions for SMPL parameters and meshes.
  • Provide visualization tools for viewing the results.

Installation

  1. Before installing smplkit, please make sure that you have installed pytorch and pytorch3d.

  2. To install the smplkit package, you can either install it from PyPI or install it from source.

    • To install from PyPI by using pip:
    pip install smplkit
    
    • Or, clone this repository and install it from source:
    git clone git@github.com:Silverster98/smpl-kit.git
    cd smpl-kit
    pip install .
    

Documentation

Tutorial

0. Model path configuration

smplkit can search the model automatically. However, you can also specify the model path manually.

  • If the model_path is not provided as a parameter for SMPL/SMPL+H/SMPL-X layers, the program will automatically search the models in current folder.
    • If ./body_models/ exists, the program will search the models in ./body_models/.
      • You should organize the ./body_models/ as follows:
        |- ./body_models/
        |--- smpl/  # SMPL model
        |----- SMPL_NEUTRAL.pkl
        |--- smplh/ # SMPL+H model
        |----- SMPLH_NEUTRAL.pkl
        |----- SMPLH_MALE.pkl
        |----- SMPLH_FEMALE.pkl
        |--- smplx/ # SMPL-X model
        |----- SMPLX_NEUTRAL.npz
        |----- SMPLX_MALE.npz
        |----- SMPLX_FEMALE.npz
        
    • If ./body_models does not exist, the program will search the models in ~/.body_models/, i.e., the home folder.
      • You should organize the ~/.body_models/ as follows (similar to the above):
        |- ~/.body_models/
        |--- smpl/  # SMPL model
        |--- smplh/ # SMPL+H model
        |--- smplx/ # SMPL-X model
        
    • So, you can either put the models in one workspace for one project or in the home folder for all related projects.
  • If the model_path is provided as a parameter for SMPL/SMPL+H/SMPL-X layers, the program will search the models in the given path.
    • If the model_path is file path, the program will load the model from the given file path.
    • If the model_path if folder path, the program will search the models in the given folder path.
      • You should organize the given folder as follows (similar to the above):
        |- ${GIVEN_FOLDER}/
        |--- smpl/  # SMPL model
        |--- smplh/ # SMPL+H model
        |--- smplx/ # SMPL-X model
        

1. Use the SMPLLayer to generate a SMPL body mesh with random translation while keeping other parameters as zero:

import torch
import trimesh
from smplkit import SMPLLayer as SMPL

body_model = SMPL()

transl = torch.rand((2, 3), dtype=torch.float32)
verts = body_model(transl=transl, return_verts=True)
verts = verts.numpy()

mesh = trimesh.Trimesh(vertices=verts[0], faces=body_model.faces)

2. Use the SMPLParam to optimize the SMPL parameters (only tranlation) with a given mesh:

import torch
from smplkit import SMPLLayer as SMPL
from smplkit import SMPLParam
from torch.optim import SGD

bm = SMPL(num_betas=10)

target_transl = torch.tensor([[0, 1, 0]], dtype=torch.float32)
target_verts = bm(transl=target_transl, return_verts=True)

## init param and optimizer
param = SMPLParam(transl=torch.rand(1, 3), requires_grad=[True, False, False, False])
opt = SGD(param.trainable_parameters(), lr=0.1)

for i in range(200):
    opt.zero_grad()
    output = bm(**param._parameters_dict(), return_verts=True)
    
    loss = ((output - target_verts) ** 2).mean()
    
    loss.backward()
    opt.step()

    if (i + 1) % 20 == 0:
        print(f"Optimization Error in Step {i + 1:3d}: {loss.item()}")

API

  • SMPLLayer
  • SMPLHLayer
  • SMPLXLayer
  • SMPLParam
  • SMPLHParam
  • SMPLXParam
  • utils
    • matrix_to_parameter
    • compute_orient
    • compute_normal
    • compute_sdf
    • VertexSelector
      • select_vertex
      • contact_vertex (Only support SMPL-X now)
      • key_vertex
    • JointSelector
      • select_joint
    • BodyModel
      • reset
      • run
      • to
  • visualize
  • constants
    • VERTEX_NUM
    • JOINTS_NUM
    • KEY_VERTEX_IDS
    • CONTACT_PART_NAME
    • CONTACT_VERTEX_IDS (Only support SMPL-X now)
    • JOINTS_NAME
    • SMPLX_LANDMARKS_NAME
    • SKELETON_CHAIN
    • SKELETON_PARENTS

License

This project is licensed under the terms of the MIT license.

Acknowledgement

Some codes are borrowed from SMPL-X. If your use this code, please consider citing the most relevant works.

Release files for smplkit 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smplkit 0.0.3
File Size Uploaded
smplkit-0.0.3.tar.gz 30.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for smplkit 0.0.3
File Interpreter ABI Platform
smplkit-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 58.5 kB

Release files / smplkit-0.0.3.tar.gz

Download URL smplkit-0.0.3.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
258bb3a63e614be7c3283ead8a36392f6cab9416ada5cf4280ae9d031e8b3d0c
BLAKE2b-256 checksum
How to use checksums
ef270c397d8a3c81c1e6b0f9d87bc2a43e35cf89ee7e22697458ca42687c48f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / smplkit-0.0.3-py3-none-any.whl

Download URL smplkit-0.0.3-py3-none-any.whl
Size 28.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8138af44182d6b4fa2d81f2fe580234b272f2f831ba3abba2ca01ad5cac4418a
BLAKE2b-256 checksum
How to use checksums
a3dd27283f368344f69b175bad030c44150747b27052813fa68ebf19eb0f333a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page