Skip to main content

dead-relu-viz

Visualize dead ReLU neurons directly on a PyTorch model's architecture graph.

A dead neuron is one whose activation never leaves zero across an entire dataset — a common failure mode after a bad weight init or too high a learning rate. dead-relu-viz propagates your data through your model, measures which Conv2d/Linear units never activate, and overlays the result on the model's architecture graph (built with torchview), so you can spot where dead neurons are concentrated at a glance.

Works with any PyTorch nn.Module and any DataLoader — not tied to a specific model or dataset.

Installation

pip install dead-relu-viz

Graphviz must also be installed on your system (it's what torchview uses to render the graph):

apt install graphviz      # Debian/Ubuntu
brew install graphviz     # macOS

Usage

In a Jupyter notebook:

from dead_relu_viz import visualization

# model: any PyTorch nn.Module
# data_loader: any DataLoader
visualization(model, data_loader, with_activation=True, dpi=300)

This displays the model's architecture graph inline, with each Conv2d/Linear layer that contains dead neurons highlighted in red and annotated with the count and percentage of dead units.

Call it with with_activation=False (the default) to just render the plain architecture graph, without running any data through the model.

Arguments

  • model — any PyTorch model (nn.Module).
  • data — a DataLoader used to measure activations.
  • with_activationFalse (default): plain torchview graph. True: graph annotated with dead neurons in red.
  • device — device used to run the model when measuring activations (defaults to CUDA if available, else CPU).
  • dpi — if set, overrides the graph's rendering resolution (e.g. dpi=300).
  • exclude_from_dead_check — layer names (as in model.named_modules()) to skip when coloring dead neurons — still measured and printed, just not flagged red. Useful for layers where "dead" isn't meaningful (e.g. a layer followed by a sigmoid instead of a ReLU).

Example

See cnn-activations for two worked examples (a small CNN trained on CIFAR-10, and GMIC, a breast-cancer screening model) using this tool.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dead_relu_viz-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dead_relu_viz-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file dead_relu_viz-0.1.0.tar.gz.

File metadata

  • Download URL: dead_relu_viz-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for dead_relu_viz-0.1.0.tar.gz
Algorithm Hash digest
SHA256 485dc37c7456761b7bddd5b9fc68f8a9fcbadc623c5add4201b50e6d23f4d05f
MD5 7bc36059cd94344ea4ae5d698515ebea
BLAKE2b-256 e28b6aab0ac21ff84dcc2072bbbaa96c92d395b36ae22f6e1dc392c9a214fd64

See more details on using hashes here.

File details

Details for the file dead_relu_viz-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dead_relu_viz-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.3

File hashes

Hashes for dead_relu_viz-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 941da900ee99fab2a64493862c4e6a3860c6008e1d648c26f89617e5fdfbb7b8
MD5 2d7e8ca1125d3dd2e3fcfc56209ef640
BLAKE2b-256 73622d699dd0267c027e16cf042dbf9b4c12df00910820c13d6765dd50618611

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page