Keras Model composed of a linear stack of layers
keras_model_sequential(
input_shape = NULL,
name = NULL,
...,
input_dtype = NULL,
input_batch_size = NULL,
input_sparse = NULL,
input_batch_shape = NULL,
input_name = NULL,
input_tensor = NULL,
input_optional = FALSE,
trainable = TRUE,
layers = list()
)
A Sequential
model instance.
A shape integer vector,
not including the batch size.
For instance, shape=c(32)
indicates that the expected input
will be batches of 32-dimensional vectors. Elements of this shape
can be NA
; NA
elements represent dimensions where the shape
is not known and may vary (e.g. sequence length).
Name of model
additional arguments passed on to keras.layers.InputLayer
.
The data type expected by the input, as a string
(e.g. "float32"
, "int32"
...)
Optional static batch size (integer).
A boolean specifying whether the expected input will be sparse
tensors. Note that, if sparse
is FALSE
, sparse tensors can still
be passed into the input - they will be densified with a default
value of 0
. This feature is only supported with the TensorFlow
backend. Defaults to FALSE
.
An optional way to specify batch_size
and input_shape
as one argument.
Optional name string for the input layer. Should be unique in a model (do not reuse the same name twice). It will be autogenerated if it isn't provided.
Optional existing tensor to wrap into the InputLayer
.
If set, the layer will use this tensor rather
than creating a new placeholder tensor.
Boolean, whether the input is optional or not.
An optional input can accept NULL
values.
Boolean, whether the model's variables should be trainable.
You can also change the trainable status of a model/layer with
freeze_weights()
and unfreeze_weights()
.
List of layers to add to the model.
model <- keras_model_sequential(input_shape = c(784))
model |>
layer_dense(units = 32) |>
layer_activation('relu') |>
layer_dense(units = 10) |>
layer_activation('softmax')model |> compile(
optimizer = 'rmsprop',
loss = 'categorical_crossentropy',
metrics = c('accuracy')
)
model
## Model: "sequential"
## +---------------------------------+------------------------+---------------+
## | Layer (type) | Output Shape | Param # |
## +=================================+========================+===============+
## | dense (Dense) | (None, 32) | 25,120 |
## +---------------------------------+------------------------+---------------+
## | activation (Activation) | (None, 32) | 0 |
## +---------------------------------+------------------------+---------------+
## | dense_1 (Dense) | (None, 10) | 330 |
## +---------------------------------+------------------------+---------------+
## | activation_1 (Activation) | (None, 10) | 0 |
## +---------------------------------+------------------------+---------------+
## Total params: 25,450 (99.41 KB)
## Trainable params: 25,450 (99.41 KB)
## Non-trainable params: 0 (0.00 B)
Other model functions:
get_config()
get_layer()
get_state_tree()
keras_model()
pop_layer()
set_state_tree()
summary.keras.src.models.model.Model()
Other model creation:
keras_input()
keras_model()