HorizonNet
This is the implementation of our CVPR’19 "
HorizonNet: Learning Room Layout with 1D Representation and Pano Stretch Data Augmentation" (project page).

Update
Feature
This repo is a pure python implementation that you can:
- Inference on your images to get cuboid or general shaped room layout
- 3D layout viewer
- Correct rotation pose to ensure manhattan alignment
- Pano stretch augmentation copy and paste to apply on your own task
- Quantitative evaluatation of 2D IoU, 3D IoU, Corner Error, Pixel Error of cuboid/general shape
- Your own dataset preparation and training
Method overview

Installation
Pytorch installation is machine dependent, please install the correct version for your machine. The tested version is pytorch 1.8.1 with python 3.7.6.
Dependencies (click to expand)
- numpy
- scipy
- sklearn
- Pillow
- tqdm
- tensorboardX
- opencv-python>=3.1 (for pre-processing)
- pylsd-nova
- open3d>=0.7 (for layout 3D viewer)
- shapely
Download
Dataset
- PanoContext/Stanford2D3D Dataset
- Structured3D Dataset
- See the tutorial to prepare training/validation/testing for HorizonNet.
- Zillow Indoor Dataset
- See the tutorial to prepare training/validation/testing for HorizonNet.
Pretrained Models
Please find the pre-trained weights here. By downloading the weights, you agree with the license and term of usage of the training datasets.
resnet50_rnn__panos2d3d.pth
- Trained on PanoContext/Stanford2d3d 817 pano images.
resnet50_rnn__st3d.pth
- Trained on Structured3D 18362 pano images
- Data setup: original furniture and lighting.
resnet50_rnn__mp3d.pth
- Trained on Matterport3D datasets.
resnet50_rnn__zind.pth
- Trained on Zillow Indoor 20077 pano images.
- Data setup:
layout_visible, is_primary, is_inside, is_ceiling_flat.
CLI downloading example:
huggingface-cli download sunset1995/HorizonNet resnet50_rnn__panos2d3d.pth --local-dir ./ckpt
Python script downloading example:
from huggingface_hub import hf_hub_download
file_path = hf_hub_download(
repo_id="sunset1995/HorizonNet",
filename="resnet50_rnn__panos2d3d.pth",
local_dir="./ckpt")
Inference on your images
In below explaination, I will use assets/demo.png for example.
(modified from PanoContext dataset)
1. Pre-processing (Align camera rotation pose)
2. Estimating layout with HorizonNet
3. Layout 3D Viewer
Your own dataset
See tutorial on how to prepare it.
Training
To train on a dataset, see python train.py -h for detailed options explaination.
Example:
python train.py --id resnet50_rnn
- Important arguments:
--id required. experiment id to name checkpoints and logs
--ckpt folder to output checkpoints (default: ./ckpt)
--logs folder to logging (default: ./logs)
--pth finetune mode if given. path to load saved checkpoint.
--backbone backbone of the network (default: resnet50)
- other options:
{resnet18,resnet34,resnet50,resnet101,resnet152,resnext50_32x4d,resnext101_32x8d,densenet121,densenet169,densenet161,densenet201}
--no_rnn whether to remove rnn (default: False)
--train_root_dir root directory to training dataset. (default: data/layoutnet_dataset/train)
--valid_root_dir root directory to validation dataset. (default: data/layoutnet_dataset/valid/)
- If giveng, the epoch with best 3DIoU on validation set will be saved as
{ckpt}/{id}/best_valid.pth
--batch_size_train training mini-batch size (default: 4)
--epochs epochs to train (default: 300)
--lr learning rate (default: 0.0001)
--device set CUDA enabled device using device id (not to be used if multi_gpu is used)
--multi_gpu enable parallel computing on all available GPUs
Quantitative Evaluation - Cuboid Layout
To evaluate on PanoContext/Stanford2d3d dataset, first running the cuboid trained model for all testing images:
python inference.py --pth ckpt/resnet50_rnn__panos2d3d.pth --img_glob "data/layoutnet_dataset/test/img/*" --output_dir output/panos2d3d/resnet50_rnn/ --force_cuboid
--img_glob shell-style wildcards for all testing images.
--output_dir path to the directory to dump results.
--force_cuboid enfoce output cuboid layout (4 walls) or the PE and CE can’t be evaluated.
To get the quantitative result:
python eval_cuboid.py --dt_glob "output/panos2d3d/resnet50_rnn/*json" --gt_glob "data/layoutnet_dataset/test/label_cor/*txt"
--dt_glob shell-style wildcards for all the model estimation.
--gt_glob shell-style wildcards for all the ground truth.
If you want to:
- just evaluate PanoContext only
python eval_cuboid.py --dt_glob "output/panos2d3d/resnet50_rnn/*json" --gt_glob "data/layoutnet_dataset/test/label_cor/pano*txt"
- just evaluate Stanford2d3d only
python eval_cuboid.py --dt_glob "output/panos2d3d/resnet50_rnn/*json" --gt_glob "data/layoutnet_dataset/test/label_cor/camera*txt"
:clipboard: The quantitative result for the released resnet50_rnn__panos2d3d.pth is shown below:
| Testing Dataset |
3D IoU(%) |
Corner error(%) |
Pixel error(%) |
| PanoContext |
83.39 |
0.76 |
2.13 |
| Stanford2D3D |
84.09 |
0.63 |
2.06 |
| All |
83.87 |
0.67 |
2.08 |
Quantitative Evaluation - General Layout
TODO
- Faster pre-processing script (top-fron alignment) (maybe cython implementation or fernandez2018layouts)
Acknowledgement
- Credit of this repo is shared with ChiWeiHsiao.
- Thanks limchaos for the suggestion about the potential boost by fixing the non-expected behaviour of Pytorch dataloader. (See Issue#4)
Citation
@inproceedings{SunHSC19,
author = {Cheng Sun and
Chi{-}Wei Hsiao and
Min Sun and
Hwann{-}Tzong Chen},
title = {HorizonNet: Learning Room Layout With 1D Representation and Pano Stretch
Data Augmentation},
booktitle = {{IEEE} Conference on Computer Vision and Pattern Recognition, {CVPR}
2019, Long Beach, CA, USA, June 16-20, 2019},
pages = {1047--1056},
year = {2019},
}
评论