Code for "3D Human Pose and Shape Regression with Pyramidal Mesh Alignment Feedback Loop"

Overview

PyMAF

This repository contains the code for the following paper:

3D Human Pose and Shape Regression with Pyramidal Mesh Alignment Feedback Loop
Hongwen Zhang*, Yating Tian*, Xinchi Zhou, Wanli Ouyang, Yebin Liu, Limin Wang, Zhenan Sun

* Equal contribution

[Project Page] [ArXiv] [Paper]

PyMAF

Requirements

  • Python 3.6.10

packages

necessary files

mesh_downsampling.npz & DensePose UV data

  • Run the following script to fetch mesh_downsampling.npz & DensePose UV data from other repositories.
bash fetch_data.sh

SMPL model files

Fetch preprocessed data from SPIN.

Download the pre-trained model and put it into the ./data/pretrained_model directory.

After collecting the above necessary files, the directory structure of ./data is expected as follows.

./data
├── dataset_extras
│   └── .npz files
├── J_regressor_extra.npy
├── J_regressor_h36m.npy
├── mesh_downsampling.npz
├── pretrained_model
│   └── PyMAF_model_checkpoint.pt
├── smpl
│   ├── SMPL_FEMALE.pkl
│   ├── SMPL_MALE.pkl
│   └── SMPL_NEUTRAL.pkl
├── smpl_mean_params.npz
├── static_fits
│   └── .npy files
└── UV_data
    ├── UV_Processed.mat
    └── UV_symmetry_transforms.mat

Demo

[UPDATE] You can first give it a try on Google Colab using the notebook we have prepared, which is no need to prepare the environment yourself: Open In Colab

Run the demo code.

python3 demo.py --checkpoint=data/pretrained_model/PyMAF_model_checkpoint.pt --vid_file ./flashmob.mp4


Frame by frame reconstruction. Video clipped from here.

Evaluation

Human3.6M / 3DPW

Run the evaluation code. Using --dataset to specify the evaluation dataset.

# Example usage:

# Human3.6M Protocol 2
python3 eval.py --checkpoint=data/pretrained_model/PyMAF_model_checkpoint.pt --dataset=h36m-p2 --log_freq=20

# 3DPW
python3 eval.py --checkpoint=data/pretrained_model/PyMAF_model_checkpoint.pt --dataset=3dpw --log_freq=20

COCO Keypoint Localization

  1. Download the preprocessed data coco_2014_val.npz. Put it into the ./data/dataset_extras directory.

  2. Run the COCO evaluation code.

python3 eval_coco.py --checkpoint=data/pretrained_model/PyMAF_model_checkpoint.pt

Training

To perform training, we need to collect preprocessed files of training datasets at first.

The preprocessed labels have the same format as SPIN and can be retrieved from here. Please refer to SPIN for more details about data preprocessing.

PyMAF is trained on Human3.6M at the first stage and then trained on the mixture of both 2D and 3D datasets at the second stage. Example usage:

# training on Human3.6M
python3 train.py --regressor pymaf_net --single_dataset --misc TRAIN.BATCH_SIZE 64
# training on mixed datasets
python3 train.py --regressor pymaf_net --pretrained_checkpoint path/to/checkpoint_file.pt --misc TRAIN.BATCH_SIZE 64

Running the above commands will use Human3.6M or mixed datasets for training, respectively. We can monitor the training process by setting up a TensorBoard at the directory ./logs.

Citation

If this work is helpful in your research, please cite the following paper.

@article{pymaf2021,
  title={3D Human Pose and Shape Regression with Pyramidal Mesh Alignment Feedback Loop},
  author={Zhang, Hongwen and Tian, Yating and Zhou, Xinchi and Ouyang, Wanli and Liu, Yebin and Wang, Limin and Sun, Zhenan},
  journal={arXiv preprint arXiv:2103.16507},
  year={2021}
}

Acknowledgments

The code is developed upon the following projects. Many thanks to their contributions.

