Home

Awesome

Advancing Plain Vision Transformer Towards Remote Sensing Foundation Model

Di Wang, Qiming Zhang, Yufei Xu, Jing Zhang, Bo Du, Dacheng Tao and Liangpei Zhang

<p align="center"> <a href="#updates">Updates</a> | <a href="#introduction">Introduction</a> | <a href="#results-and-models">Results & Models</a> | <a href="#usage">Usage</a> | </p > <p align="left"> <a href="https://arxiv.org/abs/2208.03987"><img src="https://img.shields.io/badge/arXiv-Paper-<color>"></a> <a href="https://ieeexplore.ieee.org/document/9956816"><img src="https://img.shields.io/badge/TGRS-Paper-blue"></a> </p>

PWC PWC PWC PWC PWC PWC PWC PWC PWC PWC

Current applications

ViTAE: Please see ViTAE-Transformer;

VSA: Please see ViTAE-VSA;

Matting: Please see ViTAE-Transformer for matting;

Remote Sensing Pretraining: Please see ViTAE-Transformer-Remote-Sensing;

Updates

2023.10.18

RVSA won the highly cited paper!

<figure> <div align="center"> <img src=highlycited.png width="100%"> </div> </figure>

2023.03.18

ViTAE-B + RVSA helped us win the championship of "High Resolution SAR Image Coastal Aquaculture Farm Segmentation Track" in "The 5th Gaofen Challenge", Team: TNT. (第五届“中科星图杯”国际高分遥感图像解译大赛高分辨率SAR图像中近海养殖场分割赛道冠军)News

2023.01.18

Our models have been supported by LuoJiaNET, please refer to RS-Vision-Foundation-Models for more details.

2022.11.21

The early access is available! TGRS link

2022.11.15

The arXiv has been updated! arXiv link

2022.11.06

The paper has been accepted by IEEE TGRS!

2022.10.11

The codes, configs and training logs of segmentation in fintuning are released!

2022.10.09

The codes, configs and training logs of detection in fintuning are released!

2022.10.08

The codes of pretraining and classification in fintuning are released!

2022.09.19

The codes and training logs of the VSA have been released, which is the foundation of our RVSA.

Introduction

This repository contains codes, models and test results for the paper "Advancing Plain Vision Transformer Towards Remote Sensing Foundation Model".

We resort to plain vision transformers with about 100M and make the first attempt to propose large vision models customized for RS tasks and propose a new rotated varied-size window attention (RVSA) to substitute the original full attention to handle the large image size and objects of various orientations in RS images. The RVSA could significantly reduce the computational cost and memory footprint while learn better object representation by extracting rich context from the generated diverse windows.

<figure> <img src=Figs/framework.png> <figcaption align = "center"><b>Fig.1 - The pipeline of pretraining and finetuning. </b></figcaption> </figure>

<figure> <img src=Figs/vit_rvsa.png> <figcaption align = "center"><b>Fig.2 - The structure and block of the adopted plain vision transformer, and the proposed RVSA. </b></figcaption> </figure>

Results and Models

Pretraining

MillionAID

PretrainBackboneInput sizeParams (M)Pretrained model
MAEViT-B224 × 22486Weights
MAEViTAE-B224 × 22489Weights

Object Detection

DOTA-V1.0 Single-Scale

MethodPretrainBackboneLr schdmAPConfigLogModel
Oriented R-CNNMAEViT-B + RVSA1x78.75ConfigLogModel
Oriented R-CNNMAEViT-B + RVSA $^ \Diamond$1x78.61ConfigLogModel
Oriented R-CNNMAEViTAE-B + RVSA1x78.96ConfigLogModel
Oriented R-CNNMAEViTAE-B + RVSA $^ \Diamond$1x78.99ConfigLogModel

DOTA-V1.0 Multi-Scale

MethodPretrainBackboneLr schdmAPConfigLogModel
Oriented R-CNNMAEViT-B + RVSA1x81.01ConfigLogModel
Oriented R-CNNMAEViT-B + RVSA $^ \Diamond$1x80.80ConfigLogModel
Oriented R-CNNMAEViTAE-B + RVSA1x81.24ConfigLogModel
Oriented R-CNNMAEViTAE-B + RVSA $^ \Diamond$1x81.18ConfigLogModel

