Home

Awesome

<div align="center"> <h2> STT: Building Extraction from Remote Sensing Images with Sparse Token Transformers </h2> </div> <br>

<br>

<div align="center"> <a href="https://kychen.me/STT"> <span style="font-size: 20px; ">Project Page</span> </a> &nbsp;&nbsp;&nbsp;&nbsp; <a href="https://www.mdpi.com/2072-4292/13/21/4441"> <span style="font-size: 20px; ">Paper</span> </a> &nbsp;&nbsp;&nbsp;&nbsp; <a href="https://huggingface.co/spaces/KyanChen/BuildingExtraction"> <span style="font-size: 20px; ">HFSpace</span> </a> </div> <br> <br>

GitHub stars license Hugging Face Spaces

<br> <br> <div align="center">

English | 简体中文

</div>

Introduction

This repository is the code implementation of the paper STT: Building Extraction from Remote Sensing Images with Sparse Token Transformers.

This branch has been tested with PyTorch 2.x and CUDA 12.1, supports Python 3.7+, and is compatible with most CUDA versions.

If you find this project helpful, please give us a star ⭐️. Your support is our biggest motivation.

Updates

🌟 2022.10.23 Released the STT project code.

🌟 2022.10.25 Open-sourced the pre-trained models of WHU and INRIA datasets, you can find them on Hugging Face Spaces.

🌟 2024.02.28 Reorganized the project.

Table of Contents

Installation

Dependencies

Environment Installation

We recommend using Miniconda for installation. The following commands will create a virtual environment named stt and install PyTorch.

Note: If you are familiar with PyTorch and have already installed it, you can skip to the next section. Otherwise, you can follow the steps below.

<details>

Step 0: Install Miniconda.

Step 1: Create a virtual environment named stt and activate it.

conda create -n stt python=3.10 -y
conda activate stt

Step 2: Install PyTorch2.1.x.

Linux/Windows:

pip install torch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 --index-url https://download.pytorch.org/whl/cu121

Or

conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia

Step 4: Install other dependencies.

pip install -U pandas opencv-python tqdm scikit-image einops matplotlib
</details>

Install STT

Download or clone the STT repository.

git clone git@github.com:KyanChen/STT.git
cd STT

Dataset Preparation

<details>

WHU Building Extraction Dataset

Data Download

Organization

You can also choose other sources to download the data, but you need to organize the dataset in the following format:

${DATASET_ROOT} # Dataset root directory, for example: /home/username/data/WHU
├── train
│   ├── img
│   └── label
├── val
│   ├── img
│   └── label
└── test
    ├── img
    └── label

Note: In the project folder, we provide a folder named Data, which contains an example of the organization of the dataset.

INRIA Building Extraction Dataset

Data Download

Organization

You can also choose other sources to download the data, but you need to organize the dataset in the above format.

Other Datasets

If you want to use other datasets, you can refer to the above method to prepare the dataset.

Dataset Configuration

</details>

STT Model Training

Train File and Main Parameter Parsing

We provide the training script Train.py. Below we provide an analysis of some of the main parameters.

<details>

Parameter Parsing

</details>

Single Card Training

CUDA_VISIBLE_DEVICES=0 python Train.py  # 0 is the GPU number used

Multi-card Training

CUDA_VISIBLE_DEVICES=0,1,2,3 python Train.py  # 0,1,2,3 are the GPU numbers used

STT Model Testing

Single Card Testing

We provide the training script Test.py. You need to modify load_checkpoint_path in line47 of Test.py to the checkpoint file you want to use.

CUDA_VISIBLE_DEVICES=0 python Test.py  # 0 is the GPU number used

Multi-card Testing

CUDA_VISIBLE_DEVICES=0,1,2,3 python Test.py  # 0,1,2,3 are the GPU numbers used

Note: The output results will be saved in log_path.

Citation

If you use the code or performance benchmarks of this project in your research, please refer to the following bibtex to cite TTP.

@Article{rs13214441,
AUTHOR = {Chen, Keyan and Zou, Zhengxia and Shi, Zhenwei},
TITLE = {Building Extraction from Remote Sensing Images with Sparse Token Transformers},
JOURNAL = {Remote Sensing},
VOLUME = {13},
YEAR = {2021},
NUMBER = {21},
ARTICLE-NUMBER = {4441},
URL = {https://www.mdpi.com/2072-4292/13/21/4441},
ISSN = {2072-4292},
DOI = {10.3390/rs13214441}
}

License

This project is licensed under the Apache 2.0 License.

Contact Us

If you have any other questions❓, please feel free to contact us 👬