Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Keras · Module

model.summary

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.

How it works

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.

Syntax

Model.summary(line_length=None, positions=None, print_fn=None, expand_nested=False, show_trainable=False, layer_range=None)

Parameters

NameTypeDescription
line_lengthint | NoneTotal length of printed lines; defaults to None.
positionslist | NoneRelative or absolute positions of log elements in each line; defaults to None.
print_fncallable | NoneFunction used to output each summary line; defaults to standard output.
expand_nestedboolWhether to expand nested models; defaults to False.
show_trainableboolWhether to show layer trainability; defaults to False.
layer_rangelist | tuple | NoneTwo layer names or regular-expression patterns defining the inclusive printed range; defaults to None.

Returns

Prints the model summary; the documentation does not specify a return value.

Key points

  • summary() produces a textual representation of the model architecture.
  • Use line_length to fit the report to a terminal or other display width.
  • positions controls column placement and defaults to the documented four relative positions when omitted.
  • A custom print_fn receives each generated summary line, enabling collection or redirection.
  • Set expand_nested to include the internal layers of nested models in the report.
  • Set show_trainable to add each layer's trainability status.

Common mistakes

  • The model must be built before calling summary(); otherwise Keras raises ValueError.
  • When the default standard-output destination is unsuitable, provide an alternative print_fn.

Example: Print a model summary

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.

When to use it

Inspect layers and output shapes

Reviewing architecture during model construction

Check model structure and dimensions

Debugging an unexpected network

Verify trainable layers

Auditing transfer-learning setup

Capture the textual report

Documenting or logging a model

Interview questions

QWhat does Model.summary() provide?

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.

QHow can summary formatting and output be controlled?

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.

QHow are nested models and trainability represented?

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.

  • Model
  • model.layers
  • plot_model
  • keras.Sequential

Source: The Model class - Keras. Checked 2026-10-15.