Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

KerasCallback

Base R6 class for Keras callbacks


Description

Base R6 class for Keras callbacks

Format

An R6Class generator object

Details

The logs named list that callback methods take as argument will contain keys for quantities relevant to the current batch or epoch.

Currently, the fit.keras.engine.training.Model() method for sequential models will include the following quantities in the logs that it passes to its callbacks:

  • on_epoch_end: logs include acc and loss, and optionally include val_loss (if validation is enabled in fit), and val_acc (if validation and accuracy monitoring are enabled).

  • on_batch_begin: logs include size, the number of samples in the current batch.

  • on_batch_end: logs include loss, and optionally acc (if accuracy monitoring is enabled).

Value

Fields

params

Named list with training parameters (eg. verbosity, batch size, number of epochs...).

model

Reference to the Keras model being trained.

Methods

on_epoch_begin(epoch, logs)

Called at the beginning of each epoch.

on_epoch_end(epoch, logs)

Called at the end of each epoch.

on_batch_begin(batch, logs)

Called at the beginning of each batch.

on_batch_end(batch, logs)

Called at the end of each batch.

on_train_begin(logs)

Called at the beginning of training.

on_train_end(logs)

Called at the end of training.

Examples

## Not run: 
library(keras)

LossHistory <- R6::R6Class("LossHistory",
  inherit = KerasCallback,
  
  public = list(
  
    losses = NULL,

    on_batch_end = function(batch, logs = list()) {
      self$losses <- c(self$losses, logs[["loss"]])
    }
  )
)

## End(Not run)

keras

R Interface to 'Keras'

v2.4.0
MIT + file LICENSE
Authors
Daniel Falbel [ctb, cph, cre], JJ Allaire [aut, cph], François Chollet [aut, cph], RStudio [ctb, cph, fnd], Google [ctb, cph, fnd], Yuan Tang [ctb, cph] (<https://orcid.org/0000-0001-5243-233X>), Wouter Van Der Bijl [ctb, cph], Martin Studer [ctb, cph], Sigrid Keydana [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.