How poloclub/cnn-explainer works
Purpose and runtime
CNN Explainer is a client-side interactive educational visualization for explaining CNN inference and concepts to non-experts. It is a Svelte application bundled with Rollup and served as static assets, including a pretrained model and visualization data. Primary browser entry points are public/index.html, src/main.js, and src/App.svelte.
Application composition
src/App.svelte is the top-level coordinator for the explainer UI. It assembles persistent navigation/content and switches between the network overview and layer-level explanations:
• src/Header.svelte
• src/Explainer.svelte
• src/config.js
Shared reactive application state is centralized in src/stores.js, forming the coordination boundary between overview interactions, selected layers/features, and detail panels.
CNN model and inference boundary
The browser-side CNN integration lives in src/utils/cnn-tf.js and src/utils/cnn.js. These modules load/use the packaged model data and expose CNN computations to the visual layers rather than calling a backend service. Model artifacts are static public assets:
• public/assets/data/model.json
• public/assets/data/group1-shard1of1.bin
• public/assets/data/nn_10.json
The separate training provenance is a Python/TensorFlow-style Tiny VGG project, not part of the browser runtime:
• tiny-vgg/tiny-vgg.py
• tiny-vgg/environment.yaml
• tiny-vgg/data.zip
Network overview stage
The overview provides the high-level CNN pipeline and interactive selection/navigation into individual operations. Rendering and geometry are separated into drawing-focused modules:
• src/overview/Overview.svelte
• src/overview/overview-draw.js
• src/overview/intermediate-draw.js
src/overview/intermediate-utils.js and src/overview/flatten-draw.js support layer/intermediate representation display, while src/overview/Modal.svelte handles contextual overlay interaction. This stage consumes model/intermediate state and updates shared stores to drive detail views.
Layer-detail visualization stage
The detail-view subsystem explains the selected CNN operation with operation-specific Svelte panels and animations. Architecturally important operation families are:
• Convolution: src/detail-view/Convolutionview.svelte, src/detail-view/ConvolutionAnimator.svelte
• Activation/pooling: src/detail-view/Activationview.svelte, src/detail-view/Poolview.svelte
• Classification/math: src/detail-view/Softmaxview.svelte, src/detail-view/KernelMathView.svelte
src/detail-view/Dataview.svelte and src/detail-view/DetailviewUtils.js provide common presentation/data behavior. Hyperparameter-specific interactions are isolated in Hyperparameterview.svelte, HyperparameterDataview.svelte, and HyperparameterAnimator.svelte.
Educational narrative and media
The explainer combines interactive model views with article-style instructional content:
• src/article/Article.svelte
• src/article/Youtube.svelte
• src/Explainer.svelte
This is a presentation boundary: article/media content explains concepts, while overview/detail modules render interactive computation and state.
Delivery and infrastructure
The deployable artifact is static hosting compatible with GitHub Pages. Build/development orchestration is defined by:
• package.json
• rollup.config.js
• rollup_start_dev.js
GitHub Actions runs the build at .github/workflows/build.yml; deploy-gh-page.sh supports publishing. Public styles, images, fonts, figures, and model data are delivered directly from public/, with no indicated server API or database dependency.
Main entry points: Explainer.svelte Explainer composition · Overview.svelte Network overview · App.svelte App coordinator · rollup.config.js Rollup build
Components 18
Browser application
Client-side Svelte explainer.
- Browser entry
public/index.html - Svelte bootstrap
src/main.js - App coordinator · Assembles navigation and explainer views.
src/App.svelte - Header and config
src/Header.svelte - Explainer composition · Combines interactive and educational content.
src/Explainer.svelte - Shared reactive state · Coordinates selection, features, and detail panels.
src/stores.js - Network overview · CNN pipeline navigation and layer selection.
src/overview/Overview.svelte - Overview rendering · Draws network geometry and intermediate representations.
src/overview/overview-draw.js - Overview modal
src/overview/Modal.svelte - Operation detail views · Convolution, activation, pooling, softmax, and kernel math explanations.
src/detail-view/Convolutionview.svelte - Hyperparameter interaction
src/detail-view/Hyperparameterview.svelte - Article and media · Narrative concepts and embedded video.
src/article/Article.svelte
CNN runtime
Packaged inference and visualization data.
- CNN integration · Loads packaged model data and exposes CNN computations.
src/utils/cnn-tf.js - Packaged model artifacts · TensorFlow model, weights, and network visualization data.
public/assets/data/model.json
Model provenance
Separate Tiny VGG training project.
- Tiny VGG training · Offline training provenance; not browser runtime.
tiny-vgg/tiny-vgg.py
Build and delivery
Static-site build and publishing.
- Rollup build · Bundles the Svelte application into static assets.
rollup.config.js - GitHub Actions build
.github/workflows/build.yml - Static hosting · GitHub Pages-compatible published assets.
deploy-gh-page.sh
Connections 18
- Browser entry → Svelte bootstrap: loads
- Svelte bootstrap → App coordinator: mounts
- App coordinator → Header and config: renders
- App coordinator → Explainer composition: renders
- Explainer composition → Network overview: shows overview
- Explainer composition → Operation detail views: shows selected operation
- Explainer composition → Article and media: presents narrative
- Network overview → Overview rendering: draws with
- Network overview → Overview modal: opens
- Network overview → Shared reactive state: updates selection
- Shared reactive state → Operation detail views: drives selected layer
- Operation detail views → Hyperparameter interaction: includes
- CNN integration → Packaged model artifacts: loads
- CNN integration → Shared reactive state: provides CNN state
- Packaged model artifacts → Tiny VGG training: produced by
- Rollup build → Browser entry: packages
- GitHub Actions build → Rollup build: runs
- Rollup build → Static hosting: publishes static assets