Comments
  • h36m mosh

    h36m mosh

    Hi,

    I'm trying to run the code on the h36m dataset. I noticed that when I do this, I get the error:

    FileNotFoundError: [Errno 2] No such file or directory: 'data/dataset_extras/h36m_mosh_train.npz'

    Which procedure should I use to generate the moshed data from the h36m dataset?

    opened by aespielberg 39
  • how to get finnal_fits/xxx.npz

    how to get finnal_fits/xxx.npz

    Hello, I would like to know how did you get the file finnal_fits/xxx.npz required during the training? I want to train the model in my own dataset. thanks

    opened by nanfengguli 12
  • Pretrained backbone network setting

    Pretrained backbone network setting

    @HongwenZhang

    1. In this issue, you said that PyMAF followed PARE setting. It seems that PyMAF should use the weights pretrained in mpii to initialize the backbone network for fast convergence. But in the config file, it doesn't offer the mpii option. Should I just use backbone pretrained on IM as the default or add the mpii option?

    2. Can you offer the checkpoint of the first stage, i.e. training on COCO?

    3. Besides, do you have the PyMAF scores after adding the RandCrop and synthetic occlusion augmentations?

    opened by MooreManor 6
  • Projection of estimated SMPL/SMPL-X mesh on Image

    Projection of estimated SMPL/SMPL-X mesh on Image

    Thank you very much for your amazing work. I would like to ask a question about how to project a mesh estimated by PyMAF/PyMAF-X back on the input image.

    It seems that PyMAF projects the predicted joints using the projection(...) function and the predicted camera parameters as in here. I guess this function is also applicable to a set of vertices too, instead of just joints.

    Implementation of projection(...) in smpl branch: https://github.com/HongwenZhang/PyMAF/blob/fb21d104c5556bf4e7a6d1b74e165f4240206bcf/utils/geometry.py#L241-L255

    I want to project a SMPL-X mesh estimated by PyMAF-X on the input image too. However, I do not see the projection(...) function being used in the demo_smplx.py script. Also, I found the implementation of the projection(...) function somewhat different from its counterpart in the smpl branch.

    Excerpt of projection(...) in smplx branch: https://github.com/HongwenZhang/PyMAF/blob/18a68d81d538da3498d7d4571fe6225f986b12c3/utils/geometry.py#L379-L401

    Can I just use this function in this way, projection(dict(cam_sxy=pred_joints), pred_cam), to convert the predictions from PyMAF-X to the input of projection(...)? Or how should I use this function to get a correct projection?

    Here is an example in which I project the estimated smplx vertices by: projection(dict(cam_sxy=smplx_verts), pred_cam). smplx_verts has shape (1,10475,3) and pred_cam has shape (1,3). The dimensions of the input image are (512,512). The (x and y) coordinates of the projected vertices range from -106.73 to 98.63. I am guessing that the domains of coordinates are like [-W/2, +W/2] and [-H/2, +H/2], so I rescale the projects coordinates by x*2+256 and y*2+256. Here are the input image (left) and the projection vertices (right) I get.

    download (2)

    download (3)

    Am I doing the projection correctly? Although the projection somewhat aligns with the actual human shape on the image, I am not sure if I am just putting the projected points at this location by luck or not. Also, the projection is a little bit smaller than the actual shape, and I am not sure if this is just because it is an estimation using SMPL-X, or if I am not projecting the shape correctly.

    Thank you!

    opened by tommycwh 6
  • fail to import Renderer. How to solve this problem?

    fail to import Renderer. How to solve this problem?

    fail to import Renderer. INFO:utils.train_utils:log name: logs/pymaf_res50_mix/pymaf_res50_mix_as_lp3_mlp256-128-64-5_Dec28-10-52-18-ZWK INFO:models.hmr:loaded resnet50 imagenet pretrained model INFO:datasets.base_dataset:len of h36m: 312188 INFO:datasets.base_dataset:len of lsp-orig: 1000 INFO:datasets.base_dataset:len of mpii: 14810 INFO:datasets.base_dataset:len of lspet: 9428 INFO:datasets.base_dataset:len of coco: 28344 INFO:datasets.base_dataset:len of mpi-inf-3dhp: 96507 INFO:datasets.base_dataset:len of h36m-p2-mosh: 26859 No renderer for visualization. Traceback (most recent call last): File "train.py", line 69, in main(None, ngpus_per_node, options) File "train.py", line 37, in main trainer = Trainer(options) File "/user3/lwx1055260/ID2462_PyMAF_for_pytorch/core/base_trainer.py", line 28, in init self.init_fn() File "/user3/lwx1055260/ID2462_PyMAF_for_pytorch/core/trainer.py", line 143, in init_fn self.iuv_maker = IUV_Renderer(output_size=cfg.MODEL.PyMAF.DP_HEATMAP_SIZE) NameError: name 'IUV_Renderer' is not defined

    opened by a139122679 5
  • run demo.py

    run demo.py

    Traceback (most recent call last): File "demo.py", line 572, in run_video_demo(args) File "demo.py", line 395, in run_video_demo renderer = PyRenderer(resolution=(orig_width, orig_height)) File "/root/guoshsh/PyMAF-master/utils/renderer.py", line 65, in init point_size=1.0 File "/root/softwares/anaconda3/envs/pymaf/lib/python3.6/site-packages/pyrender/offscreen.py", line 31, in init self._create() File "/root/softwares/anaconda3/envs/pymaf/lib/python3.6/site-packages/pyrender/offscreen.py", line 149, in _create self._platform.init_context() File "/root/softwares/anaconda3/envs/pymaf/lib/python3.6/site-packages/pyrender/platforms/egl.py", line 188, in init_context EGL_NO_CONTEXT, context_attributes File "/root/softwares/anaconda3/envs/pymaf/lib/python3.6/site-packages/OpenGL/platform/baseplatform.py", line 402, in call return self( *args, **named ) File "src/errorchecker.pyx", line 58, in OpenGL_accelerate.errorchecker._ErrorChecker.glCheckError OpenGL.error.GLError: GLError( err = 12297, baseOperation = eglCreateContext, cArguments = ( <OpenGL._opaque.EGLDisplay_pointer object at 0x7f4f4ffb2048>, <OpenGL._opaque.EGLConfig_pointer object at 0x7f4f4ffb2e18>, <OpenGL._opaque.EGLContext_pointer object at 0x7f4f36ac1400>, <OpenGL.arrays.lists.c_int_Array_7 object at 0x7f4f36aba6a8>, ), result = <OpenGL._opaque.EGLContext_pointer object at 0x7f4f50097400> )

    Hi,when I run the demo.py I got this problem with the code,I don"t know how to fix it out

    opened by ketsu-shan 5
  • About MPJPE

    About MPJPE

    Hi, I want to know the MPJPE is compyted on which space? Pixel space or real space? Why multiply 1000 in the code like spin? What are their units and in your paper the number is after multiply 1000? thank u ;)

    opened by ketsu-shan 4
  • Confirmation about necessary files

    Confirmation about necessary files

    'Collect SMPL model files from https://smpl.is.tue.mpg.de and UP. Rename model files' means below ?

    download SMPL_Python_v1.1.0.zip basicmodel_f_lbs_10_207_0_v1.1.0.pkl > SMPL_FEMALE.pkl basicmodel_m_lbs_10_207_0_v1.1.0.pkl > SMPL_MALE.pkl

    download basicModel_neutral_lbs_10_207_0_v1.0.0.pkl > SMPL_NEUTRAL.pkl

    opened by cedro3 4
  • install openpifpaf error

    install openpifpaf error

    Hi! I'm having trouble when installing the 'openpifpaf==0.13.1' in requirements.txt, and there are many errors occurred when I run the command 'pip3 install openpifpaf==0.13.1': ERROR: Failed building wheel for openpifpaf
    Failed to build openpifpaf
    ERROR: Could not build wheels for openpifpaf, which is required to install pyproject.toml-based projects

    Can you explain how to solve this problem? thank you very much!

    opened by Guanyuansheng 3
  • Question about training PyMAF

    Question about training PyMAF

    Hi, Hongwen! Thanks for your great job!

    I have two questions about training PyMAF. 1.

    PyMAF is trained on Human3.6M at the first stage and then trained on the mixture of both 2D and 3D datasets at the second stage.

    Why PyMAF needs to train on H36m first? And will PyMAF get comparable performance to the two-stage training method if PyMAF is trained only on mixed datasets? 2. In PyMAF, num_epochs is set to 200. Compared with other methods in HPS, the training procedure is too long. Is it possible to reduce the num of epochs to reduce the training time while keeping the performance?

    opened by MooreManor 3
  • TypeError: __call__() got an unexpected keyword argument 'image'

    TypeError: __call__() got an unexpected keyword argument 'image'

    Thanks for your brilliant work! But when I train the first stage,I meet one error: Traceback (most recent call last): File "/media/data1/mypath/PyMAF/train.py", line 69, in <module> main(None, ngpus_per_node, options) File "/media/data1/mypath/PyMAF/train.py", line 38, in main trainer.fit() File "/media/data1/mypath/PyMAF/core/trainer.py", line 502, in fit self.train(epoch) File "/media/data1/mypath/PyMAF/core/trainer.py", line 294, in train self.visualize(self.step_count, batch, 'train', **out) File "/media/data1/mypath/anaconda3/envs/pymaf/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context return func(*args, **kwargs) File "/media/data1/mypath/PyMAF/core/trainer.py", line 681, in visualize addlight=True TypeError: __call__() got an unexpected keyword argument 'image' pymaf_res50_as_lp3_mlp256-128-64-5_May06-19-26-01-asJ Epoch 0: 0%| | 10/4877 [

    orginal cfg.TRAIN_VIS_ITER_FERQ =1000, when I set cfg.TRAIN_VIS_ITER_FERQ =10, got the same error. Maybe there is no graphical interface on the remote server? And my env: Ubuntu20 python 3.6.10 torch 1.8.0+cu11.1

    opened by ywx-stack 3
  • Some question about the initial pose of body and hand

    Some question about the initial pose of body and hand

    Thanks for your great work! I have learned that the SMPL-X use the pose parameters to get the final pose from the initial pose (T-Pose), and the pose parameters for each joints is the axis-angle format rotation relative to its parent's rotation. However, I have no detail information about the actual initial coordinate of each joints, including body and hands (especially for the hands). I have tried to search in the original paper, but still got nothing. Here is an example that I would like to know about the initial coordinates. joint-coordinates Is there any documentation about it? Thanks for your attention!

    opened by henrycjh 0
  • some questions about the results

    some questions about the results

    First of all, thank you for your excellent work, and I'd like to ask you a few questions 1、When I trained the second stage according to the pare training config, I found that the loss continued to decrease, but the result getting worse 2、The training used eft 、coco pretrain、pare mixdataset setting,But the lspet dataset is not used,the best result of majpe is epoch 0 82.15(pymafx paper 79.7),Is the difference of lspet dataset so much? 3、If possible, could you please send me the download link of lspet? Now the official website is invalid this is my email [email protected],thanks very much! image

    opened by youwh-PIRI 1
  • Questions about the output results of the same input with different resolutions

    Questions about the output results of the same input with different resolutions

    Hi, if I input the same video with different resolution, what will be the change of shape, pose, and trans in the output result? Now I have a video(1920,1080) and I downsample it to get a video(960,540), will the shape, pose, and trans change (to 1/2 of the original) ?

    opened by surheaven 1
  • How to get the position of SMPLX 3d joints by PyMAF-X

    How to get the position of SMPLX 3d joints by PyMAF-X

    Thank you very much for your amazing work. I would like to ask a question about how to get the position of SMPLX 3d joints by PyMAF-X.

    The output of PyMAF-X includes smplx_verts, pose, betas, joints3d, smplx_params and so on. But I found that the joints3d is inconsistent with SMPLX joints definition. Maybe I can align it to SMPLX joints? I haven't got the idea.I tried to build smplx model from the smplx_params, but failed for some shape-invalid problems. For example, the shape of body pose is [24, 3, 3], but SMPLX expects [x, 21, 3]. (The NUM_BODY_JOINTS equals to 21).

    So could you give me some advice to get SMPLX 3d joints? Looking forward to your reply.

    opened by huanngzh 2
  • About pretrained model on coco

    About pretrained model on coco

    Hi,sorry to bother you,can you please share the pretrained model which named 'data/pretrained_model/pose_resnet_50_256x192.pth.tar' ? thank you very much!

    opened by yangyang32111 4
