Learning to Reconstruct 3D Manhattan Wireframes from a Single Image

Overview

Learning to Reconstruct 3D Manhattan Wireframes From a Single Image

This repository contains the PyTorch implementation of the paper: Yichao Zhou, Haozhi Qi, Yuexiang Zhai, Qi Sun, Zhili Chen, Li-Yi Wei, Yi Ma. "Learning to Reconstruct 3D Manhattan Wireframes From a Single Image", ICCV 2019.

Introduction

The goal of this project is to explore the idea of reconstructing high-quality compact CAD-like 3D models from images. We propose a method to create accurate 3D wireframe representation from a single image by exploiting global structural regularities. Our method uses a convolutional neural network to simultaneously detect salient junctions and straight lines, as well as predict their 3D depth and vanishing points.

Qualitative Results

Input Predicted Input Predicted

Code Structure

Below is a quick overview of the function of key files.

########################### Data ###########################
data/
    SU3/                        # default folder for the scenecity 3D dataset
logs/                           # default folder for storing the output during training
########################### Code ###########################
config/                         # neural network hyper-parameters and configurations
wireframe/                      # module so you can "import wireframe" in scripts
train.py                        # script for training and evaluating the neural network
vectorize_u3d.py                # script for turning the 2.5D results into 3D wireframe

Reproducing Results

Installation

You are suggested to install miniconda before following executing the following commands.

git clone https://github.com/zhou13/shapeunity
cd shapeunity
conda create -y -n shapeunity
source activate shapeunity
conda install -y pyyaml docopt matplotlib scikit-image opencv tqdm
# Replace cudatoolkit=10.2 with your CUDA version: https://pytorch.org/get-started/
conda install -y pytorch cudatoolkit=10.2 -c pytorch
python -m pip install --upgrade vispy cvxpy
mkdir data logs

Downloading the Processed Datasets

Make sure curl is installed on your system and execute

cd data
../misc/gdrive-download.sh 1-TABJjT4-_yzE-iRD-n_yIJ9Kwzzkm7X SU3.zip
unzip SU3.zip
rm *.zip
cd ..

Note: If your downloaded zip file is corrupted, it is likely due to the restriction on the amount of data that can be downloaded from my account per day. In that case, you can try to download the pre-processed dataset manually from our Google Drive and proceed accordingly.

Downloading the Pre-trained Models

Execute the following command to download and unzip the pre-trained models.

cd logs
../misc/gdrive-download.sh 1AuE3yje7jTRne2KjiVdxAWo1UT03i16a pretrained-wireframe.zip
../misc/gdrive-download.sh 1YwPMbAHnxSA3BgiM5Q26mKSTjd46OYRo pretrained-vanishing-points.zip
unzip pretrained-wireframe.zip
unzip pretrained-vanishing-points.zip
rm *.zip
cd ..

Alternatively, you can download them at this Google Drive link and this Google Drive link, respectively.

Training (Optional)

If you want to train the model yourself rather than using the pre-trained models, execute the following commands to train the neural networks from scratch with four GPUs (specified by -d 0,1,2,3):

python ./train.py -d 0,1,2,3 --identifier baseline config/hourglass.yaml

The checkpoints and logs will be written to logs/ accordingly.

We note that vanishing points are only supported by the neural network under the git branch vanishing-points. You need to visit that part of the code with git checkout vanishing-points for training the network with the vanishing point branch.

Predicting the 2.5D Wireframe (Optional)

Execute the following command to evaluate the neural network on the validation split:

python train.py --eval -d 0 -i default --from logs/pretrained-wireframe/checkpoint_latest.pth.tar logs/pretrained-wireframe/config.yaml

This command should generate a new folder under the logs directory with results in the npz folders.

Vectorization & Visualization

To visualize the working examples of ShapeUnity, execute the following commands:

python vectorize_u3d.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000 57
python vectorize_u3d.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000 100
python vectorize_u3d.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000 109
python vectorize_u3d.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000 141
python vectorize_u3d.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000 299

Evaluation (Optional)

To quantitatively evaluate the wireframe quality of ShapeUnity, execute the following command:

python eval_2d3d_metric.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000

The details of the sAP-10 metric can be found in the paper LCNN.

Acknowledgement

This work is supported by a research grant from Sony Research. We thank Xili Dai for providing the sAP evaluation script for the project.

Citing ShapeUnity

If you find this project useful in your research, please consider citing:

