Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
m-niemeyer committed Oct 14, 2019
1 parent f6e6551 commit c002add
Show file tree
Hide file tree
Showing 202 changed files with 30,980 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
out
.vscode
.pytest_cache
.cache
*.pyc
*.pt
*.so
*.o
*.prof
.nfs*
im2mesh/utils/libmcubes/mcubes.cpp
im2mesh/utils/libsimplify/simplify_mesh.cpp
im2mesh/utils/libsimplify/build
data/Humans.zip
data/Humans/D-FAUST
data/Humans/D-FAUST_test
161 changes: 161 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Occupancy Flow
<div style="text-align: center">
<img src="animations/pointcloud_output.gif" width="256"/>
<img src="animations/shape_interpolation.gif" width="256" />
<img src="animations/image_output.gif" width="256" />
</div>

This repository contains the code for the project [Occupancy Flow - 4D Reconstruction by Learning Particle Dynamics](https://avg.is.tuebingen.mpg.de/publications/niemeyer2019iccv).

You can find detailed usage instructions for training your own models and using pre-trained models below.

If you find our code or paper useful, please consider citing

@inproceedings{OccupancyFlow,
title = {Occupancy Flow: 4D Reconstruction by Learning Particle Dynamics},
author = {Niemeyer, Michael and Mescheder, Lars and Oechsle, Michael and Geiger, Andreas},
booktitle = {Proc. of the IEEE International Conf. on Computer Vision (ICCV)},
year = {2019}
}

## Installation
First you have to make sure that you have all dependencies in place. The simplest way to do so, is to use [anaconda](https://www.anaconda.com/).

You can create and activate an anaconda environment called `oflow` using

```
conda env create -f environment.yaml
conda activate oflow
```
Next, compile the extension modules. You can do this via
```
python setup.py build_ext --inplace
```

## Demo

You can test our code on the provided input point cloud sequences in the `demo/` folder. To this end, simple run
```
python generate.py configs/demo.yaml
```
This script should create a folder `out/demo/` where the output is stored.

## Dataset

### Point-based Data
To train a new model from scratch, you have to download the full dataset.
You can download the pre-processed data (~42 GB) using

```
bash scripts/download_data.sh
```

The script will download the point-based point-based data for the [Dynamic FAUST (D-FAUST)](http://dfaust.is.tue.mpg.de/) dataset to the `data/` folder.

_Please note_: We do not provide the renderings for the 4D reconstruction from image sequences experiment nor the meshes for the interpolation and generative tasks due to privacy regulations. We outline how you can download the mesh data in the following.

### Mesh Data

Please follow the instructions on [D-FAUST homepage](http://dfaust.is.tue.mpg.de/) to download the "female and male registrations" as well as "scripts to load / parse the data".
Next, follow their instructions in the `scripts/README.txt` file to extract the obj-files of the sequences. Once completed, you should have a folder with the following structure:
___
your_dfaust_folder/
| 50002_chicken_wings/
&nbsp;&nbsp;&nbsp;&nbsp;| 00000.obj
&nbsp;&nbsp;&nbsp;&nbsp;| 00001.obj
&nbsp;&nbsp;&nbsp;&nbsp;| ...
&nbsp;&nbsp;&nbsp;&nbsp;| 000215.obj
| 50002_hips/
&nbsp;&nbsp;&nbsp;&nbsp;| 00000.obj
&nbsp;&nbsp;&nbsp;&nbsp;| ...
| ...
| 50027_shake_shoulders/
&nbsp;&nbsp;&nbsp;&nbsp;| 00000.obj
&nbsp;&nbsp;&nbsp;&nbsp;| ...
___
You can now run
```
bash scripts/migrate_dfaust.sh path/to/your_dfaust_folder
```
to copy the mesh data to the dataset folder.
The argument has to be the folder to which you have extracted the mesh data (the `your_dfaust_folder` from the directory tree above).

## Usage

<div style="text-align: center">
<img src="animations/interpolation.gif" width="400"/>
<img src="animations/motion_transfer.gif" width="400"/>
</div>

When you have installed all dependencies and obtained the preprocessed data, you are ready to run our pre-trained models and train new models from scratch.

### Generation
To start the normal mesh generation process using a trained model, use

```
python generate.py configs/CONFIG.yaml
```
where you replace `CONFIG.yaml` with the name of the configuration file you want to use.

The easiest way is to use a pretrained model. You can do this by using one of the config files

```
configs/pointcloud/oflow_w_correspond_pretrained.yaml
configs/interpolation/oflow_pretrained.yaml
configs/generative/oflow_pretrained.yaml
```

Our script will automatically download the model checkpoints and run the generation.
You can find the outputs in the `out/` folder.

Please note that the config files *_pretrained.yaml are only for generation, not for training new models: when these configs are used for training, the model will be trained from scratch, but during inference our code will still use the pretrained model.

### Generation - Generative Tasks

For model-specific latent space interpolations and motion transfers, you first have to run
```
python encode_latent_motion_space.py config/generative/CONFIG.yaml
```
Next, you can call
```
python generate_latent_space_interpolation.py config/generative/CONFIG.yaml
```
or
```
python generate_motion_transfer.py config/generative/CONFIG.yaml
```

*Please note*: Make sure that you use the appropriate model for the generation processes, e.g. the latent space interpolations and motion transfers can only be generated with a generative model (e.g. `configs/generative/oflow_pretrained.yaml`).

### Evaluation
You can evaluate the generated output of a model on the test set using

```
python eval.py configs/CONFIG.yaml
```
The evaluation results will be saved to pickle and csv files.

### Training

Finally, to train a new network from scratch, run
```
python train.py configs/CONFIG.yaml
```
You can monitor the training process on http://localhost:6006 using tensorboard:
```
cd OUTPUT_DIR
tensorboard --logdir ./logs --port 6006
```
where you replace `OUTPUT_DIR` with the respective output directory. For available training options, please have a look at `config/default.yaml`.


## Further Information

### Implicit Representations
If you like the Occupancy Flow project, please check out our similar projects on inferring [3D shapes (Occupancy Networks)](https://avg.is.tuebingen.mpg.de/publications/occupancy-networks) and [texture (Texture Fields)](https://avg.is.tuebingen.mpg.de/publications/oechsle2019iccv).

### Neural Ordinary Differential Equations
If you enjoyed our approach using differential equations, checkout Ricky Chen et. al.'s awesome implementation of [differentiable ODE solvers](https://github.com/rtqichen/torchdiffeq) which we used in our project.

### Dynamic FAUST Dataset
We applied our method to the cool [Dynamic FAUST](http://dfaust.is.tue.mpg.de/) dataset which contains sequences of real humans performing various actions.
Binary file added animations/image_output.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/interpolation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/motion_transfer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/pointcloud_output.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added animations/shape_interpolation.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions configs/default.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
method: oflow
data:
path: data/Humans
dataset: Humans
input_type: pcl_seq
classes: ['D-FAUST']
train_split: train
val_split: val
test_split: test
dim: 3
n_training_points: 512
points_unpackbits: true
n_training_pcl_points: 100
input_pointcloud_n: 300
input_pointcloud_noise: 0.001
input_pointcloud_corresponding: true
n_views: 24
img_size: 224
img_with_camera: false
img_augment: false
length_sequence: 17
offset_sequence: 15
n_files_per_sequence: -1
points_file: points.npz
mesh_seq_folder: mesh_seq
points_iou_seq_folder: points_seq
pointcloud_seq_folder: pcl_seq
img_seq_folder: img
model:
encoder: pointnet_resnet
encoder_temporal: pointnet_resnet
decoder: cbatchnorm
velocity_field: concat
encoder_latent: null
encoder_latent_temporal: null
decoder_kwargs: {}
encoder_kwargs: {}
encoder_latent_kwargs: {}
encoder_temporal_kwargs: {}
velocity_field_kwargs: {}
encoder_latent_temporal_kwargs: {}
learn_embedding: false
ode_solver: dopri5
ode_step_size: null
use_adjoint: true
rtol: 0.001
atol: 0.00001
vae_beta: 0.0001
loss_corr: false
loss_corr_bw: false
loss_recon: true
initialize_from: null
initialization_file_name: model_best.pt
c_dim: 512
z_dim: 0
use_camera: False
training:
out_dir: out/00
model_selection_metric: iou
model_selection_mode: maximize
n_eval_points: 5000
batch_size: 16
batch_size_vis: 1
batch_size_val: 1
print_every: 5
visualize_every: 999999999
checkpoint_every: 200
validate_every: 2000
backup_every: 100000
eval_sample: true
learning_rate: 0.0001
test:
threshold: 0.3
eval_mesh: true
eval_pointcloud: false
project_to_final_mesh: false
eval_mesh_correspondences: true
eval_mesh_iou: true
eval_pointcloud_correspondences: true
eval_only_end_time_steps: false
model_file: model_best.pt
generation:
generate_pointcloud: false
generate_mesh: true
resolution_0: 32
upsampling_steps: 2
refinement_step: 0
simplify_nfaces: null
padding: 0.1
vis_n_outputs: 20
n_time_steps: 17
mesh_color: true
interpolate: false
only_end_time_points: false
fix_z: false
fix_zt: False
shuffle_generation: true
rand_seed: 12345
batch_size: 1000000
generation_dir: generation
use_sampling: false
copy_input: false
7 changes: 7 additions & 0 deletions configs/demo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
inherit_from: configs/pointcloud/oflow_w_correspond_pretrained.yaml
data:
classes: ['Demo']
test_split: null
offset_sequence: 0
training:
out_dir: out/demo
31 changes: 31 additions & 0 deletions configs/generative/oflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
method: oflow
data:
input_pointcloud_n: 4000
input_pointcloud_noise: 0.
train_split: train_generative
test_split: train_generative
model:
encoder_latent: pointnet
encoder_latent_temporal: pointnet
encoder_temporal: null
encoder: null
decoder: simple
c_dim: 0
z_dim: 128
encoder_latent_temporal_kwargs:
hidden_dim: 128
dim: 51
encoder_latent_kwargs:
hidden_dim: 128
dim: 3
velocity_field_kwargs:
hidden_size: 128
n_blocks: 3
loss_corr: true
training:
out_dir: out/generative/oflow
n_eval_points: 10000
generation:
use_sampling: true
fix_z: true
fix_zt: false
33 changes: 33 additions & 0 deletions configs/generative/oflow_pretrained.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
method: oflow
data:
input_pointcloud_n: 4000
input_pointcloud_noise: 0.
train_split: train_generative
test_split: train_generative
model:
encoder_latent: pointnet
encoder_latent_temporal: pointnet
encoder_temporal: null
encoder: null
decoder: simple
c_dim: 0
z_dim: 128
encoder_latent_temporal_kwargs:
hidden_dim: 128
dim: 51
encoder_latent_kwargs:
hidden_dim: 128
dim: 3
velocity_field_kwargs:
hidden_size: 128
n_blocks: 3
loss_corr: true
training:
out_dir: out/generative/oflow_pretrained
n_eval_points: 10000
generation:
use_sampling: true
fix_z: true
fix_zt: false
test:
model_file: https://s3.eu-central-1.amazonaws.com/avg-projects/occupancy_flow/models/generative/oflow_model-187b81a1.pt
12 changes: 12 additions & 0 deletions configs/img/oflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
method: oflow
data:
input_type: img_seq
model:
encoder_temporal: conv_3D
encoder: resnet18
decoder_kwargs:
hidden_size: 256
legacy: true
c_dim: 256
training:
out_dir: out/img/oflow
13 changes: 13 additions & 0 deletions configs/img/oflow_w_correspond.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
method: oflow
data:
input_type: img_seq
model:
encoder_temporal: conv_3D
encoder: resnet18
loss_corr: true
decoder_kwargs:
hidden_size: 256
legacy: true
c_dim: 256
training:
out_dir: out/img/oflow_w_correspond
Loading

0 comments on commit c002add

Please sign in to comment.