Keras activation surgery: peek inside the black box
A small Python library that extracts and visualizes every layer output and gradient in a Keras model without rewriting your network.

What it does Keract hooks into a compiled Keras model and returns the activations (outputs) and gradients for every layer as plain NumPy arrays. It also ships helpers to plot those activations or overlay them as heatmaps on input images, plus JSON serialization so you can stash intermediate results for later inspection.
The interesting bit
The library sidesteps the usual TensorFlow graph-tinkering by auto-compiling models if needed and offering a nested=True flag to recurse into sub-models—though the README admits this last part is where “extremely tricky” meets “not well supported.”
Key highlights
- Works with multi-input models, LSTMs, and standard conv nets out of the box.
- Three output key formats: simple layer names, full TensorFlow node names, or plain numeric indices.
- Heatmap mode overlays activation strength on the original image, with per-filter or merged-filter views.
- Can persist activations to JSON and reload them—handy for comparing runs.
- Explicitly tested through TensorFlow 2.15 (Nov 2023).
Caveats
- Stuck in the past: Not compatible with TensorFlow 2.16+; the author is actively looking for contributors to modernize it.
- Nested models are brittle: Sub-models (e.g., Sequential inside Sequential) may break, and the README warns that recent TensorFlow versions made reliable layer-output extraction harder.
Verdict Grab it if you’re on TF ≤2.15 and need quick, no-fuss activation debugging without building custom callback hooks. Skip it if you’re on current TensorFlow or rely heavily on nested model architectures.