About Keras Models

Overview

There are two types of models available in Keras: sequential models and models created with the functional API.

Sequential

Sequential models are created using the keras_model_sequential() function and are composed of a set of linear layers:

Note that Keras objects are modified in place which is why it’s not necessary for model to be assigned back to after the layers are added.

Learn more by reading the Guide to the Sequential Model.

Functional

The functional API enables you to define more complex models, such as multi-output models, directed acyclic graphs, or models with shared layers. To create a model with the functional API compose a set of input and output layers then pass them to the keras_model() function:

Learn more by reading the Guide to the Functional API.

Properties

All models share the following properties:

Functions

These functions enable you to create, train, evaluate, persist, and generate predictions with models:

keras_model()

Keras Model

keras_model_sequential()

Keras Model composed of a linear stack of layers

compile()

Configure a Keras model for training

fit()

Train a Keras model

evaluate()

Evaluate a Keras model

predict()

Predict Method for Keras Models

summary()

Print a summary of a model

save_model_hdf5() load_model_hdf5()

Save/Load models using HDF5 files

get_layer()

Retrieves a layer based on either its name (unique) or index.

pop_layer()

Remove the last layer in a model

save_model_weights_hdf5() load_model_weights_hdf5()

Save/Load model weights using HDF5 files

get_weights() set_weights()

Layer/Model weights as R arrays

get_config() from_config()

Layer/Model configuration

model_to_json() model_from_json()

Model configuration as JSON

model_to_yaml() model_from_yaml()

Model configuration as YAML