DIOR-R

MethodPretrainBackboneLr schdmAPConfigLogModel
Oriented R-CNNMAEViT-B + RVSA1x70.67ConfigLogModel
Oriented R-CNNMAEViT-B + RVSA $^ \Diamond$1x70.85ConfigLogModel
Oriented R-CNNMAEViTAE-B + RVSA1x70.95ConfigLogModel
Oriented R-CNNMAEViTAE-B + RVSA $^ \Diamond$1x71.05ConfigLogModel

Scene Classification

PretrainBackboneUCM-55AID-28AID-55NWPU-19NWPU-28
MAEViT-B + RVSA99.7096.9298.3393.7995.49
ModelModelModelModelModel
MAEViT-B + RVSA $^ \Diamond$99.5896.8698.4493.7495.45
ModelModelModelModelModel
MAEViTAE-B + RVSA99.5697.0398.4893.9395.69
ModelModelModelModelModel
MAEViTAE-B + RVSA $^ \Diamond$99.5097.0198.5093.9295.66
ModelModelModelModelModel

Semantic Segmentation

ISPRS Potsdam

MethodPretrainBackboneCrop sizeLr schdOAConfigLogModel
UperNetMAEViT-B + RVSA512 × 512160k90.60ConfigLogModel
UperNetMAEViT-B + RVSA $^ \Diamond$512 × 512160k90.77ConfigLogModel
UperNetMAEViTAE-B + RVSA512 × 512160k91.22ConfigLogModel
UperNetMAEViTAE-B + RVSA $^ \Diamond$512 × 512160k91.15ConfigLogModel

iSAID

MethodPretrainBackboneCrop sizeLr schdmIOUConfigLogModel
UperNetMAEViT-B + RVSA896 × 896160k63.76ConfigLogModel
UperNetMAEViT-B + RVSA $^ \Diamond$896 × 896160k63.85ConfigLogModel
UperNetMAEViTAE-B + RVSA896 × 896160k63.48ConfigLogModel
UperNetMAEViTAE-B + RVSA $^ \Diamond$896 × 896160k64.49ConfigLogModel

LoveDA

MethodPretrainBackboneCrop sizeLr schdmIOUConfigLogModel
UperNetMAEViT-B + RVSA512 × 512160k51.95ConfigLogModel
UperNetMAEViT-B + RVSA $^ \Diamond$512 × 512160k51.95ConfigLogModel
UperNetMAEViTAE-B + RVSA512 × 512160k52.26ConfigLogModel
UperNetMAEViTAE-B + RVSA $^ \Diamond$512 × 512160k52.44ConfigLogModel

Usage

Environment:

Pretraining & Finetuning-Classification

Pretraining (8 × A100 GPUs, 3~5 days)

  1. Preparing the MillionAID: Download the MillionAID. Here, we use previous train_labels.txt and valid_labels.txt of the RSP, which contain labels. However, since we conduct the unsupervised pretraining, the labels are not necessary. It is easy for users to record image names and revise corresponding codes MAEPretrain_SceneClassification/util/datasets.py/class MillionAIDDataset.

  2. Pretraining: take ViT-B as an example (batchsize: 2048=8*256)

python -m torch.distributed.launch --nproc_per_node 8 --master_port 10000 main_pretrain.py \
--dataset 'millionAID' --model 'mae_vit_base_patch16' \
--batch_size 256 --epochs 1600 --warmup_epochs 40 \
--input_size 224 --mask_ratio 0.75 \
--blr 1.5e-4  --weight_decay 0.05 --gpu_num 8 \
--output_dir '../mae-main/output/'

Note: Padding the convolutional kernel of PCM in the pretrained ViTAE-B with convertK1toK3.py for finetuning.

  1. Linear probe: an example of evaluating the pretrained ViT-B on UCM-55
CUDA_VISIBLE_DEVICES=0 python -m torch.distributed.launch --nproc_per_node 1 --master_port 10000 main_linprobe.py \
--dataset 'ucm' --model 'vit_base_patch16' \
--batch_size 256 --epochs 100 --warmup_epochs 10 \
--blr 1e-1  --weight_decay 0 --tag 0 \
--finetune '../mae-main/output/millionAID_224/1600_0.75_0.00015_0.05_2048/checkpoint-1599.pth'

