# manotorch
**Repository Path**: lufeng666520/manotorch
## Basic Information
- **Project Name**: manotorch
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: GPL-3.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-11-25
- **Last Updated**: 2024-11-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# manotorch: MANO Pytorch
- manotorch is a differentiable PyTorch layer that deterministically maps from pose and shape parameters to hand joints and vertices. It can be integrated into any architecture as a differentiable layer to predict hand mesh.
- manotorch is compatible with Yana's [manopth](https://github.com/hassony2/manopth) package and Omid's [MANO](https://github.com/otaheri/MANO) package, allowing for interchangeability between them. See example: [test_compatibility](scripts/test_compatibility.ipynb).
- manotorch is modified from the original [manopth](https://github.com/hassony2/manopth) with the following new features:
- [Anatomical Consistent Basis](#anatomical-consistent-basis)
- [Anatomy Loss](#anatomy-loss)
- [Composing the Hand](#composing-the-hand)
- [Anchor Interpolation](#anchor-interpolation)
## :rocket: Installation
### Get code and dependencies
```shell
$ git clone https://github.com/lixiny/manotorch.git
$ cd manotorch
```
Install the dependencies listed in [environment.yaml](environment.yaml)
```shell
# In a new environment,
$ conda env create -f environment.yaml
# Or in an existing conda environment,
$ conda env update -f environment.yaml
```
### Download MANO pickle data-structures
- Visit [MANO website](http://mano.is.tue.mpg.de/)
- Create an account by clicking _Sign Up_ and provide your information
- Download Models and Code (the downloaded file should have the format `mano_v*_*.zip`). Note that all code and data from this download falls under the [MANO license](http://mano.is.tue.mpg.de/license).
- unzip and copy the contents in `mano_v*_*/` folder to the `assets/mano/` folder
- Your `assets/mano` folder structure should look like this:
```
assets/mano
├── info.txt
├── __init__.py
├── LICENSE.txt
├── models
│ ├── info.txt
│ ├── LICENSE.txt
│ ├── MANO_LEFT.pkl
│ ├── MANO_RIGHT.pkl
│ ├── SMPLH_female.pkl
│ └── SMPLH_male.pkl
└── webuser
└── ...
```
### Optional: Install manotorch package
To be able to import and use manotorch in another project, go to your `manotorch` folder and run
```
$ pip install .
```
## :plate_with_cutlery: Usage
we provide a simple code snippet to demonstrate the minimal usage.
```python
import torch
from manotorch.manolayer import ManoLayer, MANOOutput
# Select number of principal components for pose space
ncomps = 15
# initialize layers
mano_layer = ManoLayer(use_pca=True, flat_hand_mean=False, ncomps=ncomps)
batch_size = 2
# Generate random shape parameters
random_shape = torch.rand(batch_size, 10)
# Generate random pose parameters, including 3 values for global axis-angle rotation
random_pose = torch.rand(batch_size, 3 + ncomps)
# The mano_layer's output contains:
"""
MANOOutput = namedtuple(
"MANOOutput",
[
"verts",
"joints",
"center_idx",
"center_joint",
"full_poses",
"betas",
"transforms_abs",
],
)
"""
# forward mano layer
mano_output: MANOOutput = mano_layer(random_pose, random_shape)
# retrieve 778 vertices, 21 joints and 16 SE3 transforms of each articulation
verts = mano_output.verts # (B, 778, 3), root(center_joint) relative
joints = mano_output.joints # (B, 21, 3), root relative
transforms_abs = mano_output.transforms_abs # (B, 16, 4, 4), root relative
```
### Advanced Usage
| [Visualize](scripts/simple_app.py) | [Compose Hand](scripts/simple_compose.py) | [Error Correction](scripts/simple_anatomy_loss.py) |
| :--------------------------------: | :---------------------------------------: | :------------------------------------------------: |
|  |  |  |
## :gift: New Features
### Anatomical Consistent Basis
The original MANO model is driven by a kinematic tree with 16 joints, where each joint’s rotation is represented in
the form of axis-angle. To represent the joint rotation in a three-dimensional
Euclidean space, we need to find an orthogonal basis (consists of three orthogonal axes) that describes the rotation.
Apparently, there have infinity choices of the orthogonal basis. For example, the original MANO model adopts the
same orthogonal basis as the wrist for all of its 16 joints.
We seek to find a basis whose three axes can describe three independent hand motions that satisfy the hand
anatomy. Therefore we can decompose the joint rotation w.r.t. this basis and penalize the abnormal
pose on that joint.