Official implementation of NPMs: Neural Parametric Models for 3D Deformable Shapes - ICCV 2021

Overview

NPMs: Neural Parametric Models

Project Page | Paper | ArXiv | Video


NPMs: Neural Parametric Models for 3D Deformable Shapes
Pablo Palafox, Aljaz Bozic, Justus Thies, Matthias Niessner, Angela Dai

Citation

@article{palafox2021npms
    author        = {Palafox, Pablo and Bo{\v{z}}i{\v{c}}, Alja{\v{z}} and Thies, Justus and Nie{\ss}ner, Matthias and Dai, Angela},
    title         = {NPMs: Neural Parametric Models for 3D Deformable Shapes},
    journal       = {arXiv preprint arXiv:2104.00702},
    year          = {2021},
}

Install

You can either pull our docker image, build it yourself with the provided Dockerfile or build the project from source.

Pull Docker Image

docker pull ppalafox/npms:latest

You can now run an interactive container of the image you just built (before that, navigate to npms):

cd npms
docker run --ipc=host -it --name npms --gpus=all -v $PWD:/app -v /cluster:/cluster npms:latest bash

Build Docker Image

Run the following from within the root of this project (where Dockerfile lives) to build a docker image with all required dependencies.

docker build . -t npms

You can now run an interactive container of the image you just built (before that, navigate to npms):

cd npms
docker run --ipc=host -it --name npms --gpus=all -v $PWD:/app -v /cluster:/cluster npms:latest bash

Of course, you'll have to specify you're own paths to the volumes you'd like to mount using the -v flag.

Build from source

A linux system with cuda is required for the project.

The npms_env.yml file contains (hopefully) all necessary python dependencies for the project. To conveniently install them automatically with anaconda you can use:

conda env create -f npms_env.yml
conda activate npms
Other dependencies

We need some other dependencies. Starting from the root folder of this project, we'll do the following...

  • Compile the csrc folder:
cd csrc 
python setup.py install
cd ..
  • We need some libraries from IFNet. In particular, we need libmesh and libvoxelize from that repo. They are already placed within external. (Check the corresponding LICENSE). To build these, proceed as follows:
cd libmesh/
python setup.py build_ext --inplace
cd ../libvoxelize/
python setup.py build_ext --inplace
cd ..
chmod +x build_gaps.sh
./build_gaps.sh

       You can make sure it's built properly by running:

chmod +x gaps_is_installed.sh
./gaps_is_installed.sh

       You should get a "Ready to go!" as output.

You can now navigate back to the root folder: cd ..

Data Preparation

As an example, let's have a quick overview of what the process would look like in order to generate training data from the CAPE dataset.

Download their dataset, by registering and accepting their terms. Once you've followed their steps to download the dataset, you should have a folder named cape_release.

In npms/configs_train/config_train_HUMAN.py, set the variable ROOT to point to the folder where you want your data to live in. Then:

cd <ROOT>
mkdir data

And place cape_release within data.

Download SMPL models

Register here to get access to SMPL body models. Then, under the downloads tab, download the models. Refer to https://github.com/vchoutas/smplx#model-loading for more details.

From within the root folder of this project, run:

cd npms/body_model
mkdir smpl

And place the .pkl files you just downloaded under npms/body_model/smpl. Now change their names, such that you have something like:

body_models
│── smpl
│  │── smpl
│  │  └── SMPL_FEMALE.pkl
│  │  └── SMPL_MALE.pkl
│  │  └── SMPL_NEUTRAL.pkl

Preprocess the raw CAPE

Now let's process the raw data in order to generate training samples for our NPM.

cd npms/data_processing
python prepare_cape_data.py

Then, we normalize the preprocessed dataset, such that the meshes reside within a bounding box with boundaries bbox_min=-0.5 and bbox_max=0.5.

# We're within npms/data_processing
python normalize_dataset.py

At this point, we can generate training samples for both the shape and the pose MLP. An extra step would be required if our t-poses (<ROOT>/datasets/cape/a_t_pose/000000/mesh_normalized.ply) were not watertight. We'd need to run multiview_to_watertight_mesh.py. Since CAPE is already watertight, we don't need to worry about this.

About labels.json and labels_tpose.json

One last thing before actually generating the samples is to create some "labels" files that specify the paths to the dataset we wanna create. Under the folder ZSPLITS_HUMAN we have copied some examples.

