MCPcopy Create free account
hub / github.com/AIRMEC/HECTOR / define_data_sampling

Function define_data_sampling

utils.py:66–98  ·  view source on GitHub ↗
(train_split, val_split, method, workers)

Source from the content-addressed store, hash-verified

64 return len(self.slide_df)
65
66def define_data_sampling(train_split, val_split, method, workers):
67 # Reproducibility of DataLoader.
68 g = torch.Generator()
69 g.manual_seed(0)
70
71 # Set up training data sampler.
72 if method == "random":
73 print("random sampling setting")
74 train_loader = DataLoader(
75 dataset=train_split,
76 batch_size=1, # model expects one bag of features at the time.
77 shuffle=True,
78 collate_fn=collate,
79 num_workers=workers,
80 pin_memory=True,
81 worker_init_fn=seed_worker,
82 generator=g,
83 )
84 else:
85 raise Exception(f"Sampling method '{method}' not implemented.")
86
87 val_loader = DataLoader(
88 dataset=val_split,
89 batch_size=1, # model expects one bag of features at the time.
90 sampler=SequentialSampler(val_split),
91 collate_fn=collate,
92 num_workers=workers,
93 pin_memory=True,
94 worker_init_fn=seed_worker,
95 generator=g,
96 )
97
98 return train_loader, val_loader
99
100class MonitorBestModelEarlyStopping:
101 """Early stops the training if validation loss doesn't improve after a given patience and save best model """

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected