`LightningDataModule` for combined training and test datasets. A `LightningDataModule` implements 7 key methods: ```python def prepare_data(self): # Things to do on 1 GPU/TPU (not on every GPU/TPU in DDP). # Download data, pre-process, split, save to disk, etc...
| 26 | |
| 27 | |
| 28 | class CombinedDataModule(LightningDataModule): |
| 29 | """`LightningDataModule` for combined training and test datasets. |
| 30 | |
| 31 | A `LightningDataModule` implements 7 key methods: |
| 32 | |
| 33 | ```python |
| 34 | def prepare_data(self): |
| 35 | # Things to do on 1 GPU/TPU (not on every GPU/TPU in DDP). |
| 36 | # Download data, pre-process, split, save to disk, etc... |
| 37 | |
| 38 | def setup(self, stage): |
| 39 | # Things to do on every process in DDP. |
| 40 | # Load data, set variables, etc... |
| 41 | |
| 42 | def train_dataloader(self): |
| 43 | # return train dataloader |
| 44 | |
| 45 | def val_dataloader(self): |
| 46 | # return validation dataloader |
| 47 | |
| 48 | def test_dataloader(self): |
| 49 | # return test dataloader |
| 50 | |
| 51 | def predict_dataloader(self): |
| 52 | # return predict dataloader |
| 53 | |
| 54 | def teardown(self, stage): |
| 55 | # Called on every process in DDP. |
| 56 | # Clean up after fit or test. |
| 57 | ``` |
| 58 | |
| 59 | This allows you to share a full dataset without explaining how to download, |
| 60 | split, transform and process the data. |
| 61 | |
| 62 | Read the docs: |
| 63 | https://lightning.ai/docs/pytorch/latest/data/datamodule.html |
| 64 | """ |
| 65 | |
| 66 | def __init__( |
| 67 | self, |
| 68 | data_dir: str = "data/", |
| 69 | train_datasets: List[str] = ["pdbbind", "moad", "pdbsidechain"], |
| 70 | test_datasets: List[str] = ["pdbbind", "moad"], |
| 71 | batch_size: int = 16, |
| 72 | num_workers: int = 0, |
| 73 | pin_memory: bool = False, |
| 74 | stage: Optional[str] = None, |
| 75 | **kwargs: Any, |
| 76 | ) -> None: |
| 77 | """Initialize a `CombinedDataModule`. |
| 78 | |
| 79 | :param data_dir: The data directory. Defaults to `"data/"`. |
| 80 | :param train_datasets: The datasets to use for training. Defaults to `["pdbbind", "moad", "pdbsidechain"]`. |
| 81 | :param test_datasets: The datasets to use for testing. Defaults to `["pdbbind", "moad"]`. |
| 82 | :param batch_size: The batch size. Defaults to `16`. |
| 83 | :param num_workers: The number of workers. Defaults to `0`. |
| 84 | :param pin_memory: Whether to pin memory. Defaults to `False`. |
| 85 | :param stage: The stage to setup. Either `"fit"`, `"validate"`, `"test"`, or `"predict"`. Defaults to ``None``. |
no outgoing calls
no test coverage detected