Code for "Neural Parts: Learning Expressive 3D Shape Abstractions with Invertible Neural Networks", CVPR 2021

Overview

Neural Parts: Learning Expressive 3D Shape Abstractions with Invertible Neural Networks

Example 1 Example 2 Example 3

This repository contains the code that accompanies our CVPR 2021 paper Neural Parts: Learning Expressive 3D Shape Abstractions with Invertible Neural Networks

You can find detailed usage instructions for training your own models and using our pretrained models below.

If you found this work influential or helpful for your research, please consider citing

@Inproceedings{Paschalidou2021CVPR,
     title = {Neural Parts: Learning Expressive 3D Shape Abstractions with Invertible Neural Networks},
     author = {Paschalidou, Despoina and Katharopoulos, Angelos and Geiger, Andreas and Fidler, Sanja},
     booktitle = {Proceedings IEEE Conf. on Computer Vision and Pattern Recognition (CVPR)},
     year = {2021}
}

Installation & Dependencies

Our codebase has the following dependencies:

For the visualizations, we use simple-3dviz, which is our easy-to-use library for visualizing 3D data using Python and ModernGL and matplotlib for the colormaps. Note that simple-3dviz provides a lightweight and easy-to-use scene viewer using wxpython. If you wish you use our scripts for visualizing the reconstructed primitives, you will need to also install wxpython.

The simplest way to make sure that you have all dependencies in place is to use conda. You can create a conda environment called neural_parts using

conda env create -f environment.yaml
conda activate neural_parts

Next compile the extenstion modules. You can do this via

python setup.py build_ext --inplace
pip install -e .

Demo

Example Output Example Output

You can now test our code on various inputs. To this end, simply download some input samples together with our pretrained models on D-FAUAST humans, ShapeNet chairs and ShapeNet planes from here. Now extract the nerual_parts_demo.zip that you just downloaded in the demo folder. To run our demo on the D-FAUST humans simply run

python demo.py ../config/dfaust_6.yaml --we ../demo/model_dfaust_6 --model_tag 50027_jumping_jacks:00135 --camera_target='-0.030173788,-0.10342446,-0.0021887198' --camera_position='0.076685235,-0.14528269,1.2060229' --up='0,1,0' --with_rotating_camera

This script should create a folder demo/output, where the per-primitive meshes are stored as .obj files. Similarly, you can now also run the demo for the input airplane

python demo.py ../config/shapenet_5.yaml --we ../demo/model_planes_5 --model_tag 02691156:7b134f6573e7270fb0a79e28606cb167 --camera_target='-0.030173788,-0.10342446,-0.0021887198' --camera_position='0.076685235,-0.14528269,1.2060229' --up='0,1,0' --with_rotating_camera

Usage

As soon as you have installed all dependencies and have obtained the preprocessed data, you can now start training new models from scratch, evaluate our pre-trained models and visualize the recovered primitives using one of our pre-trained models.

Reconstruction

To generate meshes using a trained model, we provide the forward_pass.py and the visualize_predictions.py scripts. Their difference is that the first performs the forward pass and generates a per-primitive mesh that is saved as an .obj file. Similarly, the visualize_predictions.py script performs the forward pass and visualizes the predicted primitives using simple-3dviz. The forward_pass.py script is ideal for reconstructing inputs on a heeadless server and you can run it by executing

python forward_pass.py path_to_config_yaml path_to_output_dir --weight_file path_to_weight_file --model_tag MODEL_TAG

where the argument --weight_file specifies the path to a trained model and the argument --model_tag defines the model_tag of the input to be reconstructed.

To run the visualize_predictions.py script you need to run

python visualize_predictions.py path_to_config_yaml path_to_output_dir --weight_file path_to_weight_file --model_tag MODEL_TAG

Using this script, you can easily render the prediction into .png images or a .gif, as well as perform various animations by rotating the camera. Furthermore, you can also specify the camera position, the up vector and the camera target as well as visualize the target mesh together with the predicted primitives simply by adding the --mesh argument.

