Home

Awesome

UNICORN :unicorn:

<div align="center"> <h2> Share With Thy Neighbors:<br> Single-View Reconstruction by Cross-Instance Consistency <p></p>

<a href="https://www.tmonnier.com">Tom Monnier</a><a href="https://techmatt.github.io/">Matthew Fisher</a><a href="https://people.eecs.berkeley.edu/~efros/">Alexei A. Efros</a><a href="https://imagine.enpc.fr/~aubrym/">Mathieu Aubry</a>

<p></p>

<a href="https://www.tmonnier.com/UNICORN/"><img src="https://img.shields.io/badge/-Webpage-blue.svg?colorA=333&logo=html5" height=35em></a> <a href="https://arxiv.org/abs/2204.10310"><img src="https://img.shields.io/badge/-Paper-blue.svg?colorA=333&logo=arxiv" height=35em></a> <a href="https://www.tmonnier.com/UNICORN/demo"><img src="https://img.shields.io/badge/-Demo-blue.svg?colorA=333&logo=googlecolab" height=35em></a> <a href="https://www.tmonnier.com/UNICORN/ref.bib"><img src="https://img.shields.io/badge/-BibTeX-blue.svg?colorA=333&logo=latex" height=35em></a>

<p></p>

teaser.gif

</h2> </div>

Official PyTorch implementation of Share With Thy Neighbors: Single-View Reconstruction by Cross-Instance Consistency (ECCV 2022). Check out our webpage for video results!

This repository contains:

<details> <summary>If you find this code useful, don't forget to <b>star the repo :star:</b> and <b>cite the paper :point_down:</b></summary>
@inproceedings{monnier2022unicorn,
  title={{Share With Thy Neighbors: Single-View Reconstruction by Cross-Instance Consistency}},
  author={Monnier, Tom and Fisher, Matthew and Efros, Alexei A and Aubry, Mathieu},
  booktitle={{ECCV}},
  year={2022},
}
</details> <details> <summary><b>Major code updates :clipboard:</b></summary> </details>

Installation :construction_worker:

1. Create conda environment :wrench:

conda env create -f environment.yml
conda activate unicorn
<details> <summary><b>Optional visualization :chart_with_downwards_trend:</b></summary> Some monitoring routines are implemented, you can use them by specifying your visdom port in the config file. You will need to install visdom from source beforehand:
git clone https://github.com/facebookresearch/visdom
cd visdom && pip install -e .
</details>

2. Download datasets :arrow_down:

bash scripts/download_data.sh

This command will download one of the following datasets:

3. Download pretrained models :arrow_down:

bash scripts/download_model.sh

We provide a small (200Mo) and a big (600Mo) version for each pretrained model (see training section for details). The command will download one of the following models:

<details> <summary><b>Important notes :page_with_curl:</b></summary>
  1. :exclamation:<b>These small models correspond to an old version of the code</b>, with in particular less training iterations. We release them for retrocompatibility and completeness, retrain from scratch for a thorough comparison.
  2. it may happen that gdown hangs, if so you can download them manually with the gdrive links and move them to the models folder.
</details>

How to use :rocket:

1. Demo - 3D reconstruction of car images :oncoming_automobile:

example_car.png example_rec.gif

You first need to download the car model (see above), then launch:

cuda=gpu_id model=car_big.pkl input=demo ./scripts/reconstruct.sh

where gpu_id is a target cuda device id, car_big.pkl corresponds to a pretrained model, demo is a folder containing the target images. Reconstruction results (.obj + gif) will be saved in a folder demo_rec.

We also provide an interactive demo Open in Colab to reconstruct cars from single images.

2. Train models from scratch :runner:

shapenet.gif

To launch a training from scratch, run:

cuda=gpu_id config=filename.yml tag=run_tag ./scripts/pipeline.sh

where gpu_id is a device id, filename.yml is a config in configs folder, run_tag is a tag for the experiment.

Results are saved at runs/${DATASET}/${DATE}_${run_tag} where DATASET is the dataset name specified in filename.yml and DATE is the current date in mmdd format.

<details> <summary><b>Configs and guidelines :high_brightness:</b></summary>

Available configs are:

:exclamation:NB: we advocate to always check the results after the first stage. In particular for cases like birds or horses, learning can fall into bad minima with bad prototypical shapes. If so, relaunch with a different seed.

</details> <details> <summary><b>Small vs big model :muscle:</b></summary>

We provide two configs to train a small and a big version of the model. Both versions give great results, the main benefit of the bigger model is slightly more detailed textures. The architecture differences are:

For faster experiments and prototyping, <b>we advocate the training of the small version</b>.

</details> <details> <summary><b>Computational cost :moneybag:</b></summary>

On a single GPU, the approximate training times are:

</details>

3. Reproduce our quantitative results :bar_chart:

A model is evaluated at the end of training. To evaluate a pretrained model (e.g. sn_big_airplane.pkl):

  1. move the model to a fake folder and rename it model.pkl (e.g. in runs/shapenet_nmr/airplane_big)
  2. point to the fake tag to resume from in the config (e.g. resume: airplane_big in airplane.yml)
  3. launch the training (and thus evaluation) with:
cuda=gpu_id config=sn_big/airplane.yml tag=airplane_big_eval ./scripts/pipeline.sh
<details> <summary><b>Chamfer-L1 scores on ShapeNet :triangular_ruler:</b></summary>
airplanebenchcabinetcarchairdisplaylampphoneriflesofaspeakertablevesselmean
0.1100.1590.1370.1680.2530.2200.5230.1270.0970.1920.2240.2430.1550.201
</details>

For CUB, the built-in evaluation included in the training pipeline is Mask-IoU. To evaluate PCK, run:

cuda=gpu_id tag=run_tag ./scripts/kp_eval.sh

4. Train on a custom dataset :crystal_ball:

If you want to learn a model for a custom object category, here are the key things you need to do:

  1. put your images in a custom_name folder inside the datasets folder
  2. edit the config file custom.yml (or custom_big.yml) in the configs folder: this includes changing the dataset name to custom_name and setting all training milestones
  3. launch training with:
cuda=gpu_id config=custom.yml tag=custom_run_tag ./scripts/pipeline.sh

Further information :books:

If you like this project, check out related works from our group: