Skip to content

About

Super fast implementation of SMPL-like models in C++ with libTorch🔥

Resources

Stars

9 stars

Watchers

0 watching

Forks

Repository files navigation

torchure_smplx

CI - LibTorch CPU + Open3D CI - LibTorch CPU + Open3D

torchure_smplx logo

A high-performance C++ implementation of the SMPL, SMPL-H, and SMPL-X body models using LibTorch. Optimized for GPU execution, capable of running up to 1000 inferences per second to torture your model in real-time! 😎 This implementation is a refined and improved version of smpl-cpp. It also includes a Torch Chamfer Distance implementation in and a fitting example that can be used to fit the SMPL model to point clouds as well as a Visualization example using Open3D.

Fast Fitting
(predicting betas)
Fast Fitting
(predicting betas and pose)
Fast Fitting Betas Fast Fitting Betas and Pose

🚀 Features

  • C++ implementation using LibTorch (PyTorch C++ API)
  • Supports SMPL, SMPL-H (TODO), and SMPL-X (TODO) models
  • GPU acceleration via CUDA (optional)
  • Suitable for real-time performance-critical applications
  • Fast model loading using NumPy .npz format (no Python runtime required)
  • Fast fitting to point clouds using Chamfer Distance
  • Easy integration with other systems since it produces a portable smplx library
  • Visualization example using Open3D

📦 Installation

1. Clone the repository

git clone https://github.com/hydran00/torchure_smplx.git
cd torchure_smplx

2. Install dependencies

  • LibTorch
  • Zlib (often pre-installed) or with sudo apt install zlib1g-dev
  • CMake
  • CUDA (optional, for GPU builds)
  • Open3D (optional, for visualization)

Download the correct LibTorch version for your platform and CUDA version from https://pytorch.org.


3. Configure and build

PyTorch users

⚠️ If you rely on pip's PyTorch package, check with which API it was built. Some Pytorch implementations are built with the deprecated Pre-CXX ABI support, which makes them incompatible with many libraries like Open3D, you can check if with

python -c "import torch; print('PyTorch ABI:', torch._C._GLIBCXX_USE_CXX11_ABI)"  # should print True

If it prints False I suggest you to download LibTorch(refer to Libtorch section) or chose a compatible PyTorch version. Then determine your Torch cmake path:

python -c "import torch; print(torch.utils.cmake_prefix_path)"

LibTorch users (recommended)

Download the C++ version of LibTorch from PyTorch's official site and extract it. Make sure to choose the version that matches your system architecture and CUDA version (if applicable). Your Torch cmake path should look like this:

/path/to/libtorch/share/cmake/Torch

(Optional) Enable CUDA

If you want GPU acceleration, set the CUDACXX variable to point to nvcc, in Linux the path is usually /usr/local/cuda/bin/nvcc.

export CUDACXX=/usr/local/cuda/bin/nvcc

Building the project

Then configure and build:

mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH="<torch cmake prefix path>"
make

Optional: To link Torch you can also set the same Torch_DIR variable in CMake, so you can avoid expliciting Torch_DIR every time

# add this line to on top of CMakeLists.txt
set(Torch_DIR "<torch cmake prefix path>")

🌀 Convert .pkl models to .npz

Download the SMPL model from the official website after registering, currently we tested only the 10 PCs shape.
This project uses .npz format for loading SMPL/SMPL-X models in C++.
Convert the official .pkl models using the included Python script:

python3 scripts/pkl2npz.py \
  smpl/models/basicModel_f_lbs_10_207_0_v1.0.0.pkl \
  smpl/models/basicModel_m_lbs_10_207_0_v1.0.0.pkl

This will produce .npz files compatible with C++ using the cnpy loader.


📘 Run the examples

⏱️ Benchmark the SMPL model

./benchmark <path-to-converted-smpl-model.npz>

This runs the model and outputs a mesh for a single forward pass. Performance on GPU can reach ~1000 FPS depending on hardware.

🧍 Fitting SMPL with C++ Chamfer Distance

./fitting <path-to-converted-smpl-model.npz>

This example will also open a Open3D window to visualize the fitting process if Open3D was available during the building process.

🔄 Including in your project

Including torchure_smplx in your project is straightforward with cmake, you can take a look at the minimal_cmake_example for a minimal example of how to include the library in your project.

...
find_package(torchure_smplx REQUIRED)
find_package(Torch REQUIRED)
...
add_executable(your_beautiful_project main.cpp)
...
target_link_libraries(your_beautiful_project PRIVATE torchure_smplx::smplx)

📜 License

Apache 2.0 License (see LICENSE file).


🙋‍♂️ Support

Please open an issue or PR on GitHub if you need help or want to contribute.

📑 References

smpl-cpp: Libtorch implementation of SMPL, base code of this project.
cnpy: A C++ library for loading NumPy .npz files.
chamferdist: Torch implementation of Chamfer Distance.
smplx: SMPL-X repository.

About

Super fast implementation of SMPL-like models in C++ with libTorch🔥

Resources

Stars

9 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages