keras_model_sequential {keras3} | R Documentation |
Keras Model composed of a linear stack of layers
Description
Keras Model composed of a linear stack of layers
Usage
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()
)
Arguments
input_shape |
A shape integer vector,
not including the batch size.
For instance, |
name |
Name of model |
... |
additional arguments passed on to |
input_dtype |
The data type expected by the input, as a string
(e.g. |
input_batch_size |
Optional static batch size (integer). |
input_sparse |
A boolean specifying whether the expected input will be sparse
tensors. Note that, if |
input_batch_shape |
An optional way to specify |
input_name |
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. |
input_tensor |
Optional existing tensor to wrap into the |
input_optional |
Boolean, whether the input is optional or not.
An optional input can accept |
trainable |
Boolean, whether the model's variables should be trainable.
You can also change the trainable status of a model/layer with
|
layers |
List of layers to add to the model. |
Value
A Sequential
model instance.
Examples
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)
Note
If input_shape
is omitted, then the model layer
shapes, including the final model output shape, will not be known until
the model is built, either by calling the model with an input tensor/array
like model(input)
, (possibly via fit()
/evaluate()
/predict()
), or by
explicitly calling model$build(input_shape)
.
See Also
Other model functions:
get_config()
get_layer()
keras_model()
pop_layer()
summary.keras.src.models.model.Model()
Other model creation:
keras_input()
keras_model()