Seasonal Contrast: Unsupervised Pre-Training from Uncurated Remote Sensing Data

Overview

Seasonal Contrast: Unsupervised Pre-Training from Uncurated Remote Sensing Data

diagram

This is the official PyTorch implementation of the SeCo paper:

@article{manas2021seasonal,
  title={Seasonal Contrast: Unsupervised Pre-Training from Uncurated Remote Sensing Data},
  author={Ma{\~n}as, Oscar and Lacoste, Alexandre and Giro-i-Nieto, Xavier and Vazquez, David and Rodriguez, Pau},
  journal={arXiv preprint arXiv:2103.16607},
  year={2021}
}

Preparation

Install Python dependencies by running:

pip install -r requirements.txt

Data Collection

First, obtain Earth Engine authentication credentials by following the installation instructions.

Then, to collect and download a new SeCo dataset from a random set of Earth locations, run:

python datasets/seco_downloader.py \
  --save_path [folder where data will be downloaded] \
  --num_locations 200000

Unsupervised Pre-training

To do unsupervised pre-training of a ResNet-18 model on the SeCo dataset, run:

python main_pretrain.py \
  --data_dir datasets/seco_1m --data_mode seco \
  --base_encoder resnet18

Transferring to Downstream Tasks

With a pre-trained SeCo model, to train a supervised linear classifier on 10% of the BigEarthNet training set in a 4-GPU machine, run:

python main_bigearthnet.py \
  --gpus 4 --accelerator dp --batch_size 1024 \
  --data_dir datasets/bigearthnet --train_frac 0.1 \
  --backbone_type pretrain --ckpt_path checkpoints/seco_resnet18_1m.ckpt \
  --freeze_backbone --learning_rate 1e-3

To train a supervised linear classifier on EuroSAT from a pre-trained SeCo model, run:

python main_eurosat.py \
  --data_dir datasets/eurosat \
  --backbone_type pretrain --ckpt_path checkpoints/seco_resnet18_1m.ckpt

To train a supervised change detection model on OSCD from a pre-trained SeCo model, run:

python main_oscd.py \
  --data_dir datasets/oscd \
  --backbone_type pretrain --ckpt_path checkpoints/seco_resnet18_1m.ckpt

Datasets

Our collected SeCo datasets can be downloaded as following:

#images RGB preview size link md5
100K 7.3 GB download ebf2d5e03adc6e657f9a69a20ad863e0
~1M 36.3 GB download 187963d852d4d3ce6637743ec3a4bd9e

Pre-trained Models

Our pre-trained SeCo models can be downloaded as following:

dataset architecture link md5
SeCo-100K ResNet-18 download dcf336be31f6c6b0e77dcb6cc958fca8
SeCo-1M ResNet-18 download 53d5c41d0f479bdfd31d6746ad4126db
SeCo-100K ResNet-50 download 9672c303f6334ef816494c13b9d05753
SeCo-1M ResNet-50 download 7b09c54aed33c0c988b425c54f4ef948
Comments
  • Could you please reveal the division of these downstream task datasets

    Could you please reveal the division of these downstream task datasets

    I try to conduct downstream tasks, and I download the different datasets. But the training needs the division of training and test sets: train.txt, val.txt and test.txt. Could you please reveal the division of these data sets?

    opened by icey-zhang 2
  • transforms SeasonalContrastBasic and SeasonalContrastTemporal

    transforms SeasonalContrastBasic and SeasonalContrastTemporal

    Thanks for sharing the code! I'm pretty impressed by your work.

    I have a few questions about the data module.

    For the class SeasonalContrastTemporalDataModule. I do see the transform as follows:

    def train_transform():
    return Moco2TrainImagenetTransforms(height=224).train_transform

    According to the paper, the second key should contain only seasonal augmentations. So I wonder if this transforms necessary because of the training of MoCo.

    Also, this built-in transform only works for images with three channels. Could you let me know how you made it work for multiple channels?

    Thanks for your help.

    opened by jingwu6 0
  • Error when training a supervised linear classifier on EuroSAT from a pre-trained SeCo model

    Error when training a supervised linear classifier on EuroSAT from a pre-trained SeCo model

    I encountered error when running this script: python main_eurosat.py --data_dir data/eurosat --backbone_type pretrain --ckpt_path checkpoints/seco_resnet50_100k.ckpt

    Traceback (most recent call last):
      File "main_eurosat.py", line 89, in <module>
        trainer.fit(model, datamodule=datamodule)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 510, in fit
        results = self.accelerator_backend.train()
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 57, in train
        return self.train_or_test()
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/accelerator.py", line 74, in train_or_test
        results = self.trainer.train()
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 532, in train
        self.run_sanity_check(self.get_model())
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 731, in run_sanity_check
        _, eval_results = self.run_evaluation(max_batches=self.num_sanity_val_batches)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 643, in run_evaluation
        output = self.evaluation_loop.evaluation_step(batch, batch_idx, dataloader_idx)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/trainer/evaluation_loop.py", line 171, in evaluation_step
        output = self.trainer.accelerator_backend.validation_step(args)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/gpu_accelerator.py", line 73, in validation_step
        return self._step(self.trainer.model.validation_step, args)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/pytorch_lightning/accelerators/gpu_accelerator.py", line 65, in _step
        output = model_step(*args)
      File "main_eurosat.py", line 39, in validation_step
        loss, acc = self.shared_step(batch)
      File "main_eurosat.py", line 46, in shared_step
        logits = self(x)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "main_eurosat.py", line 29, in forward
        logits = self.classifier(feats)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 93, in forward
        return F.linear(input, self.weight, self.bias)
      File "/home/chandler_doloriel/.conda/envs/seasonal-contrast/lib/python3.7/site-packages/torch/nn/functional.py", line 1690, in linear
        ret = torch.addmm(bias, input, weight.t())
    RuntimeError: mat1 dim 1 must match mat2 dim 0
    
    opened by chandlerbing65nm 0
  • Testing for Resnet18 100k Seco dataset

    Testing for Resnet18 100k Seco dataset

    @oscmansan i didn't find anywhere in paper. I was having look at your checkpoint file and saw for 100k SeCo implementation, you used 1000 epochs image

    Is it 1000 epochs also for MoCoV2 and MoCoV2-TP too ?

    opened by ankitpatnala 0
  • how to fix the random seed of downloaded patches

    how to fix the random seed of downloaded patches

    Hi, thanks for the exciting work! I'm wondering is there a way to fix the random seed of data downloading?

    E.g. I first download in total 100 patches (num_locations=100), and then rerun the code to download again 100 patches. The output patches would be different, can I make them the same?

    opened by wangyi111 0
  • 4 or 8 pixel blocks in downloaded Sentinel imagery

    4 or 8 pixel blocks in downloaded Sentinel imagery

    hi Pau @prlz77 and Oscar @oscmansan,

    Thanks for your work. We were downloading the data with seco_downloader.py but noticed a certain 4 or 8-pixel block structure in the images. Looking over the source code, I can't find a concrete reason. Could it be connected to the getInfo line https://github.com/ElementAI/seasonal-contrast/blob/5395c027922569f5c5b1785ad1ccddd839749c36/datasets/seco_downloader.py#L175 where (maybe) only an approximated representation of the images is returned?

    Screenshot from 2021-10-21 11-46-25 image (1) image

    opened by MarcCoru 2
  • how to freeze backbone in oscd

    how to freeze backbone in oscd

    Hi, I can't find how you freeze backbone in oscd task, maybe in main_oscd.py or segmentation.py but i can't find the code(such as torch.no_grad?). Could you please tell me where is it. Thanks.

    opened by MGLiXu 1
Owner
ElementAI
ElementAI
rastrainer is a QGIS plugin to training remote sensing semantic segmentation model based on PaddlePaddle.

rastrainer rastrainer is a QGIS plugin to training remote sensing semantic segmentation model based on PaddlePaddle. UI TODO Init UI. Add Block. Add l

deepbands 5 Mar 4, 2022
PyTorch implementation of "Contrast to Divide: self-supervised pre-training for learning with noisy labels"

Contrast to Divide: self-supervised pre-training for learning with noisy labels This is an official implementation of "Contrast to Divide: self-superv

null 55 Nov 23, 2022
Implementation of SSMF: Shifting Seasonal Matrix Factorization

SSMF Implementation of SSMF: Shifting Seasonal Matrix Factorization, Koki Kawabata, Siddharth Bhatia, Rui Liu, Mohit Wadhwa, Bryan Hooi. NeurIPS, 2021

Koki Kawabata 9 Jun 10, 2022
CFC-Net: A Critical Feature Capturing Network for Arbitrary-Oriented Object Detection in Remote Sensing Images

