LightningDataModule — PyTorch Lightning 1.5.7 documentation
pytorch-lightning.readthedocs.io › en › stableIf you need information from the dataset to build your model, then run prepare_data() and setup() manually (Lightning ensures the method runs on the correct devices). dm = MNISTDataModule () dm . prepare_data () dm . setup ( stage = "fit" ) model = Model ( num_classes = dm . num_classes , width = dm . width , vocab = dm . vocab ) trainer . fit ( model , dm ) dm . setup ( stage = "test" ) trainer . test ( datamodule = dm )
How to get dataset from prepare_data() to setup() in PyTorch ...
stackoverflow.com › questions › 67441163May 07, 2021 · def prepare_data(self): a = np.random.uniform(0, 500, 500) b = np.random.normal(0, self.constant, len(a)) c = a + b X = np.transpose(np.array([a, b])) # Converting numpy array to Tensor self.x_train_tensor = torch.from_numpy(X).float().to(device) self.y_train_tensor = torch.from_numpy(c).float().to(device) training_dataset = TensorDataset(self.x_train_tensor, self.y_train_tensor) self.training_dataset = training_dataset def setup(self): data = self.training_dataset self.train_data, self.val ...