Evaluation

For evaluation of the models we provide the script evaluate.py. You can run it using:

python evaluate.py path_to_config_yaml path_to_output_dir

The script reconstructs the input and evaluates the generated meshes using a standardized protocol. For each input, the script generates a .npz file that contains the various metrics for that particular input. Note that this script can also be executed multiple times in order to speed up the evaluation process. For example, if you wish to run the evaluation on 6 nodes, you can simply run

for i in {1..6}; do python evaluate.py path_to_config_yaml path_to_output_dir & done
[1] 9489
[2] 9490
[3] 9491
[4] 9492
[5] 9493
[6] 9494

wait
Running code on cpu
Running code on cpu
Running code on cpu
Running code on cpu
Running code on cpu
Running code on cpu

Again the script generates a per-input file in the output directory with the computed metrics.

Training

Finally, to train a new network from scratch, we provide the train_network.py script. To execute this script, you need to specify the path to the configuration file you wish to use and the path to the output directory, where the trained models and the training statistics will be saved. Namely, to train a new model from scratch, you simply need to run

python train_network.py path_to_config_yaml path_to_output_dir

Note tha it is also possible to start from a previously trained model by specifying the --weight_file argument, which should contain the path to a previously trained model. Furthermore, by using the arguments --model_tag and --category_tag, you can also train your network on a particular model (e.g. a specific plane, car, human etc.) or a specific object category (e.g. planes, chairs etc.)

Note that, if you want to use the RAdam optimizer during training, you will have to also install to download and install the corresponding code from this repository.

License

Our code is released under the MIT license which practically allows anyone to do anything with it. MIT license found in the LICENSE file.

Relevant Research

Below we list some papers that are relevant to our work.

Ours:

  • Learning Unsupervised Hierarchical Part Decomposition of 3D Objects from a Single RGB Image pdf,project-page
  • Superquadrics Revisited: Learning 3D Shape Parsing beyond Cuboids pdf,project-page

By Others:

  • Learning Shape Abstractions by Assembling Volumetric Primitives pdf
  • 3D-PRNN: Generating Shape Primitives with Recurrent Neural Networks pdf
  • Im2Struct: Recovering 3D Shape Structure From a Single RGB Image pdf
  • Learning shape templates with structured implicit functions pdf
  • CvxNet: Learnable Convex Decomposition pdf
