Skip to content

Sat-SlideMix Augmentation #2742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

isaaccorley
Copy link
Collaborator

@isaaccorley isaaccorley commented Apr 18, 2025

Adds Sat-SlideMix augmentation from the paper Data Augmentation Approaches for Satellite Imagery

I've made this into a Kornia augmentation so that it will work with both images and masks. This has some nice benefits like automatically sampling from a range of percentages to shift and random sampling which dim and direction to shift.

Example usage:

import requests
import torch
import torchvision.transforms.functional as TF
from torchgeo.transforms import SatSlideMix
import kornia.augmentation as K
from PIL import Image
from IPython.display import display


image_url = "https://project.inria.fr/aerialimagelabeling/files/2011/12/kit1.jpg"
mask_url = "https://project.inria.fr/aerialimagelabeling/files/2011/12/kit2.jpg"
image = Image.open(requests.get(image_url, stream=True).raw).convert("RGB").resize((512, 512))
mask = Image.open(requests.get(mask_url, stream=True).raw).convert("L").resize((512, 512))
image = TF.pil_to_tensor(image).unsqueeze(0)
mask = TF.pil_to_tensor(mask).unsqueeze(0)
print(image.shape, mask.shape)

aug = K.AugmentationSequential(SatSlideMix(gamma=2, beta=(0.0, 1.0), p=1.0), data_keys=None)

batch = dict(image=image.clone().repeat(2, 1, 1, 1)/255.0, mask=mask.clone().repeat(2, 1, 1, 1)/255.0)
print(batch["image"].shape, batch["mask"].shape)  # image shape: (2, 3, 512, 512)  mask shape: (2, 1, 512, 512)
batch = aug(batch)
print(batch["image"].shape, batch["mask"].shape)  # image shape: (4, 3, 512, 512)  mask shape: (4, 1, 512, 512)

for i in range(batch["image"].shape[0]):
    display(TF.to_pil_image(batch["image"][i]))
    display(TF.to_pil_image(batch["mask"][i]))

Sample 1

image
image

Sample 2

image
image

Sample 3

image
image

Sample 4

image
image

@isaaccorley isaaccorley self-assigned this Apr 18, 2025
@github-actions github-actions bot added the transforms Data augmentation transforms label Apr 18, 2025
@isaaccorley isaaccorley marked this pull request as draft April 18, 2025 15:24
@isaaccorley isaaccorley requested a review from Copilot April 18, 2025 15:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new augmentation method, Sat-SlideMix, which circularly shifts satellite images to generate additional training samples as described in the referenced paper.

  • Introduces the sat_slidemix function in augmentations.py
  • Implements input validation and image rolling for augmentation

@adamjstewart adamjstewart added this to the 0.8.0 milestone Apr 18, 2025
@adamjstewart
Copy link
Collaborator

Can we implement this in a way that is compatible with Kornia?

@isaaccorley
Copy link
Collaborator Author

Can we implement this in a way that is compatible with Kornia?

Working on it

@burakekim
Copy link
Contributor

Do we refer to the paper in the docstring?

@isaaccorley
Copy link
Collaborator Author

Do we refer to the paper in the docstring?

Not yes, still converting it to work with kornia images and masks. Will add it though.

@github-actions github-actions bot added the testing Continuous integration testing label May 22, 2025
@isaaccorley isaaccorley marked this pull request as ready for review May 22, 2025 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing Continuous integration testing transforms Data augmentation transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants