Update mnist_datamodule.py
This commit is contained in:
1 parent
eee3f9ccd3
commit
f212e617b1
1 file changed
+2
-4
@@ -63,18 +63,16 @@ class MNISTDataModule(LightningDataModule):
|
||||
MNIST(self.data_dir, train=False, download=True)
|
||||
|
||||
def setup(self, stage: Optional[str] = None):
|
||||
"""Load data. Set variables: self.data_train, self.data_val, self.data_test.
|
||||
"""Load data. Set variables: `self.data_train`, `self.data_val`, `self.data_test`.
|
||||
This method is called by lightning separately when using `trainer.fit()` and `trainer.test()`!
|
||||
The `stage` can be used to differentiate whether the `setup()` is called before trainer.fit()` or `trainer.test()`."""
|
||||
if not self.data_train or not self.data_val or not self.data_test:
|
||||
trainset = MNIST(self.data_dir, train=True, transform=self.transforms)
|
||||
testset = MNIST(self.data_dir, train=False, transform=self.transforms)
|
||||
dataset = ConcatDataset(datasets=[trainset, testset])
|
||||
self.data_train, self.data_val, self.data_test = random_split(
|
||||
dataset, self.train_val_test_split, generator=torch.Generator().manual_seed(42)
|
||||
)
|
||||
# always use generator seed in `random_split()` or else the test data
|
||||
# might leak to train data when `setup()` is called the second time!
|
||||
# alternatively, you can set the test dataset and train dataset separately for each stage
|
||||
|
||||
def train_dataloader(self):
|
||||
return DataLoader(
|
||||
|
||||
Reference in new issue
Block a user