C.W.K.
Stream
Lesson 06 of 07 · published

Inspecting the Graph

~10 min · functional

Level 0Keras Apprentice
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

The graph is data you can read

Because a Functional model is a static DAG rather than imperative code, the graph is a first-class object you can inspect and debug — no need to run a forward pass to find out what your model actually built. The Code block shows the three tools you'll reach for, in increasing power:

  • model.summary() — the text table: every layer, its output shape, and parameter count. Fastest sanity check; catches the classic 'wait, why is this shape (None, 1)?' bugs.
  • keras.utils.plot_model(...) — renders the actual DAG as an image, with shapes on the edges. This is where branches and skips become legible in a way text never will be.
  • Intermediate-output models — the power move: build a throwaway keras.Model from model.input to any inner layer's .output and call predict on it. You get the activations at that point in the graph, which is how you debug 'where did the values go NaN?' without touching the original model.

The gotcha

plot_model isn't pure Python — it shells out to Graphviz via the pydot package. If you only pip install keras, the call fails with a cryptic 'failed to import pydot' error. Install both (pip install pydot and the system Graphviz binary) before you rely on it, especially in a fresh container or CI.

Code

Three ways to inspect a Functional graph·python
# Print architecture
model.summary()

# Generate a diagram (requires pydot/graphviz)
keras.utils.plot_model(model, show_shapes=True, show_layer_names=True)

# Inspect intermediate outputs for debugging
intermediate_model = keras.Model(
    inputs=model.input,
    outputs=model.get_layer("dense_2").output,
)
intermediate_output = intermediate_model.predict(sample_data)

External links

Exercise

Take your siamese or ResNet block from earlier. Generate plot_model output. Examine the graph visually — does it match what you intended?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.