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

Fix validation and test split not being reproducible #218

Merged
merged 18 commits into from
Oct 28, 2024
Merged
Changes from 1 commit
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: 5 additions & 3 deletions crabs/detector/datamodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ def _compute_splits(
"""

# Optionally fix the generator for a reproducible split of data
generator = None
generator_1, generator_2 = None, None
sfmig marked this conversation as resolved.
Show resolved Hide resolved
if self.split_seed:
generator = torch.Generator().manual_seed(self.split_seed)
generator_1 = torch.Generator().manual_seed(self.split_seed)
generator_2 = torch.Generator().manual_seed(self.split_seed)

# Create dataset (combining all datasets passed)
full_dataset = CrabsCocoDetection(
Expand All @@ -189,7 +190,7 @@ def _compute_splits(
train_dataset, test_val_dataset = random_split(
full_dataset,
[self.config["train_fraction"], 1 - self.config["train_fraction"]],
generator=generator,
generator=generator_1,
)

# Split test/val sets from the remainder
Expand All @@ -199,6 +200,7 @@ def _compute_splits(
1 - self.config["val_over_test_fraction"],
self.config["val_over_test_fraction"],
],
generator=generator_2,
)

return train_dataset, test_dataset, val_dataset
Expand Down