CFC-Net This project hosts the official implementation for the paper: CFC-Net: A Critical Feature Capturing Network for Arbitrary-Oriented Object Dete

ming71 55 Dec 12, 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
FactSeg: Foreground Activation Driven Small Object Semantic Segmentation in Large-Scale Remote Sensing Imagery (TGRS)

FactSeg: Foreground Activation Driven Small Object Semantic Segmentation in Large-Scale Remote Sensing Imagery by Ailong Ma, Junjue Wang*, Yanfei Zhon

Kingdrone 43 Jan 5, 2023
PyTorch implementation of popular datasets and models in remote sensing

PyTorch Remote Sensing (torchrs) (WIP) PyTorch implementation of popular datasets and models in remote sensing tasks (Change Detection, Image Super Re

isaac 222 Dec 28, 2022
Deep learning models for change detection of remote sensing images

Change Detection Models (Remote Sensing) Python library with Neural Networks for Change Detection based on PyTorch. ⚡ ⚡ ⚡ I am trying to build this pr

Kaiyu Li 176 Dec 24, 2022
Change is Everywhere: Single-Temporal Supervised Object Change Detection in Remote Sensing Imagery (ICCV 2021)

Change is Everywhere Single-Temporal Supervised Object Change Detection in Remote Sensing Imagery by Zhuo Zheng, Ailong Ma, Liangpei Zhang and Yanfei

Zhuo Zheng 125 Dec 13, 2022
Remote sensing change detection tool based on PaddlePaddle

PdRSCD PdRSCD(PaddlePaddle Remote Sensing Change Detection)是一个基于飞桨PaddlePaddle的遥感变化检测的项目,pypi包名为ppcd。目前0.2版本,最新支持图像列表输入的训练和预测,如多期影像、多源影像甚至多期多源影像。可以快速完

null 38 Aug 31, 2022
LoveDA: A Remote Sensing Land-Cover Dataset for Domain Adaptive Semantic Segmentation (NeurIPS2021 Benchmark and Dataset Track)

LoveDA: A Remote Sensing Land-Cover Dataset for Domain Adaptive Semantic Segmentation by Junjue Wang, Zhuo Zheng, Ailong Ma, Xiaoyan Lu, and Yanfei Zh

Kingdrone 174 Dec 22, 2022
From this paper "SESNet: A Semantically Enhanced Siamese Network for Remote Sensing Change Detection"

SESNet for remote sensing image change detection It is the implementation of the paper: "SESNet: A Semantically Enhanced Siamese Network for Remote Se

null 1 May 24, 2022
paper: Hyperspectral Remote Sensing Image Classification Using Deep Convolutional Capsule Network

DC-CapsNet This is a tensorflow and keras based implementation of DC-CapsNet for HSI in the Remote Sensing Letters R. Lei et al., "Hyperspectral Remot

LEI 7 Nov 29, 2022
Semi-supervised Representation Learning for Remote Sensing Image Classification Based on Generative Adversarial Networks

SSRL-for-image-classification Semi-supervised Representation Learning for Remote Sensing Image Classification Based on Generative Adversarial Networks

Feng 2 Nov 19, 2021
a practicable framework used in Deep Learning. So far UDL only provide DCFNet implementation for the ICCV paper (Dynamic Cross Feature Fusion for Remote Sensing Pansharpening)

UDL UDL is a practicable framework used in Deep Learning (computer vision). Benchmark codes, results and models are available in UDL, please contact @

Xiao Wu 11 Sep 30, 2022
LoveDA: A Remote Sensing Land-Cover Dataset for Domain Adaptive Semantic Segmentation

LoveDA: A Remote Sensing Land-Cover Dataset for Domain Adaptive Semantic Segmentation by Junjue Wang, Zhuo Zheng, Ailong Ma, Xiaoyan Lu, and Yanfei Zh

Payphone 8 Nov 21, 2022
Remote sensing change detection using PaddlePaddle

Change Detection Laboratory Developing and benchmarking deep learning-based remo

Lin Manhui 15 Sep 23, 2022
Fang Zhonghao 13 Nov 19, 2022
Universal Adversarial Examples in Remote Sensing: Methodology and Benchmark

Universal Adversarial Examples in Remote Sensing: Methodology and Benchmark Yong

null 19 Dec 17, 2022