mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
added docs (#944)
This commit is contained in:
@@ -930,16 +930,23 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
|
||||
:return: PyTorch DataLoader
|
||||
|
||||
Called by lightning during training loop. Make sure to use the @pl.data_loader decorator,
|
||||
this ensures not calling this function until the data are needed.
|
||||
If you want to change the data during every epoch DON'T use the data_loader decorator.
|
||||
Return a dataloader. It will not be called every epoch unless you set
|
||||
```Trainer(reload_dataloaders_every_epoch=True)```.
|
||||
|
||||
It's recommended that all data downloads and preparation happen in prepare_data().
|
||||
|
||||
.. note:: Lightning adds the correct sampler for distributed and arbitrary hardware. No need to set yourself.
|
||||
|
||||
- .fit()
|
||||
- ...
|
||||
- prepare_data()
|
||||
- train_dataloader
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@pl.data_loader
|
||||
def train_dataloader(self):
|
||||
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (1.0,))])
|
||||
dataset = MNIST(root='/path/to/mnist/', train=True, transform=transform, download=True)
|
||||
@@ -967,8 +974,19 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
def test_dataloader(self):
|
||||
r"""
|
||||
|
||||
Called by lightning during test loop. Make sure to use the @pl.data_loader decorator,
|
||||
this ensures not calling this function until the data are needed.
|
||||
Return a dataloader. It will not be called every epoch unless you set
|
||||
```Trainer(reload_dataloaders_every_epoch=True)```.
|
||||
|
||||
It's recommended that all data downloads and preparation happen in prepare_data().
|
||||
|
||||
- .fit()
|
||||
- ...
|
||||
- prepare_data()
|
||||
- train_dataloader
|
||||
- val_dataloader
|
||||
- test_dataloader
|
||||
|
||||
.. note:: Lightning adds the correct sampler for distributed and arbitrary hardware. No need to set yourself.
|
||||
|
||||
Return:
|
||||
PyTorch DataLoader
|
||||
@@ -978,7 +996,6 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@pl.data_loader
|
||||
def test_dataloader(self):
|
||||
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (1.0,))])
|
||||
dataset = MNIST(root='/path/to/mnist/', train=False, transform=transform, download=True)
|
||||
@@ -1000,8 +1017,18 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
def val_dataloader(self):
|
||||
r"""
|
||||
|
||||
Called by lightning during validation loop. Make sure to use the @pl.data_loader decorator,
|
||||
this ensures not calling this function until the data are needed.
|
||||
Return a dataloader. It will not be called every epoch unless you set
|
||||
```Trainer(reload_dataloaders_every_epoch=True)```.
|
||||
|
||||
It's recommended that all data downloads and preparation happen in prepare_data().
|
||||
|
||||
- .fit()
|
||||
- ...
|
||||
- prepare_data()
|
||||
- train_dataloader
|
||||
- val_dataloader
|
||||
|
||||
.. note:: Lightning adds the correct sampler for distributed and arbitrary hardware No need to set yourself.
|
||||
|
||||
Return:
|
||||
PyTorch DataLoader
|
||||
@@ -1011,7 +1038,6 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@pl.data_loader
|
||||
def val_dataloader(self):
|
||||
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (1.0,))])
|
||||
dataset = MNIST(root='/path/to/mnist/', train=False, transform=transform, download=True)
|
||||
@@ -1024,7 +1050,6 @@ class LightningModule(ABC, GradInformation, ModelIO, ModelHooks):
|
||||
return loader
|
||||
|
||||
# can also return multiple dataloaders
|
||||
@pl.data_loader
|
||||
def val_dataloader(self):
|
||||
return [loader_a, loader_b, ..., loader_n]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user