Owner
Hongwen Zhang
Hongwen Zhang
TensorFlow code for the neural network presented in the paper: "Structural Language Models of Code" (ICML'2020)

SLM: Structural Language Models of Code This is an official implementation of the model described in: "Structural Language Models of Code" [PDF] To ap

null 73 Nov 6, 2022
Inference code for "StylePeople: A Generative Model of Fullbody Human Avatars" paper. This code is for the part of the paper describing video-based avatars.

NeuralTextures This is repository with inference code for paper "StylePeople: A Generative Model of Fullbody Human Avatars" (CVPR21). This code is for

Visual Understanding Lab @ Samsung AI Center Moscow 18 Oct 6, 2022
A code generator from ONNX to PyTorch code

onnx-pytorch Generating pytorch code from ONNX. Currently support onnx==1.9.0 and torch==1.8.1. Installation From PyPI pip install onnx-pytorch From

Wenhao Hu 94 Jan 6, 2023
This is the code for our KILT leaderboard submission to the T-REx and zsRE tasks. It includes code for training a DPR model then continuing training with RAG.

KGI (Knowledge Graph Induction) for slot filling This is the code for our KILT leaderboard submission to the T-REx and zsRE tasks. It includes code fo

International Business Machines 72 Jan 6, 2023
Convert Python 3 code to CUDA code.

Py2CUDA Convert python code to CUDA. Usage To convert a python file say named py_file.py to CUDA, run python generate_cuda.py --file py_file.py --arch

Yuval Rosen 3 Jul 14, 2021
Empirical Study of Transformers for Source Code & A Simple Approach for Handling Out-of-Vocabulary Identifiers in Deep Learning for Source Code

Transformers for variable misuse, function naming and code completion tasks The official PyTorch implementation of: Empirical Study of Transformers fo

Bayesian Methods Research Group 56 Nov 15, 2022
Reference implementation of code generation projects from Facebook AI Research. General toolkit to apply machine learning to code, from dataset creation to model training and evaluation. Comes with pretrained models.

This repository is a toolkit to do machine learning for programming languages. It implements tokenization, dataset preprocessing, model training and m

Facebook Research 408 Jan 1, 2023
Code for the prototype tool in our paper "CoProtector: Protect Open-Source Code against Unauthorized Training Usage with Data Poisoning".

CoProtector Code for the prototype tool in our paper "CoProtector: Protect Open-Source Code against Unauthorized Training Usage with Data Poisoning".

Zhensu Sun 1 Oct 26, 2021
Low-code/No-code approach for deep learning inference on devices

EzEdgeAI A concept project that uses a low-code/no-code approach to implement deep learning inference on devices. It provides a componentized framewor

On-Device AI Co., Ltd. 7 Apr 5, 2022
Code for all the Advent of Code'21 challenges mostly written in python

Advent of Code 21 Code for all the Advent of Code'21 challenges mostly written in python. They are not necessarily the best or fastest solutions but j

null 4 May 26, 2022
Code to use Augmented Shapiro Wilks Stopping, as well as code for the paper "Statistically Signifigant Stopping of Neural Network Training"

This codebase is being actively maintained, please create and issue if you have issues using it Basics All data files are included under losses and ea

J K Terry 32 Nov 9, 2021
Opinionated code formatter, just like Python's black code formatter but for Beancount

beancount-black Opinionated code formatter, just like Python's black code formatter but for Beancount Try it out online here Features MIT licensed - b

Launch Platform 16 Oct 11, 2022
a delightful machine learning tool that allows you to train, test and use models without writing code

igel A delightful machine learning tool that allows you to train/fit, test and use models without writing code Note I'm also working on a GUI desktop

Nidhal Baccouri 3k Jan 5, 2023
Pytorch Lightning code guideline for conferences

Deep learning project seed Use this seed to start new deep learning / ML projects. Built in setup.py Built in requirements Examples with MNIST Badges

Pytorch Lightning 1k Jan 2, 2023
Automatically Build Multiple ML Models with a Single Line of Code. Created by Ram Seshadri. Collaborators Welcome. Permission Granted upon Request.

Auto-ViML Automatically Build Variant Interpretable ML models fast! Auto_ViML is pronounced "auto vimal" (autovimal logo created by Sanket Ghanmare) N

AutoViz and Auto_ViML 397 Dec 30, 2022
Code samples for my book "Neural Networks and Deep Learning"

Code samples for "Neural Networks and Deep Learning" This repository contains code samples for my book on "Neural Networks and Deep Learning". The cod

Michael Nielsen 13.9k Dec 26, 2022
Code for: https://berkeleyautomation.github.io/bags/

DeformableRavens Code for the paper Learning to Rearrange Deformable Cables, Fabrics, and Bags with Goal-Conditioned Transporter Networks. Here is the

Daniel Seita 121 Dec 30, 2022
Code for our method RePRI for Few-Shot Segmentation. Paper at http://arxiv.org/abs/2012.06166

Region Proportion Regularized Inference (RePRI) for Few-Shot Segmentation In this repo, we provide the code for our paper : "Few-Shot Segmentation Wit

Malik Boudiaf 138 Dec 12, 2022
Applications using the GTN library and code to reproduce experiments in "Differentiable Weighted Finite-State Transducers"

gtn_applications An applications library using GTN. Current examples include: Offline handwriting recognition Automatic speech recognition Installing

Facebook Research 68 Dec 29, 2022