Description Format Details Methods Note See Also Examples
Base R6 class for Keras constraints
An R6Class generator object
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.
call(w)
Constrain the specified weights.
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()
.
constraints
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ## 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.