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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
tags:
|
| 6 |
+
- OneScience
|
| 7 |
+
- earth-science
|
| 8 |
+
- remote-sensing-representation-learning
|
| 9 |
+
- multiscale-remote-sensing
|
| 10 |
+
- GSD-scale-modeling
|
| 11 |
+
- low-high-frequency-reconstruction
|
| 12 |
+
frameworks: PyTorch
|
| 13 |
+
datasets:
|
| 14 |
+
- FMoW-RGB
|
| 15 |
+
- RESISC-45
|
| 16 |
+
- EuroSAT
|
| 17 |
+
- UCMerced
|
| 18 |
+
- AID
|
| 19 |
+
- MLRSNet
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
<p align="center"><strong><span style="font-size: 30px;">Scale-MAE</span></strong></p>
|
| 23 |
+
|
| 24 |
+
# Model Introduction
|
| 25 |
+
|
| 26 |
+
Scale-MAE is a scale-aware masked autoencoder for multiscale geospatial imagery that learns stable remote sensing image representations through ground-sampling-distance-aware positional encoding, visible-patch encoding, and low- and high-frequency target reconstruction.
|
| 27 |
+
|
| 28 |
+
Paper: Scale-MAE: A Scale-Aware Masked Autoencoder for Multiscale Geospatial Representation Learning
|
| 29 |
+
https://arxiv.org/abs/2212.14532
|
| 30 |
+
|
| 31 |
+
# Model Description
|
| 32 |
+
|
| 33 |
+
Scale-MAE was proposed by research teams at NASA's Jet Propulsion Laboratory and Stanford University. The model is trained using multiscale geospatial imagery such as FMoW-RGB. The model is suitable for tasks such as remote sensing image representation learning, scene classification, and building segmentation.
|
| 34 |
+
|
| 35 |
+
# Applicable Scenarios
|
| 36 |
+
|
| 37 |
+
| Scenario | Description |
|
| 38 |
+
| :---: | :--- |
|
| 39 |
+
| Multiscale remote sensing pre-training | Use paired low-resolution and high-resolution `BCHW` imagery with GSD metadata. |
|
| 40 |
+
| Scene classification | Perform kNN transfer evaluation through reusable CLS features. |
|
| 41 |
+
| Building segmentation | Transfer scale-aware representations to building semantic-segmentation tasks such as SpaceNet and fine-tune them. |
|
| 42 |
+
| Low- and high-frequency reconstruction | Use area resampling and band-pass targets to evaluate scale sensitivity. |
|
| 43 |
+
| Local quick validation | Use synthetic data to check data loading, training, inference, and evaluation. |
|
| 44 |
+
| Multi-GPU training | Launch distributed data-parallel training through `torchrun`. |
|
| 45 |
+
|
| 46 |
+
# Usage Instructions
|
| 47 |
+
|
| 48 |
+
## 1. OneCode Usage
|
| 49 |
+
|
| 50 |
+
Experience intelligent one-click AI4S programming through the OneCode online environment:
|
| 51 |
+
|
| 52 |
+
[Experience intelligent one-click AI4S programming](https://web-2069360198568017922-iaaj.ksai.scnet.cn:58043/home)
|
| 53 |
+
|
| 54 |
+
## 2. Manual Installation and Usage
|
| 55 |
+
|
| 56 |
+
**Hardware Requirements**
|
| 57 |
+
|
| 58 |
+
- GPU or DCU execution is recommended.
|
| 59 |
+
- CPU can be used to validate the workflow with the current default small configuration.
|
| 60 |
+
- DCU users need to install a DTK version matching the cluster in advance. DTK 25.04.2 or later is recommended.
|
| 61 |
+
|
| 62 |
+
### Download the Model Package
|
| 63 |
+
|
| 64 |
+
```bash
|
| 65 |
+
hf download OneScience-Group/Scale-MAE --local-dir ./Scale-MAE
|
| 66 |
+
cd Scale-MAE
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
### Install the Runtime Environment
|
| 70 |
+
|
| 71 |
+
**DCU Environment**
|
| 72 |
+
|
| 73 |
+
```bash
|
| 74 |
+
conda create -n onescience311 python=3.11 -y
|
| 75 |
+
conda activate onescience311
|
| 76 |
+
pip install onescience[earth-dcu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
**GPU Environment**
|
| 80 |
+
|
| 81 |
+
```bash
|
| 82 |
+
conda create -n onescience311 python=3.11 -y libstdcxx-ng=12 libgcc-ng=12 gcc_linux-64=12 gxx_linux-64=12
|
| 83 |
+
conda activate onescience311
|
| 84 |
+
pip install onescience[earth-gpu] -i http://mirrors.onescience.ai:3141/pypi/simple/ --trusted-host mirrors.onescience.ai
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### Training Data Introduction
|
| 88 |
+
|
| 89 |
+
The paper uses multiscale geospatial imagery such as FMoW-RGB for pre-training and evaluates on tasks including RESISC-45, UCMerced, EuroSAT, AID, MLRSNet, and SpaceNet. Data files contain `images` `[B,C,H,W]`, `targets` `[B,C,Ht,Wt]`, `gsd` `[B]`, and `labels` `[B]`.
|
| 90 |
+
|
| 91 |
+
Synthetic data is used by default:
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
python scripts/fake_data.py
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
When using real data, do not run `fake_data.py`. First organize the data into the following directories and fields, and replace the files under `data/` generated by the synthetic-data script:
|
| 98 |
+
|
| 99 |
+
```text
|
| 100 |
+
data/train.npz
|
| 101 |
+
data/test.npz
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
Each NPZ file contains at least:
|
| 105 |
+
|
| 106 |
+
```text
|
| 107 |
+
images: float32 [N,C,input_size,input_size]
|
| 108 |
+
targets: float32 [N,C,target_size,target_size]
|
| 109 |
+
gsd: float32 [N]
|
| 110 |
+
labels: int64 [N]
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
Here, `images` is the model input, `targets` is the target-resolution imagery corresponding to the input scene, `gsd` is the ground sampling distance for each sample in meters per pixel, and `labels` is used for kNN feature evaluation. The channel count, input size, target size, and GSD range of real data must be consistent with `conf/config.yaml` and the model configuration; cropping, registration, channel organization, and numerical normalization should be completed before generating the NPZ files.
|
| 114 |
+
|
| 115 |
+
Modify `input_size`, `target_size`, `channels`, `gsd_values`, and paths in `conf/config.yaml` according to the real data. After completing data preparation, continue to use the unified training, inference, and evaluation commands below; if other file locations are needed, override the default paths through script arguments.
|
| 116 |
+
|
| 117 |
+
### Training
|
| 118 |
+
|
| 119 |
+
Single GPU:
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
python scripts/train.py
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
Multiple GPUs:
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
torchrun --nproc_per_node=8 scripts/train.py
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
Training outputs:
|
| 132 |
+
|
| 133 |
+
```text
|
| 134 |
+
result/checkpoints/scalemae.pt
|
| 135 |
+
result/training/metrics.json
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
Training outputs include a model checkpoint that can be used for subsequent inference and feature extraction, as well as training metrics reflecting changes in overall, low-frequency, and high-frequency reconstruction losses, facilitating training-state preservation and analysis of model optimization.
|
| 139 |
+
|
| 140 |
+
AdamW uses betas `(0.9, 0.95)` and includes gradient accumulation, AMP, warmup, and cosine decay.
|
| 141 |
+
|
| 142 |
+
### Trained Weights
|
| 143 |
+
|
| 144 |
+
This repository provides weights trained on multiscale geospatial imagery in the `weight/` folder. The weight files will be uploaded soon.
|
| 145 |
+
|
| 146 |
+
### Inference
|
| 147 |
+
|
| 148 |
+
```bash
|
| 149 |
+
python scripts/inference.py
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
Inference results are output to:
|
| 153 |
+
|
| 154 |
+
```text
|
| 155 |
+
result/output/reconstruction.npz
|
| 156 |
+
```
|
| 157 |
+
|
| 158 |
+
### Evaluation and Visualization
|
| 159 |
+
|
| 160 |
+
```bash
|
| 161 |
+
python scripts/result.py
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
Evaluation and visualization outputs are saved to:
|
| 165 |
+
|
| 166 |
+
```text
|
| 167 |
+
result/evaluation/metrics.json
|
| 168 |
+
result/evaluation/features.npy
|
| 169 |
+
result/evaluation/bandpass_reconstruction.png
|
| 170 |
+
result/evaluation/frequency_error.png
|
| 171 |
+
result/evaluation/gsd_reconstruction_error.png
|
| 172 |
+
result/evaluation/gsd_knn_accuracy.png
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
Evaluation results comprehensively reflect overall and low- and high-frequency reconstruction quality, scale adaptability under different GSD values, and the kNN classification capability of representation features, while reconstruction comparisons and scale-variation curves demonstrate the model's ability to process multiscale geospatial imagery. The current results are based on a small amount of synthetic data and are mainly used to confirm that the training, inference, evaluation, and visualization workflows operate normally.
|
| 176 |
+
|
| 177 |
+
# OneScience Official Information
|
| 178 |
+
|
| 179 |
+
| Platform | OneScience Main Repository | Skills Repository |
|
| 180 |
+
| --- | --- | --- |
|
| 181 |
+
| Gitee | https://gitee.com/onescience-ai/onescience | https://gitee.com/onescience-ai/oneskills |
|
| 182 |
+
| GitHub | https://github.com/onescience-ai/OneScience | https://github.com/onescience-ai/oneskills |
|
| 183 |
+
|
| 184 |
+
# Citation and License
|
| 185 |
+
|
| 186 |
+
This repository is a reproduction of the original Scale-MAE paper.
|