Shortcuts

Source code for pytorch_lightning.callbacks.base

# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

r"""
Abstract base class used to build new callbacks.

"""

import abc


[docs]class Callback(abc.ABC): r""" Abstract base class used to build new callbacks. Subclass this class and override any of the relevant hooks """
[docs] def setup(self, trainer, pl_module, stage: str): """Called when fit or test begins""" pass
[docs] def teardown(self, trainer, pl_module, stage: str): """Called when fit or test ends""" pass
[docs] def on_init_start(self, trainer): """Called when the trainer initialization begins, model has not yet been set.""" pass
[docs] def on_init_end(self, trainer): """Called when the trainer initialization ends, model has not yet been set.""" pass
[docs] def on_fit_start(self, trainer, pl_module): """Called when fit begins""" pass
[docs] def on_fit_end(self, trainer, pl_module): """Called when fit ends""" pass
[docs] def on_sanity_check_start(self, trainer, pl_module): """Called when the validation sanity check starts.""" pass
[docs] def on_sanity_check_end(self, trainer, pl_module): """Called when the validation sanity check ends.""" pass
[docs] def on_train_batch_start(self, trainer, pl_module, batch, batch_idx, dataloader_idx): """Called when the train batch begins.""" pass
[docs] def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx, dataloader_idx): """Called when the train batch ends.""" pass
[docs] def on_train_epoch_start(self, trainer, pl_module): """Called when the train epoch begins.""" pass
[docs] def on_train_epoch_end(self, trainer, pl_module, outputs): """Called when the train epoch ends.""" pass
[docs] def on_validation_epoch_start(self, trainer, pl_module): """Called when the val epoch begins.""" pass
[docs] def on_validation_epoch_end(self, trainer, pl_module): """Called when the val epoch ends.""" pass
[docs] def on_test_epoch_start(self, trainer, pl_module): """Called when the test epoch begins.""" pass
[docs] def on_test_epoch_end(self, trainer, pl_module): """Called when the test epoch ends.""" pass
[docs] def on_epoch_start(self, trainer, pl_module): """Called when the epoch begins.""" pass
[docs] def on_epoch_end(self, trainer, pl_module): """Called when the epoch ends.""" pass
[docs] def on_batch_start(self, trainer, pl_module): """Called when the training batch begins.""" pass
[docs] def on_validation_batch_start(self, trainer, pl_module, batch, batch_idx, dataloader_idx): """Called when the validation batch begins.""" pass
[docs] def on_validation_batch_end(self, trainer, pl_module, outputs, batch, batch_idx, dataloader_idx): """Called when the validation batch ends.""" pass
[docs] def on_test_batch_start(self, trainer, pl_module, batch, batch_idx, dataloader_idx): """Called when the test batch begins.""" pass
[docs] def on_test_batch_end(self, trainer, pl_module, outputs, batch, batch_idx, dataloader_idx): """Called when the test batch ends.""" pass
[docs] def on_batch_end(self, trainer, pl_module): """Called when the training batch ends.""" pass
[docs] def on_train_start(self, trainer, pl_module): """Called when the train begins.""" pass
[docs] def on_train_end(self, trainer, pl_module): """Called when the train ends.""" pass
[docs] def on_pretrain_routine_start(self, trainer, pl_module): """Called when the pretrain routine begins.""" pass
[docs] def on_pretrain_routine_end(self, trainer, pl_module): """Called when the pretrain routine ends.""" pass
[docs] def on_validation_start(self, trainer, pl_module): """Called when the validation loop begins.""" pass
[docs] def on_validation_end(self, trainer, pl_module): """Called when the validation loop ends.""" pass
[docs] def on_test_start(self, trainer, pl_module): """Called when the test begins.""" pass
[docs] def on_test_end(self, trainer, pl_module): """Called when the test ends.""" pass
[docs] def on_keyboard_interrupt(self, trainer, pl_module): """Called when the training is interrupted by KeyboardInterrupt.""" pass
[docs] def on_save_checkpoint(self, trainer, pl_module): """Called when saving a model checkpoint, use to persist state.""" pass
[docs] def on_load_checkpoint(self, checkpointed_state): """Called when loading a model checkpoint, use to reload state.""" pass

© Copyright Copyright (c) 2018-2020, William Falcon et al... Revision 0979e2ce.

Built with Sphinx using a theme provided by Read the Docs.