This repository contains the code for our fast polygonal building extraction from overhead images pipeline.

Overview

Polygonal Building Segmentation by Frame Field Learning

We add a frame field output to an image segmentation neural network to improve segmentation quality and provide structural information for the subsequent polygonization step.


Figure 1: Close-up of our additional frame field output on a test image.



Figure 2: Given an overhead image, the model outputs an edge mask, an interior mask, and a frame field for buildings. The total loss includes terms that align the masks and frame field to ground truth data as well as regularizers to enforce smoothness of the frame field and consistency between the outputs.



Figure 3: Given classification maps and a frame field as input, we optimize skeleton polylines to align to the frame field using an Active Skeleton Model (ASM) and detect corners using the frame field, simplifying non-corner vertices.

This repository contains the official code for the paper:

Polygonal Building Segmentation by Frame Field Learning
Nicolas Girard, Dmitriy Smirnov, Justin Solomon, Yuliya Tarabalka
Pre-print
[paper, video]

Whose short version has been published as:

Regularized Building Segmentation by Frame Field Learning
Nicolas Girard, Dmitriy Smirnov, Justin Solomon, Yuliya Tarabalka
IGARSS 2020

Setup

Git submodules

This project uses various git submodules that should be cloned too.

To clone a repository including its submodules execute:

git clone --recursive --jobs 8 <URL to Git repo>

If you already have cloned the repository and now want to load it’s submodules execute:

git submodule update --init --recursive --jobs 8

or:

git submodule update --recursive

For more about explanations about using submodules and git, see SUBMODULES.md.

Docker

The easiest way to setup environment is to use the Docker image provided in the docker (see README inside the folder).

Once the docker container is built and launched, execute the setup.sh script inside to install required packages.

The environment in the container is now ready for use.

Conda environment

Alternatively you can install all dependencies in a conda environment. I provide my environment specifications in the environment.yml which you can use to create your environment own with:

conda env create -f environment.yml

Data

Several datasets are used in this work. We typically put all datasets in a "data" folder which we link to the "/data" folder in the container (with the -v argument when running the container). Each dataset has it's own sub-folder, usually named with a short version of that dataset's name. Each dataset sub-folder should have a "raw" folder inside containing all the original folders and files fo the datset. When pre-processing data, "processed" folders will be created alongside the "raw" folder.

For example, here is an example working file structure inside the container:

/data 
|-- AerialImageDataset
     |-- raw
         |-- train
         |   |-- aligned_gt_polygons_2
         |   |-- gt
         |   |-- gt_polygonized
         |   |-- images
         `-- test
             |-- aligned_gt_polygons_2
             |-- images
`-- mapping_challenge_dataset
     |-- raw
         |-- train
         |   |-- images
         |   |-- annotation.json
         |   `-- annotation-small.json
         `-- val
              `-- ...

If however you would like to use a different folder for the datasets (for example while not using Docker), you can change the path to datasets in config files. You can modify the "data_dir_candidates" list in the config to only include your path. The training script checks this list of paths one at a time and picks the first one that exists. It then appends the "data_root_partial_dirpath" directory to get to the dataset.

You can find some of the data we used in this shared "data" folder: https://drive.google.com/drive/folders/19yqseUsggPEwLFTBl04CmGmzCZAIOYhy?usp=sharing.

Inria Aerial Image Labeling Dataset

Link to the dataset: https://project.inria.fr/aerialimagelabeling/

For the Inria dataset, the original ground truth is just a collection of raster masks. As our method requires annotations to be polygons in order to compute the ground truth angle for the frame field, we made 2 versions of the dataset:

The Inria OSM dataset has aligned annotations pulled from OpenStreetMap.

The Inria Polygonized dataset has polygon annotations obtained from using our frame field polygonization algorithm on the original raster masks. This was done by running the polygonize_mask.py script like so: python polygonize_mask.py --run_name inria_dataset_osm_mask_only.unet16 --filepath ~/data/AerialImageDataset/raw/train/gt/*.tif

You can find this new ground truth for both cases in the shared "data" folder (https://drive.google.com/drive/folders/19yqseUsggPEwLFTBl04CmGmzCZAIOYhy?usp=sharing.).

Running the main.py script

Execute main.py script to train a model, test a model or use a model on your own image. See the help of the main script with:

python main.py --help

The script can be launched on multiple GPUs for multi-GPU training and evaluation. Simply set the --gpus argument to the number of gpus you want to use. However, for the first launch of the script on a particular dataset (when it will pre-process the data), it is best to leave it at 1 as I did not implement multi-GPU synchronization when pre-processing datasets.

An example use is for training a model with a certain config file, like so: python main.py --config configs/config.mapping_dataset.unet_resnet101_pretrained which will train the Unet-Resnet101 on the CrowdAI Mapping Challenge dataset. The batch size can be adjusted like so: python main.py --config configs/config.mapping_dataset.unet_resnet101_pretrained -b <new batch size>

When training is done, the script can be launched in eval mode, to evaluate the trained model: python main.py --config configs/config.mapping_dataset.unet_resnet101_pretrained --mode eval. Depending on the eval parameters of the config file, running this will output results on the test dataset.

Finally, if you wish to compute AP and AR metrics with the COCO API, you can run: python main.py --config configs/config.mapping_dataset.unet_resnet101_pretrained --mode eval_coco.

Launch inference on one image

Make sure the run folder has the correct structure:

Polygonization-by-Frame-Field-Learning
|-- frame_field_learning
|   |-- runs
|   |   |-- <run_name> | <yyyy-mm-dd hh:mm:ss>
|   |   `-- ...
|   |-- inference.py
|   `-- ...
|-- main.py
|-- README.md (this file)
`-- ...

Execute the [main.py] script like so (filling values for arguments run_name and in_filepath): python main.py --run_name <run_name> --in_filepath <your_image_filepath>

The outputs will be saved next to the input image

Download trained models

We provide already-trained models so you can run inference right away. Download here: https://drive.google.com/drive/folders/1poTQbpCz12ra22CsucF_hd_8dSQ1T3eT?usp=sharing. Each model was trained in a "run", whose folder (named with the format <run_name> | <yyyy-mm-dd hh:mm:ss>) you can download at the provided link. You should then place those runs in a folder named "runs" inside the "frame_field_learning" folder like so:

Polygonization-by-Frame-Field-Learning
|-- frame_field_learning
|   |-- runs
|   |   |-- inria_dataset_polygonized.unet_resnet101_pretrained.leaderboard | 2020-06-02 07:57:31
|   |   |-- mapping_dataset.unet_resnet101_pretrained.field_off.train_val | 2020-09-07 11:54:48
|   |   |-- mapping_dataset.unet_resnet101_pretrained.train_val | 2020-09-07 11:28:51
|   |   `-- ...
|   |-- inference.py
|   `-- ...
|-- main.py
|-- README.md (this file)
`-- ...

Because Google Drive reformats folder names, you have to rename the run folders as above.

Cite:

If you use this code for your own research, please cite

@InProceedings{Girard_2020_IGARSS,
  title = {{Regularized Building Segmentation by Frame Field Learning}},
  author = {Girard, Nicolas and Smirnov, Dmitriy and Solomon, Justin and Tarabalka, Yuliya},
  booktitle = {IEEE International Geoscience and Remote Sensing Symposium (IGARSS)},
  ADDRESS = {Waikoloa, Hawaii},
  year = {2020},
  month = Jul,
}

@misc{girard2020polygonal,
    title={Polygonal Building Segmentation by Frame Field Learning},
    author={Nicolas Girard and Dmitriy Smirnov and Justin Solomon and Yuliya Tarabalka},
    year={2020},
    eprint={2004.14875},
    archivePrefix={arXiv},
    primaryClass={cs.CV}
}
Comments
  • Polygonize mask - Inria dataset

    Polygonize mask - Inria dataset

    From your answer of the "training flowline" issue, I have understood the following,

    1. Masks in .png format can be converted to .geojson files and it can be used for training
    2. polygonize_mask.py script can be used to convert images masks to polygon masks in .geojson format

    When I run polygonize_mask.py script, it asks for run_name to convert binary masks into polygon masks. Can you please provide trained weights to do this operation?

    opened by sarathsrk 19
  • Error in inference

    Error in inference

    While running inference, it shows error for the below mentioned two trained models, but it works well for inria model. Please help me to resolve this

    mapping_dataset.unet_resnet101_pretrained.train_val mapping_dataset.unet_resnet101_pretrained.field_off.train_val

    Traceback (most recent call last):
      File "main.py", line 374, in <module>
        main()
      File "main.py", line 364, in main
        launch_inference_from_filepath(args)
      File "main.py", line 175, in launch_inference_from_filepath
        inference_from_filepath(config, args.in_filepath, backbone)
      File "/app/Polygonization-by-Frame-Field-Learning/frame_field_learning/inference_from_filepath.py", line 45, in inference_from_filepath
        tile_data = inference.inference(config, model, sample, compute_polygonization=True)
      File "/app/Polygonization-by-Frame-Field-Learning/frame_field_learning/inference.py", line 28, in inference
        inference_no_patching(config, model, tile_data)
      File "/app/Polygonization-by-Frame-Field-Learning/frame_field_learning/inference.py", line 51, in inference_no_patching
        pred, batch = network_inference(config, model, batch)
      File "/app/Polygonization-by-Frame-Field-Learning/frame_field_learning/inference.py", line 17, in network_inference
        pred, batch = model(batch, tta=config["eval_params"]["test_time_augmentation"])
    KeyError: 'test_time_augmentation'
    
    opened by sarathsrk 8
  • distance transform

    distance transform

    hi, may i ask how to calculate the distance to the second nearest building? i'm not quite familiar with that, i know with cv2.distanceTransform we can calculate distance to the nearest building.

    opened by wangyi111 5
  • problem while using docker run

    problem while using docker run

    As instructed I created docker image, but when i run the image using the following command shows error

    docker run --rm -it --init --gpus 1 --ipc=host --network=host-e -v "./data:/data" lydorn/frame-field-learning

    Unable to find image 'frame-field-learning:latest' locally

    But when I run docker ps -a it shows the image

    opened by sarathsrk 4
  • Annotation for the frame field

    Annotation for the frame field

    I have the angles for each pixel as a .npy file to be used as groundtruth as mentioned in the paper.

    My question is: is this directly used in the network or is there a need to calculate frame field to be fed into the network? If so what should the format be?

    I would appreciate any kind of help. Thank you.

    opened by kriti115 2
  • question about weighted loss

    question about weighted loss

    Hi, i saw your paper and got something unclear: when you did the edge segmentation task, were you using dice loss + weighted cross entropy (2 classes: edge and background)? For the weighted BCE, were you using the pixel frequency of each class as the weights?

    opened by wangyi111 2
  • Hyperparameters for Training/evaluation

    Hyperparameters for Training/evaluation

    Hello, I have opened new thread to ask details about paramters, I will close that old issue. My full image size is 1024x1024, In "dataset_params" you configured it as "data_patch_size": 725, and "input_patch_size": 512, but the Inria dataset image resolution is 5000x5000. How did you give it as 725 & 512? Is it just to reduce GPU memory allocation?

    opened by sarathsrk 2
  • ERROR: frame_field_learning package is not installed

    ERROR: frame_field_learning package is not installed

    Even though the frame-field-learning package is installed successfully, the main.py does not execute as shown below.

    I would like to request some help in this matter. Thank you.

    error

    opened by kriti115 1
  • Training flowline

    Training flowline

    Could you please tell me the training procedure for Indria dataset from scratch? I have aerial images and corresponding masks in .png format right now.

    opened by sarathsrk 1
  • Error during run after halfway through training

    Error during run after halfway through training

    The configs for Inria Dataset runs halfway and creates .pt files for half of the image folders but stops abruptly with following errors.

    Any kind of help if someone has this issue would be appreciated. Thank you.

    Current_half_patch_then_error

    Current_half_patch_then_error_next

    opened by kriti115 0
  • eval_coco error ValueError: No Shapely geometry can be created from null value

    eval_coco error ValueError: No Shapely geometry can be created from null value

    Traceback (most recent call last): File "/opt/conda/lib/python3.7/site-packages/multiprocess/pool.py", line 121, in worker result = (True, func(*args, **kwds)) File "/home/fei.qi/frame_field_learning/frame_field_attention_learning/eval_coco.py", line 156, in compute_contour_metrics fixed_gt_polygons = polygon_utils.fix_polygons(gt_polygons, buffer=0.0001) # Buffer adds vertices but is needed to repair some geometries File "/home/fei.qi/frame_field_learning/frame_field_attention_learning/lydorn_utils/polygon_utils.py", line 1645, in fix_polygons polygons_geom = shapely.ops.unary_union(polygons) # Fix overlapping polygons File "/opt/conda/lib/python3.7/site-packages/shapely/ops.py", line 161, in unary_union return geom_factory(lgeos.methods'unary_union') File "/opt/conda/lib/python3.7/site-packages/shapely/geometry/base.py", line 73, in geom_factory raise ValueError("No Shapely geometry can be created from null value") ValueError: No Shapely geometry can be created from null value

    opened by qifei123 0
  • Bug in seg_coco

    Bug in seg_coco

    In frame_field_learning/save_utils.py line 236, I noticed that if I use the key "image_id" into the sample dictionary, it is invalid. Instead I replace it with "number" as a workaround.

    opened by schuegra 0
  • Running pretrained model issue

    Running pretrained model issue

    I've encountered a size mismatch issue when trying to run the author's pretrained model on a single image. Could someone who have successfully run the model share your environment.yml file and the running command? Lot of thanks! (The error screenshot is as follows.) 19ec4f6a-6049-45f0-b9ff-54ebf7ae41c7

    opened by codFish3 0
  • Several different classes

    Several different classes

    Greetings! Thanks for great work I would like to clarify, if I have a dataset with several different classes in it - how is it possible to modify your framework, so it can do segmentation and polygonization for all of them?

    opened by theVmagnificient 0
  • Questions for pretrained models

    Questions for pretrained models

    Hi,

    Thank you for sharing the outstanding work to the public, your contribution is worth to appreciate too much. When I try to use your shared pretrained weights to perform inference, I found a very interesting thing. The pretrained weights from "inria_dataset_polygonized.unet_resnet101_pretrained.leaderboard | 2020-06-02 07:57:31" could produce more regularized building footprints (see figure below), but other three pretrained models such as “mapping_dataset.unet_resnet101_pretrained.train_val | 2020-09-07 11:28:51” cannot do the same thing. So I'm wondering that if you perform any regurlization operations when you train the model "inria_dataset_polygonized.unet_resnet101_pretrained.leaderboard | 2020-06-02 07:57:31" . Why the building boundaries look so regular? image

    Thanks

    opened by YJ-He 0
  • Error during Model Evaluation: ValueError: need at least one array to concatenate

    Error during Model Evaluation: ValueError: need at least one array to concatenate

    After training on INRIA dataset using the polygonized_unetresnet_leaderboard run, I tried to evaluate the model using --mode eval on the same config. The error was faced in the tensorpoly.py file inside the transforms folder.

    File "Polygonization-by-Frame-Field-Learning/pytorch_lydorn/torch_lydorn/torchvision/transforms/tensorpoly.py", line 78, in polygons_to_tensorpoly pos = np.concatenate(polygon_list, axis=0) File "<array_function internals>", line 180, in concatenate ValueError: need at least one array to concatenate

    Here, the polygon list is empty, there are no polygons there so it is not finding any arrays to concatenate. It is in the polygon_to_tensorpoly function and the author has mentioned in the comments in Line 50 # TODO: If there are no polygons but it has not been implemented. I would like to ask if anyone had come across this problem. I would glad to learn more about it.

    Thank you.

    opened by kriti115 0
Owner
Nicolas Girard
Research engineer at LuxCarta with a PhD in deep learning applied to remote sensing.
Nicolas Girard
Deep Ensembling with No Overhead for either Training or Testing: The All-Round Blessings of Dynamic Sparsity

[ICLR 2022] Deep Ensembling with No Overhead for either Training or Testing: The All-Round Blessings of Dynamic Sparsity by Shiwei Liu, Tianlong Chen, Zahra Atashgahi, Xiaohan Chen, Ghada Sokar, Elena Mocanu, Mykola Pechenizkiy, Zhangyang Wang, Decebal Constantin Mocanu

VITA 18 Dec 31, 2022
This repository contains the source code of our work on designing efficient CNNs for computer vision

Efficient networks for Computer Vision This repo contains source code of our work on designing efficient networks for different computer vision tasks:

Sachin Mehta 386 Nov 26, 2022
This repository contains the entire code for our work "Two-Timescale End-to-End Learning for Channel Acquisition and Hybrid Precoding"

Two-Timescale-DNN Two-Timescale End-to-End Learning for Channel Acquisition and Hybrid Precoding This repository contains the entire code for our work

QiyuHu 3 Mar 7, 2022
buildseg is a building extraction plugin of QGIS based on PaddlePaddle.

buildseg buildseg is a building extraction plugin of QGIS based on PaddlePaddle. TODO Extract building on 512x512 remote sensing images. Extract build

Yizhou Chen 11 Sep 26, 2022
buildseg is a building extraction plugin of QGIS based on PaddlePaddle.

buildseg buildseg is a Building Extraction plugin for QGIS based on PaddlePaddle. How to use Download and install QGIS and clone the repo : git clone

null 39 Dec 9, 2022
API for RL algorithm design & testing of BCA (Building Control Agent) HVAC on EnergyPlus building energy simulator by wrapping their EMS Python API

RL - EmsPy (work In Progress...) The EmsPy Python package was made to facilitate Reinforcement Learning (RL) algorithm research for developing and tes

null 20 Jan 5, 2023
Evaluation Pipeline for our ECCV2020: Journey Towards Tiny Perceptual Super-Resolution.

Journey Towards Tiny Perceptual Super-Resolution Test code for our ECCV2020 paper: https://arxiv.org/abs/2007.04356 Our x4 upscaling pre-trained model

Royson 6 Mar 30, 2022
Implementation for our AAAI2021 paper (Entity Structure Within and Throughout: Modeling Mention Dependencies for Document-Level Relation Extraction).

SSAN Introduction This is the pytorch implementation of the SSAN model (see our AAAI2021 paper: Entity Structure Within and Throughout: Modeling Menti

benfeng 69 Nov 15, 2022
Sign Language is detected in realtime using video sequences. Our approach involves MediaPipe Holistic for keypoints extraction and LSTM Model for prediction.

RealTime Sign Language Detection using Action Recognition Approach Real-Time Sign Language is commonly predicted using models whose architecture consi

Rishikesh S 15 Aug 20, 2022
This repo contains the official code of our work SAM-SLR which won the CVPR 2021 Challenge on Large Scale Signer Independent Isolated Sign Language Recognition.

Skeleton Aware Multi-modal Sign Language Recognition By Songyao Jiang, Bin Sun, Lichen Wang, Yue Bai, Kunpeng Li and Yun Fu. Smile Lab @ Northeastern

Isen (Songyao Jiang) 128 Dec 8, 2022
The repository contain code for building compiler using puthon.

Building Compiler This is a python implementation of JamieBuild's "Super Tiny Compiler" Overview JamieBuilds developed a wonderfully educative compile

Shyam Das Shrestha 1 Nov 21, 2021
Cascading Feature Extraction for Fast Point Cloud Registration (BMVC 2021)

Cascading Feature Extraction for Fast Point Cloud Registration This repository contains the source code for the paper [Arxive link comming soon]. Meth

null 7 May 26, 2022
Official Pytorch Implementation of Adversarial Instance Augmentation for Building Change Detection in Remote Sensing Images.

IAug_CDNet Official Implementation of Adversarial Instance Augmentation for Building Change Detection in Remote Sensing Images. Overview We propose a

null 53 Dec 2, 2022
Official code for our ICCV paper: "From Continuity to Editability: Inverting GANs with Consecutive Images"

GANInversion_with_ConsecutiveImgs Official code for our ICCV paper: "From Continuity to Editability: Inverting GANs with Consecutive Images" https://a

QingyangXu 38 Dec 7, 2022
Official repository for "Action-Based Conversations Dataset: A Corpus for Building More In-Depth Task-Oriented Dialogue Systems"

Action-Based Conversations Dataset (ABCD) This respository contains the code and data for ABCD (Chen et al., 2021) Introduction Whereas existing goal-

ASAPP Research 49 Oct 9, 2022
This repository contains the code used for Predicting Patient Outcomes with Graph Representation Learning (https://arxiv.org/abs/2101.03940).

Predicting Patient Outcomes with Graph Representation Learning This repository contains the code used for Predicting Patient Outcomes with Graph Repre

Emma Rocheteau 76 Dec 22, 2022
An efficient and effective learning to rank algorithm by mining information across ranking candidates. This repository contains the tensorflow implementation of SERank model. The code is developed based on TF-Ranking.

SERank An efficient and effective learning to rank algorithm by mining information across ranking candidates. This repository contains the tensorflow

Zhihu 44 Oct 20, 2022
This repository contains PyTorch code for Robust Vision Transformers.

This repository contains PyTorch code for Robust Vision Transformers.

null 117 Dec 7, 2022