Layer | R Documentation |
This function is maintained but deprecated. Please use new_layer_class()
or
%py_class%
to define custom layers.
Layer(
classname,
initialize,
build = NULL,
call = NULL,
compute_output_shape = NULL,
...,
inherit = keras::keras$layers$Layer
)
classname |
the name of the custom Layer. |
initialize |
a function. This is where you define the arguments used to further
build your layer. For example, a dense layer would take the |
build |
a function that takes |
call |
This is where the layer's logic lives. Unless you want your layer to
support masking, you only have to care about the first argument passed to |
compute_output_shape |
a function that takes |
... |
Any other methods and/or attributes can be specified using named arguments. They will be added to the layer class. |
inherit |
the Keras layer to inherit from. |
A function that wraps create_layer
, similar to keras::layer_dense
.
## Not run:
layer_dense2 <- Layer(
"Dense2",
initialize = function(units) {
super()$`__init__`()
self$units <- as.integer(units)
},
build = function(input_shape) {
print(class(input_shape))
self$kernel <- self$add_weight(
name = "kernel",
shape = list(input_shape[[2]], self$units),
initializer = "uniform",
trainable = TRUE
)
},
call = function(x) {
tensorflow::tf$matmul(x, self$kernel)
},
compute_output_shape = function(input_shape) {
list(input_shape[[1]], self$units)
}
)
l <- layer_dense2(units = 10)
l(matrix(runif(10), ncol = 1))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.