Within it, you can find other folders containing datasets in the form of the paths to the actual data. For example, CAPE-SHAPE-TRAIN-35id, which in turn contains two files: labels_tpose and labels. They define datasets in a flexible way, by means of a list of dictionaries, where each dictionary holds the paths to a particular sample. You'll get a feeling of why we have a labels.json and labels_tpose.json by running the following sections to generate data, as well as when you dive into actually training a new NPM from scratch.

Go ahead and copy the folder ZSPLITS_HUMAN into <ROOT>/datasets, where ROOT is a path to your datasets that you can specify in npms/configs_train/config_train_HUMAN.py. If you followed along until now, within <ROOT>/datasets you should already have the preprocessed <ROOT>/datasets/cape dataset.

# Assuming you're in the root folder of the project
cp -r ZSPLITS_HUMAN <ROOT>/datasets

Note: within data_scripts you can find helpful scripts to generate your own labels.json and labels_tpose.json from a dataset. Check out the npms/data_scripts/README.md for a brief overview on these scripts.

SDF samples

Generate SDF samples around our identities in their t-pose in order to train the shape latent space.

# We're within npms/data_processing
python sample_boundary_sdf_gaps.py
Flow samples

Generate correspondences from an identity in its t-pose to its posed instances.

# We're within npms/data_processing
python sample_flow.py -sigma 0.01
python sample_flow.py -sigma 0.002

