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

KerasConstraint

Base R6 class for Keras constraints


Description

Base R6 class for Keras constraints

Format

An R6Class generator object

Details

You can implement a custom constraint either by creating an R function that accepts a weights (w) parameter, or by creating an R6 class that derives from KerasConstraint and implements a call method.

Methods

call(w)

Constrain the specified weights.

Note

Models which use custom constraints cannot be serialized using save_model_hdf5(). Rather, the weights of the model should be saved and restored using save_model_weights_hdf5().

See Also

Examples

## Not run: 
CustomNonNegConstraint <- R6::R6Class(
  "CustomNonNegConstraint",
  inherit = KerasConstraint,
  public = list(
    call = function(x) {
       w * k_cast(k_greater_equal(w, 0), k_floatx())
    }
  )
)

layer_dense(units = 32, input_shape = c(784), 
            kernel_constraint = CustomNonNegConstraint$new())

## 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.