S2s2net - Sentinel-2 Super-Resolution Segmentation Network

Overview

S2S2Net

Sentinel-2 Super-Resolution Segmentation Network

Getting started

Installation

Basic

To help out with development, start by cloning this repo-url

git clone <repo-url>

Then I recommend using mamba to install both non-python binaries and python libraries. A virtual environment will also be created with Python and JupyterLab installed.

cd s2s2net
mamba env create --file environment.yml

Activate the virtual environment first.

mamba activate s2s2net

Finally, double-check that the libraries have been installed.

mamba list

Advanced

This is for those who want full reproducibility of the virtual environment.

Making an explicit conda-lock file (only needed if creating a new virtual environment/refreshing an existing one).

mamba env create --file environment.yml
mamba list --explicit > environment-linux-64.lock

Creating/Installing a virtual environment from a conda lock file. See also https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/managenvironments.html#building-identical-conda-environments.

mamba create --name s2s2net --file environment-linux-64.lock
mamba install --name s2s2net --file environment-linux-64.lock

Running jupyter lab

mamba activate s2s2net
python -m ipykernel install --user --name s2s2net  # to install virtual env properly
jupyter kernelspec list --json                     # see if kernel is installed
jupyter lab &
You might also like...
Official implementation of the paper 'Efficient and Degradation-Adaptive Network for Real-World Image Super-Resolution'
Official implementation of the paper 'Efficient and Degradation-Adaptive Network for Real-World Image Super-Resolution'

DASR Paper Efficient and Degradation-Adaptive Network for Real-World Image Super-Resolution Jie Liang, Hui Zeng, and Lei Zhang. In arxiv preprint. Abs

Super-Fast-Adversarial-Training - A PyTorch Implementation code for developing super fast adversarial training

Super-Fast-Adversarial-Training This is a PyTorch Implementation code for develo

A framework for joint super-resolution and image synthesis, without requiring real training data
A framework for joint super-resolution and image synthesis, without requiring real training data

SynthSR This repository contains code to train a Convolutional Neural Network (CNN) for Super-resolution (SR), or joint SR and data synthesis. The met

CVPR 2021 Challenge on Super-Resolution Space
CVPR 2021 Challenge on Super-Resolution Space

Learning the Super-Resolution Space Challenge NTIRE 2021 at CVPR Learning the Super-Resolution Space challenge is held as a part of the 6th edition of

(CVPR2021) ClassSR: A General Framework to Accelerate Super-Resolution Networks by Data Characteristic

ClassSR (CVPR2021) ClassSR: A General Framework to Accelerate Super-Resolution Networks by Data Characteristic Paper Authors: Xiangtao Kong, Hengyuan

Repository for
Repository for "Exploring Sparsity in Image Super-Resolution for Efficient Inference", CVPR 2021

SMSR Reposity for "Exploring Sparsity in Image Super-Resolution for Efficient Inference" [arXiv] Highlights Locate and skip redundant computation in S

git《Investigating Loss Functions for Extreme Super-Resolution》(CVPR 2020) GitHub:

Investigating Loss Functions for Extreme Super-Resolution NTIRE 2020 Perceptual Extreme Super-Resolution Submission. Our method ranked first and secon

[CVPR 2021] Unsupervised Degradation Representation Learning for Blind Super-Resolution
[CVPR 2021] Unsupervised Degradation Representation Learning for Blind Super-Resolution

DASR Pytorch implementation of "Unsupervised Degradation Representation Learning for Blind Super-Resolution", CVPR 2021 [arXiv] Overview Requirements

The implementation of ICASSP 2020 paper
The implementation of ICASSP 2020 paper "Pixel-level self-paced learning for super-resolution"

Pixel-level Self-Paced Learning for Super-Resolution This is an official implementaion of the paper Pixel-level Self-Paced Learning for Super-Resoluti

Comments
  • :alembic: Model redesign to single-branch, use Dice, Mish/Swish and PuP

    :alembic: Model redesign to single-branch, use Dice, Mish/Swish and PuP

    Re-architecting S2S2Net to be simpler (single-branch instead of dual-branch) and peform better (using a nicer loss model). Recommendations from @Ziwei-0129.

    TODO:

    • [x] Change from using dual-branch (in 979358749bdbca1587322ff4cd14504e882aa3b3) to single-branch (bf4f34efc46c9a01b4d9e79ea7571a1ec6abf15f)
      • Mainly because the dual-branch didn't really help for our task as it needed too much tweaking/hyperparameter tuning
      • Really, a single-branch network that's well designed can do the segmentation+super-resolution task equally well
    • [x] Swap out Focal Loss for a BinaryCrossEntropyLoss+DiceLoss (from https://smp.readthedocs.io/en/v0.2.1/losses.html#diceloss), also using soft labels of 0.1 (28892798b3ad315e7ee1a6d77897cc3910f328f9)
    • [x] Add Mish activation function to the upsampling head, change Segformer activation to Swish (f5da3c7a931432fe535de14a1837de80b0d5974f)
    • [x] Change from x4x5 head to progressive upsampling head x2x2x2x2.5 (50dcc4a2a3870237854d8f9c25b953e1fb1170a4)

    References:

    • https://medium.com/ai-salon/understanding-dice-loss-for-crisp-boundary-detection-bb30c2e5f62b
    • Deng, R., Shen, C., Liu, S., Wang, H., & Liu, X. (2018). Learning to predict crisp boundaries (arXiv:1807.10097). arXiv. https://doi.org/10.48550/arXiv.1807.10097
    • Ma, J., Chen, J., Ng, M., Huang, R., Li, Y., Li, C., Yang, X., & Martel, A. L. (2021). Loss odyssey in medical image segmentation. Medical Image Analysis, 71, 102035. https://doi.org/10.1016/j.media.2021.102035
    • Müller, R., Kornblith, S., & Hinton, G. (2020). When Does Label Smoothing Help? (arXiv:1906.02629). arXiv. https://doi.org/10.48550/arXiv.1906.02629
    enhancement 
    opened by weiji14 0
  • :zap: DeepSpeed ZeRO Stage 2 model parallel training

    :zap: DeepSpeed ZeRO Stage 2 model parallel training

    To prevent out-of-memory (OOM) errors when running the Transformer models! Change from distributed data parallel (DDP) to a data+model parallel strategy

    Current State

    As of 979358749bdbca1587322ff4cd14504e882aa3b3, we have been using distributed data parallel (DDP) to split the data batch-wise across multiple GPUs. However when running on a full-size Sentinel-2 image (batch_size=1) during test phase (#1), this can already cause out-of-memory issues for our Super-Resolution Segmentation task.

    Future State

    One possible solution is to shard the neural network model itself across multiple GPUs. This reduces the GPU memory requirements and allows for larger models and/or bigger datasets to be used for training/inference.

    Sharding model parameters, optimizers and gradients

    Specifically, we'll be switching to use DeepSpeed (https://github.com/microsoft/DeepSpeed) which offers several 'levels' of model sharding, and . See https://devblog.pytorchlightning.ai/experiment-with-billion-parameter-models-faster-using-deepspeed-and-meta-tensors-2e9c255edd71 and https://huggingface.co/blog/zero-deepspeed-fairscale for a good explainer

    Main DeepSpeed stages (from https://pytorch-lightning.readthedocs.io/en/1.6.3/advanced/model_parallel.html#deepspeed):

    • DeepSpeed ZeRO Stage 1 - Shard optimizer states, remains at speed parity with DDP whilst providing memory improvement
    • DeepSpeed ZeRO Stage 2 - Shard optimizer states and gradients, remains at speed parity with DDP whilst providing even more memory improvement
    • DeepSpeed ZeRO Stage 3 - Shard optimizer states, gradients, parameters and optionally activations. Increases distributed communication volume, but provides even more memory improvement

    :bulb: Suggest to use Stage 2 instead of Stage 3 because while Stage 3 improves memory use, it comes with increased latency from the cost of extra distributed communication.

    DeepSpeed Stage 1, 2, 3

    Other benefits of using DeepSpeed:

    • Stage 2 and Stage 3 also has an 'Offload' to CPU feature to save on memory, in cases when the GPU memory is simply not enough
    • Allows me to train the model on just 16GB of GPU RAM on my workstation :exploding_head:

    Alternative strategies (and why they were not considered)

    Pytorch-Lightning offers several other advanced training strategies. These might work well for other cases, but probably not for our specific project.

    • Bagua (https://github.com/BaguaSys/bagua)
      • Data Distributed Parallel
      • Why not use this? Due to it not being model parallel (though they may be working on it)
      • https://pytorch-lightning.readthedocs.io/en/1.6.3/accelerators/gpu.html#bagua
      • https://devblog.pytorchlightning.ai/bagua-a-new-efficient-distributed-training-strategy-available-in-pytorch-lightning-1-6-d6392633b15
    • Fairscale (https://github.com/facebookresearch/fairscale)
      • Model parallel training, a close competitor to DeepSpeed
      • Why not use this? I did try, but the conda-forge package couldn't work because of some ABI compatibility issue.
      • https://pytorch-lightning.readthedocs.io/en/1.6.3/advanced/model_parallel.html#fully-sharded-training

    TODO:

    • [x] Add deepspeed dependency (0a666012ffd523f8fffed541612d85ed0e151e7d)
    • [x] Switch model to use DeepSpeed ZeRO Stage 2 (6394c12fc92a4837f8f453b5192d038928dffd46)
    • [ ] ~~Use Meta Tensors, c.f. https://devblog.pytorchlightning.ai/experiment-with-billion-parameter-models-faster-using-deepspeed-and-meta-tensors-2e9c255edd71~~
      • Nope, doesn't work. Error given is NotImplementedError: Could not run 'aten::_local_scalar_dense' with arguments from the 'Meta' backend. See also https://github.com/pytorch/pytorch/issues/77764
    • [ ] Decide whether to remove the Super-Resolution branch :thinking:
    enhancement 
    opened by weiji14 0
  • :monocle_face: Implement test_step on independent hold-out set of images

    :monocle_face: Implement test_step on independent hold-out set of images

    To allow fair comparison of different models, compute F1 and IoU metrics on 8 independent images from a hold-out set (see 00a1c5b4fa9992749221d3f02bbd8a1e99447890) that was handpicked to be from different geographic localities compared to the train/val set. The evaluate function now has a boolean calc_loss parameter, so that the expensive loss computation can be skipped during the test_step loop (i.e. compute metrics only).

    Note on issues and workarounds:

    • Computing the test metrics means the full-size masks need to be loaded, and for some reason the geographical extent of the mask doesn't align with the image so need to do rio.clip_box.
    • Predicted tensor shapes are sometimes not exactly 5x that of the input image, so need to interpolate to the right size (which isn't actually proper, I know).
    • ~~Needed to use CPU for test_step because GPU did not have enough memory, and use 32-bit precision too.~~ Edit: fixed with model sharding #2.

    TODO:

    • [x] Initial implementatin of test_step (7e87c6ccb0ded0586b90a338d0be374b0af1737a)
    • [x] Run test_step on GPU instead of CPU (#1 and 099f92f5bb441a0158b51230a1108f38cd4cdbd0)
    • [x] Refactor to ensure image and mask geographical extents align (e03a6e97f85b4ceca2f25fba84d77e3087820d15)
    • [ ] FIx saving and loading from model checkpoint
    enhancement 
    opened by weiji14 0
Owner
Wei Ji
Geospatial Data Scientist, Postdoc doing Remote Sensing AI research.
Wei Ji
Implementation of CVPR 2020 Dual Super-Resolution Learning for Semantic Segmentation

Dual super-resolution learning for semantic segmentation 2021-01-02 Subpixel Update Happy new year! The 2020-12-29 update of SISR with subpixel conv p

Sam 79 Nov 24, 2022
The official pytorch implemention of the CVPR paper "Temporal Modulation Network for Controllable Space-Time Video Super-Resolution".

This is the official PyTorch implementation of TMNet in the CVPR 2021 paper "Temporal Modulation Network for Controllable Space-Time VideoSuper-Resolu

Gang Xu 95 Oct 24, 2022
PyTorch code for our paper "Attention in Attention Network for Image Super-Resolution"

Under construction... Attention in Attention Network for Image Super-Resolution (A2N) This repository is an PyTorch implementation of the paper "Atten

Haoyu Chen 71 Dec 30, 2022
PyTorch code for our ECCV 2020 paper "Single Image Super-Resolution via a Holistic Attention Network"

HAN PyTorch code for our ECCV 2020 paper "Single Image Super-Resolution via a Holistic Attention Network" This repository is for HAN introduced in the

五维空间 140 Nov 23, 2022
Project page of the paper 'Analyzing Perception-Distortion Tradeoff using Enhanced Perceptual Super-resolution Network' (ECCVW 2018)

EPSR (Enhanced Perceptual Super-resolution Network) paper This repo provides the test code, pretrained models, and results on benchmark datasets of ou

Subeesh Vasu 78 Nov 19, 2022
Pytorch implementation of Deep Recursive Residual Network for Super Resolution (DRRN)

DRRN-pytorch This is an unofficial implementation of "Deep Recursive Residual Network for Super Resolution (DRRN)", CVPR 2017 in Pytorch. [Paper] You

yun_yang 192 Dec 12, 2022
pytorch implementation for Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network arXiv:1609.04802

PyTorch SRResNet Implementation of Paper: "Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network"(https://arxiv.org/abs

Jiu XU 436 Jan 9, 2023
Official PyTorch code for Mutual Affine Network for Spatially Variant Kernel Estimation in Blind Image Super-Resolution (MANet, ICCV2021)

Mutual Affine Network for Spatially Variant Kernel Estimation in Blind Image Super-Resolution (MANet, ICCV2021) This repository is the official PyTorc

Jingyun Liang 139 Dec 29, 2022
Code repo for "RBSRICNN: Raw Burst Super-Resolution through Iterative Convolutional Neural Network" (Machine Learning and the Physical Sciences workshop in NeurIPS 2021).

RBSRICNN: Raw Burst Super-Resolution through Iterative Convolutional Neural Network An official PyTorch implementation of the RBSRICNN network as desc

Rao Muhammad Umer 6 Nov 14, 2022
A Text Attention Network for Spatial Deformation Robust Scene Text Image Super-resolution (CVPR2022)

A Text Attention Network for Spatial Deformation Robust Scene Text Image Super-resolution (CVPR2022) https://arxiv.org/abs/2203.09388 Jianqi Ma, Zheto

MA Jianqi, shiki 104 Jan 5, 2023