We're done with generating data for CAPE! This was just an example using CAPE, but as you've seen, the only thing you need to have is a dataset of meshes:

  • we need t-pose meshes for each identity in the dataset, and we can use multiview_to_watertight_mesh.py to make these t-pose meshes watertight, to then sample points and their SDF values.
  • for a given identity, we need to have surface correspondences between the t-pose and the posed meshes (but note that these posed meshes don't need to be watertight).

Training an NPM

Shape Latent Space

Set only_shape=True in config_train_HUMAN.py. Then, from within the npms folder, start the training:

python train.py

Pose Latent Space

Set only_shape=False in config_train_HUMAN.py. We now need to load the best checkpoint from training the shape MLP. For that, go to config_train_HUMAN.py, make sure init_from = True in its first appearance in the file, and then set this same variable to your pretrained model name later in the file:

init_from = "<model_name>"
checkpoint = <the_epoch_number_you_want_to_load>

Then, from within the npms folder, start the training:

python train.py

Once we reach convergence, you're done. You know have latent spaces of shape and pose that you can play with.

You could:

Fitting an NPM to a Monocular Depth Sequence

Code Initialization

When fitting an NPM to monocular depth sequence, it is recommended that we have a relatively good initialization of our shape and pose codes to avoid falling into local minima. To this end, we are gonna learn a shape and a pose encoder that map an input depth map to a shape and pose code, respectively.

We basically use the shape and pose codes that we've learned during training time as targets for training the shape and pose encoders. You can use prepare_labels_shape_encoder.py and prepare_labels_pose_encoder.py to generate the dataset labels for this encoder training.

You basically have to train them like so:

python encode_shape_codes.py
python encode_pose_codes.py

And regarding the data you need for training the encoder...

Data preparation: Take a look at the scripts voxelize_multiview.py to prepare the single-view voxel grids that we require to train our encoders.

Test-time Optimization

Now you can fit NPMs to an input monocular depth sequence:

python fit_npm.py -o -d HUMAN -e <EXTRA_NAME_IF_YOU_WANT>

The -o flag for optimize; the -d flag for the kind of dataset (HUMAN, MANO) and the -e flag for appending a string to the name of the current optimization run.

You'll have to take a look at config_eval_HUMAN.py and set the name of your trained model (exp_model) and its hyperparameters, as well as the dataset name dataset_name you want to evaluate on.

It's definitely not the cleanest and easiest config file, sorry for that!

Data preparation: Take a look at the scripts compute_partial_sdf_grid.py to prepare the single-view SDF grid that we assume as input at test-time.

Visualization

With the following script you can visualize your fitting. Have a look at config_viz_OURS.py and set the name of your trained model (exp_model) as well as the name of your optimization run (run_name) of test-time fitting you just computed.

python viz_all_methods.py -m NPM -d HUMAN

There are a bunch of other scripts for visualization. They're definitely not cleaned-up, but I kept them here anyways in case they might be useful for you as a starting point.

Compute metrics

python compute_errors.py -n <name_of_optimization_run>

Latent-space Interpolation

Check out the files:

Shape and Pose Transfer

Check out the files:

Pretrained Models

Download pre-trained models here

License

NPMs is relased under the MIT License. See the LICENSE file for more details.

Check the corresponding LICENSES of the projects under the external folder.

For instance, we make use of libmesh and libvoxelize, which come from IFNets. Please check their LICENSE.

We need some helper functions from LDIF. Namely, base_util.py and file_util.py, which should be already under utils. Check the license and copyright in those files.

Comments
  • add the .cpp & .c dependencies back into the repo

    add the .cpp & .c dependencies back into the repo

    This PR aims to fix the missing .cpp & .c files in the external folder, which is caused by the wildcard .c .cpp pattern in .gitignore

    So people don't have to go through the grunt work of finding them manually.

    I am assuming this fix is desired because the .h & .hh files are still in the repo. If this is not the case, git submodule is another viable alternative.

    opened by johnbanq 1
  • setting of bounding box

    setting of bounding box

    Appreciate your interesting work. I am a little confused about the setting of the bounding box in your experiments. You set compute_bbox = Falseas default in normalize_dataset.py, it means you use a predefined bounding box(bbox.json) to normalize the meshes. If I set compute_bbox = True to compute them in the cape datasets, I should get the same results as bbox.json, right? and the boundary should be set as [-0.5, 0.5] in both two options.

    opened by NguyenTriTrinh 1
  • Unable to build gaps

    Unable to build gaps

    I was able to successfully install the dependencies. While building gaps, whenever I run " ./build_gaps.sh ", I get the following error:

    # # CD inside the external folder
    # cd external
    
    # This should create a gaps/ folder at external/gaps/
    if [[ -d gaps ]]
    then
      echo "GAPS has already been cloned, skipping."
    else
      git clone https://github.com/tomfunkhouser/gaps.git
    fi
    GAPS has already been cloned, skipping.
    
    # Necessary dependencies:
    # Figure out whether we are on MacOS or Linux:
    # if [[ $(uname -s) == Darwin* ]]
    # then
      # echo "On MacOS, GL dependencies should have shipped and OSMesa support is disabled."
    # else
      #On linux, the packages need to be installed.
      # sudo apt-get update
      # sudo apt-get install -y mesa-common-dev libglu1-mesa-dev libosmesa6-dev libxi-dev libgl1-mesa-dev libglew-dev
      # For some reason on Ubuntu there can be a broken link from /usr/lib/x86_64-linux-gnu/libGL.so
      # to libGL.so.1.2.0 in the same directory, which does not exist. However libgl1-mesa-glx should
      # provide libGL.so.1.2.0. Reinstalling libgl1-mesa-glx results in libGL.so.1.2.0 correctly
      # existing in /usr/lib/x86_64-linux-gnu as it should.
      # sudo apt-get install -y --reinstall libgl1-mesa-glx
    # fi
    # If the above command(s) fail, get the GL/gl.h and GL/glu.h headers, OSMesa and GL
    # static libraries (osmesa on macos), delete the above code, and try again.
    
    # Now apply customizations to GAPS:
    
    # This should make a copy of the qview folder at ldif/ldif/gaps/apps/qview/
    if [[ -d gaps/apps/qview ]]
    then
      echo "qview has already been copied into ldif/ldif/gaps/qview, skipping."
    else
      cp -R ./qview gaps/apps/
    fi
    qview has already been copied into ldif/ldif/gaps/qview, skipping.
    
    # Everything is local to GAPS from this point:
    cd gaps
    
    # Ptsview and qview aren't built by default, adjust the makefile to build them.
    # sed commands are for script idempotency
    sed -i.bak '/ptsview/d' ./apps/Makefile
    sed -i.bak '/qview/d' ./apps/Makefile
    echo "  cd ptsview; \$(MAKE) \$(TARGET)" >> ./apps/Makefile
    echo "  cd qview; \$(MAKE) \$(TARGET)" >> ./apps/Makefile
    
    # Make GAPS (assuming 8 threads):
    # On MacOS, using OSMesa is more difficult, so we don't
    if [[ ! $(uname -s) == Darwin* ]]
    then
      make mesa -j8
    else
      make -j8
    fi
    make target "TARGET=mesa"
    make[1]: Entering directory '/lustre/work/jnehvi/npms/external/gaps'
    cd pkgs; make mesa
    make[2]: Entering directory '/lustre/work/jnehvi/npms/external/gaps/pkgs'
    make target "TARGET=mesa"
    make[3]: Entering directory '/lustre/work/jnehvi/npms/external/gaps/pkgs'
    cd RNBasics; make mesa
    make[4]: Entering directory '/lustre/work/jnehvi/npms/external/gaps/pkgs/RNBasics'
    make ../../lib/x86_64/libRNBasics.a "CFLAGS=  -Wall -I. -I../../pkgs -O3 -DNDEBUG -DUSE_MESA" 
    make[5]: Entering directory '/lustre/work/jnehvi/npms/external/gaps/pkgs/RNBasics'
    make[5]: *** No rule to make target 'RNBasics.cpp', needed by '../../lib/x86_64/libRNBasics.a'.  Stop.
    make[5]: Leaving directory '/lustre/work/jnehvi/npms/external/gaps/pkgs/RNBasics'
    make[4]: *** [../../makefiles/Makefile.pkgs:48: mesa] Error 2
    make[4]: Leaving directory '/lustre/work/jnehvi/npms/external/gaps/pkgs/RNBasics'
    make[3]: *** [Makefile:52: target] Error 2
    make[3]: Leaving directory '/lustre/work/jnehvi/npms/external/gaps/pkgs'
    make[2]: *** [Makefile:41: mesa] Error 2
    make[2]: Leaving directory '/lustre/work/jnehvi/npms/external/gaps/pkgs'
    make[1]: *** [Makefile:32: target] Error 2
    make[1]: Leaving directory '/lustre/work/jnehvi/npms/external/gaps'
    make: *** [Makefile:18: mesa] Error 2
    

    Your help will be appreciated.

    opened by jalees018 1
  • Number of camera views when generating voxelized data to train the shape encoder

    Number of camera views when generating voxelized data to train the shape encoder

    Hi @pablopalafox, thanks for your interesting work. May i know how many camera views you are using to generate the voxelized data for the shape encoder? Currently it is set to 1 in the released code, but there is one comment line, which shows 'render 4 views'. May I know the number of camera views you are using exactly during this process?

    opened by chaneyddtt 1
  • When will the code of

    When will the code of "SPAMs: Structured Implicit Parametric Models" be released?

    I found that your new paper, "SPAMs: Structured Implicit Parametric Models" are accepted by CVPR 2022. When will the code of "SPAMs: Structured Implicit Parametric Models" be released?

    opened by ksoy0128 0
Owner
PabloPalafox
PhD Student @ TU Munich w/ Angela Dai
PabloPalafox
Implementation of Deformable Attention in Pytorch from the paper "Vision Transformer with Deformable Attention"

Deformable Attention Implementation of Deformable Attention from this paper in Pytorch, which appears to be an improvement to what was proposed in DET

Phil Wang 128 Dec 24, 2022
Official code release for ICCV 2021 paper SNARF: Differentiable Forward Skinning for Animating Non-rigid Neural Implicit Shapes.

Official code release for ICCV 2021 paper SNARF: Differentiable Forward Skinning for Animating Non-rigid Neural Implicit Shapes.

null 235 Dec 26, 2022
Code for ICCV 2021 paper: ARAPReg: An As-Rigid-As Possible Regularization Loss for Learning Deformable Shape Generators..

ARAPReg Code for ICCV 2021 paper: ARAPReg: An As-Rigid-As Possible Regularization Loss for Learning Deformable Shape Generators.. Installation The cod

Bo Sun 132 Nov 28, 2022
This repository contains the accompanying code for Deep Virtual Markers for Articulated 3D Shapes, ICCV'21

Deep Virtual Markers This repository contains the accompanying code for Deep Virtual Markers for Articulated 3D Shapes, ICCV'21 Getting Started Get sa

KimHyomin 45 Oct 7, 2022
This is the official source code for SLATE. We provide the code for the model, the training code, and a dataset loader for the 3D Shapes dataset. This code is implemented in Pytorch.

SLATE This is the official source code for SLATE. We provide the code for the model, the training code and a dataset loader for the 3D Shapes dataset.

Gautam Singh 66 Dec 26, 2022
Learning Skeletal Articulations with Neural Blend Shapes

This repository provides an end-to-end library for automatic character rigging and blend shapes generation as well as a visualization tool. It is based on our work Learning Skeletal Articulations with Neural Blend Shapes that is published in SIGGRAPH 2021.

Peizhuo 504 Dec 30, 2022
Code for Learning Manifold Patch-Based Representations of Man-Made Shapes, in ICLR 2021.

LearningPatches | Webpage | Paper | Video Learning Manifold Patch-Based Representations of Man-Made Shapes Dmitriy Smirnov, Mikhail Bessmeltsev, Justi

Dima Smirnov 22 Nov 14, 2022
This is the code for Deformable Neural Radiance Fields, a.k.a. Nerfies.

Deformable Neural Radiance Fields This is the code for Deformable Neural Radiance Fields, a.k.a. Nerfies. Project Page Paper Video This codebase conta

Google 1k Jan 9, 2023
Some code of the implements of Geological Modeling Using 3D Pixel-Adaptive and Deformable Convolutional Neural Network

3D-GMPDCNN Geological Modeling Using 3D Pixel-Adaptive and Deformable Convolutional Neural Network PyTorch implementation of "Geological Modeling Usin

null 5 Nov 21, 2022
[CVPRW 2021] Code for Region-Adaptive Deformable Network for Image Quality Assessment

RADN [CVPRW 2021] Code for Region-Adaptive Deformable Network for Image Quality Assessment [Paper on arXiv] Overview Update [2021/5/7] add codes for W

IIGROUP 53 Dec 28, 2022
Implementation based on Paper - Learning a Probabilistic Latent Space of Object Shapes via 3D Generative-Adversarial Modeling

Implementation based on Paper - Learning a Probabilistic Latent Space of Object Shapes via 3D Generative-Adversarial Modeling

HamasKhan 3 Jul 8, 2022
pytorch implementation of "Contrastive Multiview Coding", "Momentum Contrast for Unsupervised Visual Representation Learning", and "Unsupervised Feature Learning via Non-Parametric Instance-level Discrimination"

Unofficial implementation: MoCo: Momentum Contrast for Unsupervised Visual Representation Learning (Paper) InsDis: Unsupervised Feature Learning via N

Zhiqiang Shen 16 Nov 4, 2020
This repository contains a pytorch implementation of "HeadNeRF: A Real-time NeRF-based Parametric Head Model (CVPR 2022)".

HeadNeRF: A Real-time NeRF-based Parametric Head Model This repository contains a pytorch implementation of "HeadNeRF: A Real-time NeRF-based Parametr

null 294 Jan 1, 2023
The pytorch implementation of DG-Font: Deformable Generative Networks for Unsupervised Font Generation

DG-Font: Deformable Generative Networks for Unsupervised Font Generation The source code for 'DG-Font: Deformable Generative Networks for Unsupervised

null 130 Dec 5, 2022
PyTorch implementation of Deformable Convolution

Deformable Convolutional Networks in PyTorch This repo is an implementation of Deformable Convolution. Ported from author's MXNet implementation. Buil

null 411 Dec 16, 2022
PyTorch implementation of Deformable Convolution

PyTorch implementation of Deformable Convolution !!!Warning: There is some issues in this implementation and this repo is not maintained any more, ple

Wei Ouyang 893 Dec 18, 2022
3D AffordanceNet is a 3D point cloud benchmark consisting of 23k shapes from 23 semantic object categories, annotated with 56k affordance annotations and covering 18 visual affordance categories.

3D AffordanceNet This repository is the official experiment implementation of 3D AffordanceNet benchmark. 3D AffordanceNet is a 3D point cloud benchma

null 49 Dec 1, 2022
SymmetryNet: Learning to Predict Reflectional and Rotational Symmetries of 3D Shapes from Single-View RGB-D Images

SymmetryNet SymmetryNet: Learning to Predict Reflectional and Rotational Symmetries of 3D Shapes from Single-View RGB-D Images ACM Transactions on Gra

null 26 Dec 5, 2022
Behind the Curtain: Learning Occluded Shapes for 3D Object Detection

Behind the Curtain: Learning Occluded Shapes for 3D Object Detection Acknowledgement We implement our model, BtcDet, based on [OpenPcdet 0.3.0]. Insta

Qiangeng Xu 163 Dec 19, 2022