Finetuning evaluation for pretraining & Finetuning-Classification

For instance, finetuning ViTAE-B + RVSA on NWPU-28

CUDA_VISIBLE_DEVICES=0 python -m torch.distributed.launch --nproc_per_node 1 --master_port 20000 main_finetune.py \
--dataset 'nwpu' --model 'vitae_nc_base_win_rvsa' --input_size 224 --postfix 'sota' \
--batch_size 64 --epochs 200 --warmup_epochs 5 \
--blr 1e-3  --weight_decay 0.05 --split 28 --tag 0 --exp_num 1 \
--finetune '../mae-main/output/mae_vitae_base_pretrn/millionAID_224/1600_0.75_0.00015_0.05_2048/checkpoint-1599-transform-no-average.pth'

Finetuning-Detection & Finetuning-Segmentation

Since we use OBBDetection and MMSegmenation to implement corresponding detection or segmentation models, we only provide necessary config and backbone files. The main frameworks are both in RSP

git clone https://github.com/ViTAE-Transformer/ViTAE-Transformer-Remote-Sensing.git

The installation and dataset preparation can separately refer OBBDetection-installation and MMSegmentation-installation

Then put these files into corresponding folders.

For convenience, we preserve the relative path for users to find files.

For example, put ./Object Detection/mmdet/models/backbones/vit_win_rvsa_v3_wsz7.py into ViTAE-Transformer-Remote-Sensing/Object Detection/mmdet/models/backbones

Training-Detection

First, cd ./Object Detection

Then, we provide several examples. For instance,

Training the Oriented-RCNN with ViT-B + RVSA on DOTA-V1.0 multi-scale detection dataset with 2 GPUs

CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 --master_port=40000 tools/train.py \
configs/obb/oriented_rcnn/vit_base_win/faster_rcnn_orpn_our_rsp_vit-base-win-rvsa_v3_wsz7_fpn_1x_dota10_ms_lr1e-4_ldr75_dpr15.py \
--launcher 'pytorch' --options 'find_unused_parameters'=True

Training the Oriented-RCNN with ViTAE-B + RVSA $^ \Diamond$ backbone on DIOR-R detection dataset with 1 GPU

CUDA_VISIBLE_DEVICES=0 python -m torch.distributed.launch --nproc_per_node=1 --master_port=40001 tools/train.py \
configs/obb/oriented_rcnn/vit_base_win/faster_rcnn_orpn_our_rsp_vitae-nc-base-win-rvsa_v3_kvdiff_wsz7_fpn_1x_dior_lr1e-4_ldr75_dpr10.py \
--launcher 'pytorch' --options 'find_unused_parameters'=True

Inference-Detection

Predicting the saving detection map using ViT-B + RVSA $^ \Diamond$ on DOTA-V1.0 scale-scale detection dataset

CUDA_VISIBLE_DEVICES=0 python tools/test.py configs/obb/oriented_rcnn/vit_base_win/faster_rcnn_orpn_our_rsp_vit-base-win-rvsa_v3_kvdiff_wsz7_fpn_1x_dota10_lr1e-4_ldr75_dpr15.py \
../OBBDetection/work_dirs/faster/faster_rcnn_orpn_our_rsp_vit-base-win-rvsa_v3_kvdiff_wsz7_fpn_1x_dota10_lr1e-4_ldr75_dpr15/latest.pth \
--format-only --show-dir work_dirs/save/faster/display/faster_rcnn_orpn_our_rsp_vit-base-win-rvsa_v3_kvdiff_wsz7_fpn_1x_dota10_lr1e-4_ldr75_dpr15 \
--options save_dir='work_dirs/save/faster/full_det/faster_rcnn_orpn_our_rsp_vit-base-win-rvsa_v3_kvdiff_wsz7_fpn_1x_dota10_lr1e-4_ldr75_dpr15' nproc=1

Evaluating the detection maps predicted by ViTAE-B + RVSA on DIOR-R dataset

