Skip to content
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

MoCo/SimCLR transforms update #1357

Merged
merged 5 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions torchgeo/trainers/moco.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def moco_augmentations(
T.RandomGrayscale(weights=weights, p=0.2),
# Not appropriate for multispectral imagery, seasonal contrast used instead
# K.ColorJitter(brightness=0.4, contrast=0.4, saturation=0.4, hue=0.4, p=1)
K.RandomBrightness(brightness=(0.8, 1.0), p=0.8),
K.RandomContrast(contrast=(0.8, 1.0), p=0.8),
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
K.RandomHorizontalFlip(),
K.RandomVerticalFlip(), # added
data_keys=["input"],
Expand All @@ -74,6 +76,8 @@ def moco_augmentations(
# K.ColorJitter(
# brightness=0.4, contrast=0.4, saturation=0.4, hue=0.1, p=0.8
# )
K.RandomBrightness(brightness=(0.8, 1.0), p=0.8),
K.RandomContrast(contrast=(0.8, 1.0), p=0.8),
T.RandomGrayscale(weights=weights, p=0.2),
K.RandomGaussianBlur(kernel_size=(ks, ks), sigma=(0.1, 2), p=0.5),
K.RandomHorizontalFlip(),
Expand All @@ -88,6 +92,8 @@ def moco_augmentations(
# K.ColorJitter(
# brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8
# )
K.RandomBrightness(brightness=(0.8, 1.0), p=0.8),
K.RandomContrast(contrast=(0.8, 1.0), p=0.8),
T.RandomGrayscale(weights=weights, p=0.2),
K.RandomGaussianBlur(kernel_size=(ks, ks), sigma=(0.1, 2), p=1),
K.RandomHorizontalFlip(),
Expand All @@ -100,6 +106,8 @@ def moco_augmentations(
# K.ColorJitter(
# brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1, p=0.8
# )
K.RandomBrightness(brightness=(0.8, 1.0), p=0.8),
K.RandomContrast(contrast=(0.8, 1.0), p=0.8),
T.RandomGrayscale(weights=weights, p=0.2),
K.RandomGaussianBlur(kernel_size=(ks, ks), sigma=(0.1, 2), p=0.1),
K.RandomSolarize(p=0.2),
Expand Down
2 changes: 2 additions & 0 deletions torchgeo/trainers/simclr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def simclr_augmentations(size: int, weights: Tensor) -> nn.Module:
K.RandomVerticalFlip(), # added
# Not appropriate for multispectral imagery, seasonal contrast used instead
# K.ColorJitter(brightness=0.8, contrast=0.8, saturation=0.8, hue=0.2, p=0.8)
K.RandomBrightness(brightness=(0.8, 1.0), p=0.8),
K.RandomContrast(contrast=(0.8, 1.0), p=0.8),
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved
T.RandomGrayscale(weights=weights, p=0.2),
K.RandomGaussianBlur(kernel_size=(ks, ks), sigma=(0.1, 2)),
data_keys=["input"],
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/transforms/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def apply_transform(
Returns:
The augmented input.
"""
weights = flags["weights"][..., :, None, None]
weights = flags["weights"][..., :, None, None].to(input.device)
out = input * weights
out = out.sum(dim=-3)
out = out.unsqueeze(-3).expand(input.shape)
Expand Down