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

Shuffle patches only during training #135

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Changes from all 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
7 changes: 1 addition & 6 deletions src/model_clay.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def __init__( # noqa: PLR0913
mask_ratio,
image_size,
patch_size,
shuffle,
dim,
depth,
heads,
Expand All @@ -74,7 +73,6 @@ def __init__( # noqa: PLR0913
self.mask_ratio = mask_ratio
self.image_size = image_size
self.patch_size = patch_size
self.shuffle = shuffle
self.dim = dim
self.bands = bands
self.band_groups = band_groups
Expand Down Expand Up @@ -246,7 +244,7 @@ def mask_out(self, patches):
GL == self.num_patches
), f"Expected {self.num_patches} patches, got {GL} patches."

if self.shuffle: # Shuffle the patches
if self.training: # Shuffle the patches
noise = torch.randn((B, GL), device=patches.device) # [B GL]
else: # Don't shuffle useful for interpolation & inspection of embeddings
noise = rearrange(
Expand Down Expand Up @@ -589,22 +587,19 @@ def __init__( # noqa: PLR0913
"sar": (10, 11),
"dem": (12,),
},
shuffle=True,
**kwargs,
):
super().__init__()
self.mask_ratio = mask_ratio
self.image_size = image_size
self.patch_size = patch_size
self.shuffle = shuffle
self.bands = bands
self.band_groups = band_groups

self.encoder = Encoder(
mask_ratio=mask_ratio,
image_size=image_size,
patch_size=patch_size,
shuffle=shuffle,
dim=dim,
depth=depth,
heads=heads,
Expand Down