Comments
  • error in demo.py

    error in demo.py

    Hi, @paschalidoud ,

    When I run the demo.py using the following command, I got the following type error:

    # python demo.py ../config/dfaust_6.yaml --we ../demo/model_dfaust_6 --model_tag 50027_jumping_jacks:00135 --camera_target='-0.030173788,-0.10342446,-0.0021887198' --camera_position='0.076685235,-0.14528269,1.2060229' --up='0,1,0' --with_rotating_camera
    
    Running code on cuda:0
    Found 270 Dynamic Faust models
    Keep 1/270 based on tags
    Traceback (most recent call last):
      File "demo.py", line 210, in <module>
        main(sys.argv[1:])
      File "demo.py", line 172, in main
        for i in parts
      File "demo.py", line 172, in <listcomp>
        for i in parts
      File "/root2/anaconda3/envs/pytorch1.7/lib/python3.7/site-packages/simple_3dviz/renderables/mesh.py", line 317, in from_faces
        [vertices, faces, colors]
      File "/root2/anaconda3/envs/pytorch1.7/lib/python3.7/site-packages/numpy/core/_asarray.py", line 102, in asarray
        return array(a, dtype, copy=False, order=order)
      File "/root2/anaconda3/envs/pytorch1.7/lib/python3.7/site-packages/torch/tensor.py", line 630, in __array__
        return self.numpy()
    TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.
    
    

    It seems some place should be converted to cpu type first. Could you give some hints to solve this issue?

    Thanks~

    opened by amiltonwong 5
  • Clarification about occupancy function

    Clarification about occupancy function

    Hi Dears,

    I tried to understand the conservative_implicit_surface_loss(which is responsible for calculating the occupancy loss)

    I want to know why we use the gt_labels in the method,while the method is supposed to be un-supervised ,what is the ground truth for the points ?

    what is the two terms "inside_but_out" and "outside_but_in" why we take the summation over the points of the target shape as it is explained in the paper,while it should be interest by the point of the primitive,since even if all points in the target shape,the problem is in the points that is in primitive but not in target shape.

    Regards,

    opened by mahmoudEltaher 3
  • Error : RuntimeError: CUDA out of memory. Tried to allocate 30.00 MiB (GPU 0; 8.00 GiB total capacity; 5.97 GiB already allocated; 3.75 MiB free; 6.12 GiB reserved in total by PyTorch)

    Error : RuntimeError: CUDA out of memory. Tried to allocate 30.00 MiB (GPU 0; 8.00 GiB total capacity; 5.97 GiB already allocated; 3.75 MiB free; 6.12 GiB reserved in total by PyTorch)

    Hi, @paschalidoud ,

    When I run the demo.py using the following command, I got the following type error: python scripts/train_network.py config/shapenet_5.yaml output/ Running code on cuda:0 experiment_directory output/AJEYHFV7Y Save experiment statistics in AJEYHFV7Y Found 10 MultiModelsShapeNetV1 models Keep 10/10 based on train/test splits Dataset has 10 elements Found 10 MultiModelsShapeNetV1 models Keep 0/10 based on train/test splits Dataset has 0 elements Traceback (most recent call last): File "scripts/train_network.py", line 288, in main(sys.argv[1:]) File "scripts/train_network.py", line 250, in main network, optimizer, loss_fn, metrics_fn, X, targets, config File "d:\cottbus\code\neural_parts-master\neural_parts\models\flexible_primitives.py", line 258, in train_on_batch F, network, targets, config File "d:\cottbus\code\neural_parts-master\neural_parts\models\flexible_primitives.py", line 214, in compute_predictions_from_features network.implicit_surface(F, targets[-1][:, :, :3]) File "d:\cottbus\code\neural_parts-master\neural_parts\models\flexible_primitives.py", line 58, in implicit_surface y_latent, ldj = self.invertible_network.inverse(F, y) File "d:\cottbus\code\neural_parts-master\neural_parts\models\simple_nvp.py", line 166, in inverse x, ldji = self._call(l.inverse, F, x) File "d:\cottbus\code\neural_parts-master\neural_parts\models\simple_nvp.py", line 116, in _call return func(*args, **kwargs) File "d:\cottbus\code\neural_parts-master\neural_parts\models\simple_nvp.py", line 34, in inverse t = self.map_t(F_x1) File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\site-packages\torch\nn\modules\container.py", line 117, in forward input = module(input) File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\site-packages\torch\nn\modules\linear.py", line 93, in forward return F.linear(input, self.weight, self.bias) File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\site-packages\torch\nn\functional.py", line 1692, in linear output = input.matmul(weight.t()) RuntimeError: CUDA out of memory. Tried to allocate 30.00 MiB (GPU 0; 8.00 GiB total capacity; 5.97 GiB already allocated; 3.75 MiB free; 6.12 GiB reserved in total by PyTorch)

    Could you give some hints to solve this issue? Thanks,

    opened by mahmoudEltaher 1
  • error in train.py  fatal: not a git repository (or any of the parent directories): .git

    error in train.py fatal: not a git repository (or any of the parent directories): .git

    Hi, @paschalidoud ,

    When I run the demo.py using the following command, I got the following type error:

    python scripts/train_network.py config/shapenet_5.yaml output/ Running code on cuda:0 experiment_directory output/H6ICBWNS5 git_dir D:\Cottbus\code\neural_parts-master\scripts fatal: not a git repository (or any of the parent directories): .git fatal: not a git repository (or any of the parent directories): .git Traceback (most recent call last): File "scripts/train_network.py", line 52, in save_experiment_params if epoch < e: File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\subprocess.py", line 395, in check_output **kwargs).stdout File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\subprocess.py", line 487, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['git', 'rev-parse', 'HEAD']' returned non-zero exit status 128.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last): File "scripts/train_network.py", line 287, in # Create a batchprovider object to start generating batches File "scripts/train_network.py", line 186, in main # Parameters related to the loss function and the loss weights File "scripts/train_network.py", line 59, in save_experiment_params return optimizer File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\subprocess.py", line 395, in check_output **kwargs).stdout File "C:\Users\Mahmoud Eltaher\Anaconda3\lib\subprocess.py", line 487, in run output=stdout, stderr=stderr) subprocess.CalledProcessError: Command '['git', 'rev-parse', 'HEAD']' returned non-zero exit status 128.

    Could you give some hints to solve this issue? Thanks,

    opened by mahmoudEltaher 1
  • Comparison with primitive-based methods

    Comparison with primitive-based methods

    From related papers like UCSGNet https://github.com/kacperkan/ucsgnet/ and DagAmendment https://github.com/eliemichel/DagAmendment, how do you relate the proposal to create procedural parameter constraints of a dag graph (union, subtraction, and intersection) to Neural Parts primitives.

    The previous idea is to decompose 3d shapes into primitives so they can be adjusted by sliders.

    Examples cases are like in a character creator to create new combination of shapes or via hyperparameter optimization as in DagAmendment to procedurally generate new models.

    opened by fire 1
  • Difference between sampled_faces.npy and pointcloud.npz

    Difference between sampled_faces.npy and pointcloud.npz

    Hi, I would like to ask what is the difference between the two files. From what I know, pointcloud.npz (as well as model.binvox, points.npz and img_choy2016) was originally from the dataset pre-processed by Occupancy Networks here. Upon my inspection, the first three columns of sampled_faces.npy gives the point cloud / sampled points on the mesh and the last three columns give the surface normals from the mesh. While both files contain 100000 samples, they don't exactly match in terms of the point coordinates and surface normals. With that, what is the distinction between the two? Thank you.

    opened by low5545 0
[CVPR 21] Vectorization and Rasterization: Self-Supervised Learning for Sketch and Handwriting, IEEE Conf. on Computer Vision and Pattern Recognition (CVPR), 2021.

Vectorization and Rasterization: Self-Supervised Learning for Sketch and Handwriting, CVPR 2021. Ayan Kumar Bhunia, Pinaki nath Chowdhury, Yongxin Yan

Ayan Kumar Bhunia 44 Dec 12, 2022
[CVPR 2022] CoTTA Code for our CVPR 2022 paper Continual Test-Time Domain Adaptation

CoTTA Code for our CVPR 2022 paper Continual Test-Time Domain Adaptation Prerequisite Please create and activate the following conda envrionment. To r

Qin Wang 87 Jan 8, 2023
[CVPR 2021] Released code for Counterfactual Zero-Shot and Open-Set Visual Recognition

Counterfactual Zero-Shot and Open-Set Visual Recognition This project provides implementations for our CVPR 2021 paper Counterfactual Zero-S

null 144 Dec 24, 2022
Code for Multiple Instance Active Learning for Object Detection, CVPR 2021

Language: 简体中文 | English Introduction This is the code for Multiple Instance Active Learning for Object Detection, CVPR 2021. Installation A Linux pla

Tianning Yuan 269 Dec 21, 2022
Code for our CVPR 2021 paper "MetaCam+DSCE"

Joint Noise-Tolerant Learning and Meta Camera Shift Adaptation for Unsupervised Person Re-Identification (CVPR'21) Introduction Code for our CVPR 2021

FlyingRoastDuck 59 Oct 31, 2022
Official code of the paper "ReDet: A Rotation-equivariant Detector for Aerial Object Detection" (CVPR 2021)

ReDet: A Rotation-equivariant Detector for Aerial Object Detection ReDet: A Rotation-equivariant Detector for Aerial Object Detection (CVPR2021), Jiam

csuhan 334 Dec 23, 2022
Code for Multiple Instance Active Learning for Object Detection, CVPR 2021

MI-AOD Language: 简体中文 | English Introduction This is the code for Multiple Instance Active Learning for Object Detection (The PDF is not available tem

Tianning Yuan 269 Dec 21, 2022
Official code for the paper: Deep Graph Matching under Quadratic Constraint (CVPR 2021)

QC-DGM This is the official PyTorch implementation and models for our CVPR 2021 paper: Deep Graph Matching under Quadratic Constraint. It also contain

Quankai Gao 55 Nov 14, 2022
Code for CVPR 2021 paper: Anchor-Free Person Search

Introduction This is the implementationn for Anchor-Free Person Search in CVPR2021 License This project is released under the Apache 2.0 license. Inst

null 158 Jan 4, 2023
Code of paper "CDFI: Compression-Driven Network Design for Frame Interpolation", CVPR 2021

CDFI (Compression-Driven-Frame-Interpolation) [Paper] (Coming soon...) | [arXiv] Tianyu Ding*, Luming Liang*, Zhihui Zhu, Ilya Zharkov IEEE Conference

Tianyu Ding 95 Dec 4, 2022
Code release for "Transferable Semantic Augmentation for Domain Adaptation" (CVPR 2021)

Transferable Semantic Augmentation for Domain Adaptation Code release for "Transferable Semantic Augmentation for Domain Adaptation" (CVPR 2021) Paper

null 66 Dec 16, 2022
Code for "LoFTR: Detector-Free Local Feature Matching with Transformers", CVPR 2021

LoFTR: Detector-Free Local Feature Matching with Transformers Project Page | Paper LoFTR: Detector-Free Local Feature Matching with Transformers Jiami

ZJU3DV 1.4k Jan 4, 2023
Code for "NeuralRecon: Real-Time Coherent 3D Reconstruction from Monocular Video", CVPR 2021 oral

NeuralRecon: Real-Time Coherent 3D Reconstruction from Monocular Video Project Page | Paper NeuralRecon: Real-Time Coherent 3D Reconstruction from Mon

ZJU3DV 1.4k Dec 30, 2022
Official PyTorch Code of GrooMeD-NMS: Grouped Mathematically Differentiable NMS for Monocular 3D Object Detection (CVPR 2021)

GrooMeD-NMS: Grouped Mathematically Differentiable NMS for Monocular 3D Object Detection GrooMeD-NMS: Grouped Mathematically Differentiable NMS for Mo

Abhinav Kumar 76 Jan 2, 2023
Official code for the CVPR 2021 paper "How Well Do Self-Supervised Models Transfer?"

How Well Do Self-Supervised Models Transfer? This repository hosts the code for the experiments in the CVPR 2021 paper How Well Do Self-Supervised Mod

Linus Ericsson 157 Dec 16, 2022
Demo code for paper "Learning optical flow from still images", CVPR 2021.

Depthstillation Demo code for "Learning optical flow from still images", CVPR 2021. [Project page] - [Paper] - [Supplementary] This code is provided t

null 130 Dec 25, 2022
Official PyTorch code of Holistic 3D Scene Understanding from a Single Image with Implicit Representation (CVPR 2021)

Implicit3DUnderstanding (Im3D) [Project Page] Holistic 3D Scene Understanding from a Single Image with Implicit Representation Cheng Zhang, Zhaopeng C

Cheng Zhang 149 Jan 8, 2023
Official code of CVPR 2021's PLOP: Learning without Forgetting for Continual Semantic Segmentation

PLOP: Learning without Forgetting for Continual Semantic Segmentation This repository contains all of our code. It is a modified version of Cermelli e

Arthur Douillard 116 Dec 14, 2022
Code for Pose-Controllable Talking Face Generation by Implicitly Modularized Audio-Visual Representation (CVPR 2021)

Pose-Controllable Talking Face Generation by Implicitly Modularized Audio-Visual Representation (CVPR 2021) Hang Zhou, Yasheng Sun, Wayne Wu, Chen Cha

Hang_Zhou 628 Dec 28, 2022