@inproceedings{zhou2019learning,
  title={Learning to Reconstruct 3D Manhattan Wireframes From a Single Image},
  author={Zhou, Yichao and Qi, Haozhi and Zhai, Yuexiang and Sun, Qi and Chen, Zhili and Wei, Li-Yi and Ma, Yi},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  year={2019}
}
Comments
  • Calibration from vanishing points

    Calibration from vanishing points

    Hello,

    Thanks for your great work. I have a question about "Calibrating from three orthogonal vanishing points". This is a classic problem and it's not the main point of your paper, but I also read about it in your blog (https://yichaozhou.com/post/20190402vanishingpoint/) and my question is, the first element (S_{11}) of the matrix S = K^-T K^-1 is 1/f^2, which will be very small when f is sufficiently large, leading to numerical instability. Do you have any idea how to handle this? Thanks in advance.

    opened by kvuong2711 5
  • Installing dependencies

    Installing dependencies

    Hi, thanks for the great work.

    I want to test your code, however, I'm struggling to run it. I followed your notes on installation and downloaded the pre-trained models. I'm trying to execute the following command as said in the readme:

    python vectorize_u3d.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000 57
    

    First, I needed to figure out that I have to use python=3.7 instead of python=3.9 to resolve dependency conflicts during install.

    After installation seemed fine, I'm now getting following error:

    RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
    Traceback (most recent call last):
      File "vectorize_u3d.py", line 39, in <module>
        from wireframe.optimize import (
      File "/home/brakebein/PycharmProjects/shapeunity/wireframe/optimize.py", line 5, in <module>
        import cvxpy as cvx
    

    Wenn I decrease numpy version to 1.14, I get another error:

    ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
    Traceback (most recent call last):
      File "vectorize_u3d.py", line 39, in <module>
        from wireframe.optimize import (
      File "/home/brakebein/PycharmProjects/shapeunity/wireframe/optimize.py", line 5, in <module>
        import cvxpy as cvx
    

    And during install I already got following message:

    ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
    mkl-fft 1.2.0 requires numpy>=1.16, but you have numpy 1.14.6 which is incompatible.
    cvxpy 1.1.17 requires numpy>=1.15, but you have numpy 1.14.6 which is incompatible.
    

    However, increasing the numpy version to 1.16 and above throws the RuntimeError as said above.

    Despite of consulting Google, stackoverflow, etc., I could not resolve this issue. So, my question is: Which dependency versions are required to successfully run your code?

    opened by Brakebein 4
  • Segmentation fault (core dumped)

    Segmentation fault (core dumped)

    Any clue that I got Segmentation fault (coredumped) when excuting python vectorize_u3d.py logs/pretrained-wireframe/npz/003576000 --vpdir logs/pretrained-vanishing-points/npz/000096000 57 output: K: 2.6102218630949925 [[ 2.6102219 0. 0. 0. ] [ 0. 2.6102219 0. 0. ] [ 0. 0. 0. -1. ] [ 0. 0. 1. 0. ]] Segmentation fault (core dumped)

    question 
    opened by Blame4 4
  • Extract information directly from images?

    Extract information directly from images?

    Thank you very much for your research. I have downloaded your data and code, and try to run and debug it. I would like to ask how this project can extract lines, junctions, depth and vanishing points from only one image. I would appreciate it and hope you can give me some suggestions.

    opened by wdj1995 3
  • Unable to download dataset using given script

    Unable to download dataset using given script

    As titled. I followed steps in README and ran specified scripts, but it seems like the command of downloading SU3.zip doesn't work. Is it possible to update the script/command? Thank you!

    opened by sawsa307 3
  • dataset

    dataset

    Dear author,I want to ask how your training dataset is obtained through blender and sceneCity, such as how your 23000 images and jason files are obtained.Can you explain the specific steps or provide relevant codes?
    Thanks!

    opened by litaibai-yf 2
  • the function of

    the function of "def test(self, fname):"

    Thanks for your good job. I have a small problem in the file of train.py and trainer.py. Could you tell me how do I use this function which is "def test(self, fname):" in trainer.py. Thanks for your again.

    opened by edc-fansion 1
  • Test custom images with pre-trained model

    Test custom images with pre-trained model

    I have downloaded the pre-trained models and the huge dataset. Running the vectorization & visualization command with the SU3 dataset works. Now, I would like to test some of my own images with the pre-trained model to see how well it works. However, I'm not sure how to do that. How do I have to organize custom images and what command I have to run to evaluate the pre-trained model with these images?


    I also tried to run the prediction command with the SU3 dataset.

    python train.py --eval -d 0 -i default --from logs/pretrained-wireframe/checkpoint_latest.pth.tar logs/pretrained-wireframe/config.yaml
    

    However, I'm getting the error that it cannot use a CUDA device. My older Nvidia graphics card is not compatible with cudatoolkit 10.x. But it looks like that the pre-trained model has somewhere saying inside that it wants to run things on CUDA, and not fall back on CPU.

    Error log
    Traceback (most recent call last):
      File "train.py", line 204, in 
        main()
      File "train.py", line 124, in main
        checkpoint = torch.load(resume_from)
      File "/home/brakebein/anaconda3/envs/shapeunity/lib/python3.7/site-packages/torch/serialization.py", line 608, in load
        return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
      File "/home/brakebein/anaconda3/envs/shapeunity/lib/python3.7/site-packages/torch/serialization.py", line 787, in _legacy_load
        result = unpickler.load()
      File "/home/brakebein/anaconda3/envs/shapeunity/lib/python3.7/site-packages/torch/serialization.py", line 743, in persistent_load
        deserialized_objects[root_key] = restore_location(obj, location)
      File "/home/brakebein/anaconda3/envs/shapeunity/lib/python3.7/site-packages/torch/serialization.py", line 175, in default_restore_location
        result = fn(storage, location)
      File "/home/brakebein/anaconda3/envs/shapeunity/lib/python3.7/site-packages/torch/serialization.py", line 151, in _cuda_deserialize
        device = validate_cuda_device(location)
      File "/home/brakebein/anaconda3/envs/shapeunity/lib/python3.7/site-packages/torch/serialization.py", line 135, in validate_cuda_device
        raise RuntimeError('Attempting to deserialize object on a CUDA '
    RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

    So, my next thought was that I have to train the model by myself on the CPU. So, I need to run the training command:

    python ./train.py -d 0,1,2,3 --identifier baseline config/hourglass.yaml
    

    But there is the next error I cannot resolve. I tried it several times, but it always errors at the same image or data chunk (in the folder that has been created in logs, 3 npz files has been generated, and in viz, 000002_img.jpg has been generated but not the other files (see screenshot)).

    logs/.../viz/000000600/
    Error log
    progress | sum    | jmap   | jdir   | lmap   | joff   | ldir   | dpth   | jdep   | speed
    Running validation...                                                                            Traceback (most recent call last):
      File "./train.py", line 204, in 
        main()
      File "./train.py", line 200, in main
        trainer.train()
      File "/media/brakebein/Daten4TB/projects/shapeunity/wireframe/trainer.py", line 260, in train
        self.train_epoch()
      File "/media/brakebein/Daten4TB/projects/shapeunity/wireframe/trainer.py", line 200, in train_epoch
        self.validate()
      File "/media/brakebein/Daten4TB/projects/shapeunity/wireframe/trainer.py", line 131, in validate
        self._plot_samples(i, index, H, target, f"{viz}/{index:06}")
      File "/media/brakebein/Daten4TB/projects/shapeunity/wireframe/trainer.py", line 225, in _plot_samples
        mask_target = target["jmap"][i].cpu()
    IndexError: index 2 is out of bounds for dimension 0 with size 2

    Of course, it would be better to avoid the training process. I just want to test some custom images on your pre-trained model, but it doesn't seem to be trivial. Any help is appreciated.

    opened by Brakebein 6
  • Landmark 3D Wireframe Dataset

    Landmark 3D Wireframe Dataset

    Hello, Zhou, thanks for your excellent work. I am now trying to reconstruct 3D wireframe from real-world images and therefore I think L3D dataset will be helpful. Would you please plan to release the L3D dataset?

    opened by Luo1Cheng 1
Owner
Yichao Zhou
Apple Inc. | Ph.D. at UC Berkeley
Yichao Zhou
A Planar RGB-D SLAM which utilizes Manhattan World structure to provide optimal camera pose trajectory while also providing a sparse reconstruction containing points, lines and planes, and a dense surfel-based reconstruction.

ManhattanSLAM Authors: Raza Yunus, Yanyan Li and Federico Tombari ManhattanSLAM is a real-time SLAM library for RGB-D cameras that computes the camera

null 117 Dec 28, 2022
Code for "Neural 3D Scene Reconstruction with the Manhattan-world Assumption" CVPR 2022 Oral

News 05/10/2022 To make the comparison on ScanNet easier, we provide all quantitative and qualitative results of baselines here, including COLMAP, COL

ZJU3DV 365 Dec 30, 2022
A study project using the AA-RMVSNet to reconstruct buildings from multiple images

3d-building-reconstruction This is part of a study project using the AA-RMVSNet to reconstruct buildings from multiple images. Introduction It is exci

null 17 Oct 17, 2022
Accurate 3D Face Reconstruction with Weakly-Supervised Learning: From Single Image to Image Set (CVPRW 2019). A PyTorch implementation.

Accurate 3D Face Reconstruction with Weakly-Supervised Learning: From Single Image to Image Set —— PyTorch implementation This is an unofficial offici

Sicheng Xu 833 Dec 28, 2022
Official implementation of "SinIR: Efficient General Image Manipulation with Single Image Reconstruction" (ICML 2021)

SinIR (Official Implementation) Requirements To install requirements: pip install -r requirements.txt We used Python 3.7.4 and f-strings which are in

null 47 Oct 11, 2022
Selective Wavelet Attention Learning for Single Image Deraining

SWAL Code for Paper "Selective Wavelet Attention Learning for Single Image Deraining" Prerequisites Python 3 PyTorch Models We provide the models trai

Bobo 9 Jun 17, 2022
Implementation of the paper: "SinGAN: Learning a Generative Model from a Single Natural Image"

SinGAN This is an unofficial implementation of SinGAN from someone who's been sitting right next to SinGAN's creator for almost five years. Please ref

null 35 Nov 10, 2022
Contrastive Learning for Compact Single Image Dehazing, CVPR2021

AECR-Net Contrastive Learning for Compact Single Image Dehazing, CVPR2021. Official Pytorch based implementation. Paper arxiv Pytorch Version TODO: mo

glassy 253 Jan 1, 2023
Code for 'Single Image 3D Shape Retrieval via Cross-Modal Instance and Category Contrastive Learning', ICCV 2021

CMIC-Retrieval Code for Single Image 3D Shape Retrieval via Cross-Modal Instance and Category Contrastive Learning. ICCV 2021. Introduction In this wo

null 42 Nov 17, 2022
Official pytorch implementation of the paper: "SinGAN: Learning a Generative Model from a Single Natural Image"

SinGAN Project | Arxiv | CVF | Supplementary materials | Talk (ICCV`19) Official pytorch implementation of the paper: "SinGAN: Learning a Generative M

Tamar Rott Shaham 3.2k Dec 25, 2022
PyTorch code for 'Efficient Single Image Super-Resolution Using Dual Path Connections with Multiple Scale Learning'

Efficient Single Image Super-Resolution Using Dual Path Connections with Multiple Scale Learning This repository is for EMSRDPN introduced in the foll

null 7 Feb 10, 2022
《Deep Single Portrait Image Relighting》(ICCV 2019)

Ratio Image Based Rendering for Deep Single-Image Portrait Relighting [Project Page] This is part of the Deep Portrait Relighting project. If you find

null 62 Dec 21, 2022
CoReNet is a technique for joint multi-object 3D reconstruction from a single RGB image.

CoReNet CoReNet is a technique for joint multi-object 3D reconstruction from a single RGB image. It produces coherent reconstructions, where all objec

Google Research 80 Dec 25, 2022
《Single Image Reflection Removal Beyond Linearity》(CVPR 2019)

Single-Image-Reflection-Removal-Beyond-Linearity Paper Single Image Reflection Removal Beyond Linearity. Qiang Wen, Yinjie Tan, Jing Qin, Wenxi Liu, G

Qiang Wen 51 Jun 24, 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
Aerial Single-View Depth Completion with Image-Guided Uncertainty Estimation (RA-L/ICRA 2020)

Aerial Depth Completion This work is described in the letter "Aerial Single-View Depth Completion with Image-Guided Uncertainty Estimation", by Lucas

ETHZ V4RL 70 Dec 22, 2022
PyTorch code for our ECCV 2020 paper "Single Image Super-Resolution via a Holistic Attention Network"

HAN PyTorch code for our ECCV 2020 paper "Single Image Super-Resolution via a Holistic Attention Network" This repository is for HAN introduced in the

五维空间 140 Nov 23, 2022
Code for generating a single image pretraining dataset

Single Image Pretraining of Visual Representations As shown in the paper A critical analysis of self-supervision, or what we can learn from a single i

Yuki M. Asano 12 Dec 19, 2022