CUDA_VISIBLE_DEVICES=0 python tools/test.py configs/obb/oriented_rcnn/vit_base_win/faster_rcnn_orpn_our_rsp_vitae-nc-base-win-rvsa_v3_wsz7_fpn_1x_dior_lr1e-4_ldr75_dpr10.py \
../OBBDetection/work_dirs/faster/faster_rcnn_orpn_our_rsp_vitae-nc-base-win-rvsa_v3_wsz7_fpn_1x_dior_lr1e-4_ldr75_dpr10/latest.pth \
--out work_dirs/save/faster/full_det/faster_rcnn_orpn_our_rsp_vitae-nc-base-win-rvsa_v3_wsz7_fpn_1x_dior_lr1e-4_ldr75_dpr10/det_result.pkl --eval 'mAP' \
--show-dir work_dirs/save/faster/display/faster_rcnn_orpn_our_rsp_vitae-nc-base-win-rvsa_v3_wsz7_fpn_1x_dior_lr1e-4_ldr75_dpr10

Note: the pathes of saved maps and outputs should be constructed before evaluating the DIOR-R testing set.

Training & Evaluation-Segmentation

cd ./Semantic Segmentation

Training and evaluation the UperNet with ViT-B + RVSA backbone on Potsdam dataset:

CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch --nproc_per_node=2 --master_port=30000 tools/train.py \
configs/vit_base_win/upernet_vit_base_win_rvsa_v3_512x512_160k_potsdam_rgb_dpr10_lr6e5_lrd90_ps16_class5_ignore5.py \
--launcher 'pytorch' --cfg-options 'find_unused_parameters'=True

Note: when training on the LoveDA, please add --no-validate

Inference the LoveDA dataset for online evaluation using the UperNet with ViTAE-B + RVSA $^ \Diamond$ backbone

CUDA_VISIBLE_DEVICES=0 python tools/test.py configs/vit_base_win/upernet_vitae_nc_base_rvsa_v3_kvdiff_wsz7_512x512_160k_loveda_dpr10_lr6e5_lrd90_ps16.py \
../mmsegmentation-master/work_dirs/upernet_vitae_nc_base_rvsa_v3_kvdiff_wsz7_512x512_160k_loveda_dpr10_lr6e5_lrd90_ps16/latest.pth \
--format-only --eval-options imgfile_prefix="work_dirs/display/upernet_vitae_nc_base_rvsa_v3_kvdiff_wsz7_512x512_160k_loveda_dpr10_lr6e5_lrd90_ps16/result" \
--show-dir work_dirs/display/upernet_vitae_nc_base_rvsa_v3_kvdiff_wsz7_512x512_160k_loveda_dpr10_lr6e5_lrd90_ps16/rgb

When finetuning with more than one GPU for detection or segmentation, please use nn.SyncBatchNorm in the NormalCell of ViTAE models.

Citation

If this repo is useful for your research, please consider citation

@ARTICLE{rvsa,
  author={Wang, Di and Zhang, Qiming and Xu, Yufei and Zhang, Jing and Du, Bo and Tao, Dacheng and Zhang, Liangpei},
  journal={IEEE Transactions on Geoscience and Remote Sensing}, 
  title={Advancing Plain Vision Transformer Toward Remote Sensing Foundation Model}, 
  year={2023},
  volume={61},
  number={},
  pages={1-15},
  doi={10.1109/TGRS.2022.3222818}
 }

@ARTICLE{rsp,
  author={Wang, Di and Zhang, Jing and Du, Bo and Xia, Gui-Song and Tao, Dacheng},
  journal={IEEE Transactions on Geoscience and Remote Sensing}, 
  title={An Empirical Study of Remote Sensing Pretraining}, 
  year={2023},
  volume={61},
  number={},
  pages={1-20},
  doi={10.1109/TGRS.2022.3176603}
}

Statement

This project is under MIT licence. For any other questions please contact di.wang at gmail.com .

References

The codes of Pretraining & Scene Classification part mainly from MAE.

Relevant Projects

[1] <strong>An Empirical Study of Remote Sensing Pretraining, IEEE TGRS, 2022</strong> | Paper | Github <br><em>     Di Wang<sup></sup>, Jing Zhang<sup></sup>, Bo Du, Gui-Song Xia and Dacheng Tao</em>