Inspect layers and output shapes
Reviewing architecture during model construction
Keras · Module
Prints a readable summary of a built Keras model, including its layers and network information. Options can expand nested models, show trainability, redirect output, and restrict the displayed layer range.
Call summary() on a built Keras model to print a readable network overview. Optional arguments control line width, column positions, output handling, nested-model expansion, trainability display, and the layer range included.
Model.summary(line_length=None, positions=None, print_fn=None, expand_nested=False, show_trainable=False, layer_range=None)| Name | Type | Description |
|---|---|---|
line_length | int | None | Total length of printed lines; defaults to None. |
positions | list | None | Relative or absolute positions of log elements in each line; defaults to None. |
print_fn | callable | None | Function used to output each summary line; defaults to standard output. |
expand_nested | bool | Whether to expand nested models; defaults to False. |
show_trainable | bool | Whether to show layer trainability; defaults to False. |
layer_range | list | tuple | None | Two layer names or regular-expression patterns defining the inclusive printed range; defaults to None. |
Prints the model summary; the documentation does not specify a return value.
import keras
model = keras.Sequential([
keras.Input(shape=(4,)),
keras.layers.Dense(3, activation="relu"),
keras.layers.Dense(1),
])
model.summary(show_trainable=True)Creates a built Sequential model and prints its layer, output-shape, parameter, and trainability information.
Reviewing architecture during model construction
Debugging an unexpected network
Auditing transfer-learning setup
Documenting or logging a model
summary() prints a textual overview of the network. It reports the layers and their output shapes, parameter counts, and can also show whether layers are trainable when show_trainable=True.
Follow-up: How would you inspect only part of a large model? Pass layer_range as a two-element list or tuple containing the starting and ending layer names; both endpoints are included.
The method accepts line_length to control the total line width and positions to control the relative or absolute column locations. If positions is omitted, Keras uses its documented default column positions.
Follow-up: How can the summary be captured rather than printed? Supply print_fn with a custom function; Keras calls it once for each summary line.
expand_nested=True expands nested models in the displayed report, while show_trainable=True adds trainability information for layers. Both options default to False.
Follow-up: Can layer_range use patterns instead of literal names? Yes. It accepts regular-expression patterns and selects the first matching start and last matching end.
Modelmodel.layersplot_modelkeras.Sequential