LayerLens is a powerful library for layer-by-layer explainability of deep learning models. It provides insights into how models make decisions by analyzing the behavior of individual layers.
- Layer-wise Explanation: Generate surrogate models for each layer to explain its behavior
- Hierarchical Insights: Stitch together layer explanations to understand the full model
- Interactive Visualization: Explore model behavior through an intuitive dashboard
- Production Monitoring: Detect drift and localize failures in deployed models
- Framework Agnostic: Works with PyTorch, TensorFlow, and other major frameworks
- Comprehensive Testing: Full test suite ensuring reliability and stability
# Clone the repository
git clone https://github.com/your-username/LayerLens.git
cd LayerLens
# Install dependencies
pip install -r requirements.txt
# Install LayerLens
pip install -e .pip install layerlensNote: You'll also need to install at least one ML framework:
pip install torch # For PyTorch support
# or
pip install tensorflow # For TensorFlow supportfrom layerlens import Explainer
import numpy as np
# Load your trained model (PyTorch or TensorFlow)
# model = ... (your trained model)
# Create a LayerLens explainer
explainer = Explainer(model)
# Prepare your data
input_data = np.random.rand(10, 28, 28, 1) # Example
# Generate explanations
explanation = explainer.explain(input_data)
# Visualize the results
explainer.visualize(explanation, output_dir='./explanations')
# Monitor for drift (production use)
explainer.monitor(input_data)Try the MNIST demo to see LayerLens in action:
cd examples
jupyter notebook mnist_demo.ipynbVerify your installation is working correctly:
python tests/verify_installation.pyRun the full test suite:
pytest tests/For detailed documentation and usage guides:
- USAGE.md - Complete usage guide with examples
- docs/ - Technical documentation and theory
- examples/ - Jupyter notebook demos
LayerLens/
├── layerlens/ # Main package
│ ├── core/ # Core explainability engine
│ ├── visualization/ # Interactive dashboards and plots
│ ├── monitoring/ # Production monitoring tools
│ └── utils/ # Helper utilities
├── examples/ # Demo notebooks
├── tests/ # Test suite
└── docs/ # Documentation
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use LayerLens in your research, please cite:
@software{layerlens,
title = {LayerLens: Layer-by-Layer Explainability for Deep Learning},
author = {navi-04},
year = {2025},
url = {https://github.com/navi-04/LayerLens}
}D:/GitHub/LayerLens/.venv/Scripts/python.exe -m jupyter notebook mnist_demo.ipynb