mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-12 12:40:20 +08:00
@@ -4,7 +4,7 @@ Early stopping
|
||||
Default behavior
|
||||
----------------
|
||||
By default early stopping will be enabled if `'val_loss'`
|
||||
is found in `validation_end()` return dict. Otherwise
|
||||
is found in `validation_epoch_end()` return dict. Otherwise
|
||||
training will proceed with early stopping disabled.
|
||||
|
||||
Enable Early Stopping
|
||||
@@ -16,7 +16,7 @@ There are two ways to enable early stopping.
|
||||
.. code-block:: python
|
||||
|
||||
# A) Set early_stop_callback to True. Will look for 'val_loss'
|
||||
# in validation_end() return dict. If it is not found an error is raised.
|
||||
# in validation_epoch_end() return dict. If it is not found an error is raised.
|
||||
trainer = Trainer(early_stop_callback=True)
|
||||
|
||||
# B) Or configure your own callback
|
||||
|
||||
@@ -87,7 +87,7 @@ Here we show the validation loss in the progress bar
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def validation_end(self, outputs):
|
||||
def validation_epoch_end(self, outputs):
|
||||
loss = some_loss()
|
||||
...
|
||||
|
||||
|
||||
@@ -603,7 +603,7 @@ sample split in the `train_dataloader` method.
|
||||
loss = F.nll_loss(logits, y)
|
||||
return {'val_loss': loss}
|
||||
|
||||
def validation_end(self, outputs):
|
||||
def validation_epoch_end(self, outputs):
|
||||
avg_loss = torch.stack([x['val_loss'] for x in outputs]).mean()
|
||||
tensorboard_logs = {'val_loss': avg_loss}
|
||||
return {'avg_val_loss': avg_loss, 'log': tensorboard_logs}
|
||||
@@ -657,7 +657,7 @@ Just like the validation loop, we define exactly the same steps for testing:
|
||||
loss = F.nll_loss(logits, y)
|
||||
return {'val_loss': loss}
|
||||
|
||||
def test_end(self, outputs):
|
||||
def test_epoch_end(self, outputs):
|
||||
avg_loss = torch.stack([x['val_loss'] for x in outputs]).mean()
|
||||
tensorboard_logs = {'val_loss': avg_loss}
|
||||
return {'avg_val_loss': avg_loss, 'log': tensorboard_logs}
|
||||
|
||||
Reference in New Issue
Block a user