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

Update gandlf_data.py #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions fets/data/pytorch/gandlf_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
from fets.data.gandlf_utils import get_dataframe_and_headers
from fets.data import get_appropriate_file_paths_from_subject_dir

## added for reproducibility
def seed_worker(worker_id):
worker_seed = torch.initial_seed() % 2**32
numpy.random.seed(worker_seed)
random.seed(worker_seed)

g = torch.Generator()
g.manual_seed(0)
## added for reproducibility

# adapted from https://codereview.stackexchange.com/questions/132914/crop-black-border-of-image-using-numpy/132933#132933
def crop_image_outside_zeros(array, psize):
Expand Down Expand Up @@ -672,9 +681,9 @@ def get_loaders(self, data_frame, train, augmentations):
preprocessing=self.preprocessing,
in_memory=self.in_memory)
if train:
loader = DataLoader(data, shuffle=True, batch_size=self.batch_size)
loader = DataLoader(data, shuffle=True, batch_size=self.batch_size, worker_init_fn=seed_worker)
else:
loader = DataLoader(data, shuffle=False, batch_size=1)
loader = DataLoader(data, shuffle=False, batch_size=1, , worker_init_fn=seed_worker)

companion_loader = None
if train:
Expand Down