{"id":13478458,"url":"https://github.com/chr5tphr/zennit","last_synced_at":"2025-04-09T05:13:19.219Z","repository":{"id":37078271,"uuid":"311716183","full_name":"chr5tphr/zennit","owner":"chr5tphr","description":"Zennit is a high-level framework in Python using PyTorch for explaining/exploring neural networks using attribution methods like LRP.","archived":false,"fork":false,"pushed_at":"2024-07-19T16:44:06.000Z","size":2389,"stargazers_count":217,"open_issues_count":30,"forks_count":34,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-02T04:05:35.694Z","etag":null,"topics":["attribution","deep-learning","explainability","explainable-ai","feature-attribution","interpretability","interpretable-ai","interpretable-ml","lrp","machine-learning","python","pytorch","xai"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chr5tphr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-10T16:17:38.000Z","updated_at":"2025-03-26T02:31:52.000Z","dependencies_parsed_at":"2024-01-12T04:49:53.510Z","dependency_job_id":"c5f0388f-a9e2-43fb-8c2b-99301198844a","html_url":"https://github.com/chr5tphr/zennit","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chr5tphr%2Fzennit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chr5tphr%2Fzennit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chr5tphr%2Fzennit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chr5tphr%2Fzennit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chr5tphr","download_url":"https://codeload.github.com/chr5tphr/zennit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980843,"owners_count":21027808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attribution","deep-learning","explainability","explainable-ai","feature-attribution","interpretability","interpretable-ai","interpretable-ml","lrp","machine-learning","python","pytorch","xai"],"created_at":"2024-07-31T16:01:57.312Z","updated_at":"2025-04-09T05:13:19.190Z","avatar_url":"https://github.com/chr5tphr.png","language":"Python","funding_links":[],"categories":["Python","XAI Libraries for Vision/Vision-Language","Tools"],"sub_categories":["Interpretability/Explicability"],"readme":"# Zennit\n![Zennit-Logo](share/img/zennit.png)\n\n[![Documentation Status](https://readthedocs.org/projects/zennit/badge/?version=latest)](https://zennit.readthedocs.io/en/latest/?badge=latest)\n[![tests](https://github.com/chr5tphr/zennit/actions/workflows/tests.yml/badge.svg)](https://github.com/chr5tphr/zennit/actions/workflows/tests.yml)\n[![PyPI Version](https://img.shields.io/pypi/v/zennit)](https://pypi.org/project/zennit/)\n[![License](https://img.shields.io/pypi/l/zennit)](https://github.com/chr5tphr/zennit/blob/master/COPYING.LESSER)\n\nZennit (**Z**ennit **e**xplains **n**eural **n**etworks **i**n **t**orch) is a\nhigh-level framework in Python using Pytorch for explaining/exploring neural\nnetworks. Its design philosophy is intended to provide high customizability and\nintegration as a standardized solution for applying rule-based attribution\nmethods in research, with a strong focus on Layerwise Relevance Propagation\n(LRP). Zennit strictly requires models to use Pytorch's `torch.nn.Module`\nstructure (including activation functions).\n\nZennit is currently under active development, but should be mostly stable.\n\nIf you find Zennit useful for your research, please consider citing our related\n[paper](https://arxiv.org/abs/2106.13200):\n```\n@article{anders2021software,\n      author  = {Anders, Christopher J. and\n                 Neumann, David and\n                 Samek, Wojciech and\n                 Müller, Klaus-Robert and\n                 Lapuschkin, Sebastian},\n      title   = {Software for Dataset-wide XAI: From Local Explanations to Global Insights with {Zennit}, {CoRelAy}, and {ViRelAy}},\n      journal = {CoRR},\n      volume  = {abs/2106.13200},\n      year    = {2021},\n}\n```\n\n## Documentation\nThe latest documentation is hosted at\n[zennit.readthedocs.io](https://zennit.readthedocs.io/en/latest/).\n\n## Install\n\nTo install directly from PyPI using pip, use:\n```shell\n$ pip install zennit\n```\n\nAlternatively, install from a manually cloned repository to try out the examples:\n```shell\n$ git clone https://github.com/chr5tphr/zennit.git\n$ pip install ./zennit\n```\n\n## Usage\nAt its heart, Zennit registers hooks at Pytorch's Module level, to modify the\nbackward pass to produce rule-based attributions like LRP (instead of the usual\ngradient). All rules are implemented as hooks\n([`zennit/rules.py`](src/zennit/rules.py)) and most use the LRP basis\n`BasicHook` ([`zennit/core.py`](src/zennit/core.py)).\n\n**Composites** ([`zennit/composites.py`](src/zennit/composites.py)) are a way\nof choosing the right hook for the right layer. In addition to the abstract\n**NameMapComposite**, which assigns hooks to layers by name, and\n**LayerMapComposite**, which assigns hooks to layers based on their Type, there\nexist explicit **Composites**, some of which are `EpsilonGammaBox` (`ZBox` in\ninput, `Epsilon` in dense, `Gamma` in convolutions) or `EpsilonPlus` (`Epsilon`\nin dense, `ZPlus` in convolutions). All composites may be used by directly\nimporting from `zennit.composites`, or by using their snake-case name as key\nfor `zennit.composites.COMPOSITES`.\n\n**Canonizers** ([`zennit/canonizers.py`](src/zennit/canonizers.py)) temporarily\ntransform models into a canonical form, if required, like\n`SequentialMergeBatchNorm`, which automatically detects and merges BatchNorm\nlayers followed by linear layers in sequential networks, or\n`AttributeCanonizer`, which temporarily overwrites attributes of applicable\nmodules, e.g. to handle the residual connection in ResNet-Bottleneck modules.\n\n**Attributors** ([`zennit/attribution.py`](src/zennit/attribution.py)) directly\nexecute the necessary steps to apply certain attribution methods, like the\nsimple `Gradient`, `SmoothGrad` or `Occlusion`. An optional **Composite** may\nbe passed, which will be applied during the **Attributor**'s execution to\ncompute the modified gradient, or hybrid methods.\n\nUsing all of these components, an LRP-type attribution for VGG16 with\nbatch-norm layers with respect to label 0 may be computed using:\n\n```python\nimport torch\nfrom torchvision.models import vgg16_bn\n\nfrom zennit.composites import EpsilonGammaBox\nfrom zennit.canonizers import SequentialMergeBatchNorm\nfrom zennit.attribution import Gradient\n\n\ndata = torch.randn(1, 3, 224, 224)\nmodel = vgg16_bn()\n\ncanonizers = [SequentialMergeBatchNorm()]\ncomposite = EpsilonGammaBox(low=-3., high=3., canonizers=canonizers)\n\nwith Gradient(model=model, composite=composite) as attributor:\n    out, relevance = attributor(data, torch.eye(1000)[[0]])\n```\n\nA similar setup using [the example script](share/example/feed_forward.py)\nproduces the following attribution heatmaps:\n![beacon heatmaps](share/img/beacon_vgg16_epsilon_gamma_box.png)\n\nFor more details and examples, have a look at our\n[**documentation**](https://zennit.readthedocs.io/en/latest/).\n\n### More Example Heatmaps\nMore heatmaps of various attribution methods for VGG16 and ResNet50, all\ngenerated using\n[`share/example/feed_forward.py`](share/example/feed_forward.py), can be found\nbelow.\n\n\u003cdetails\u003e\n  \u003csummary\u003eHeatmaps for VGG16\u003c/summary\u003e\n\n  ![vgg16 heatmaps](share/img/beacon_vgg16_various.webp)\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eHeatmaps for ResNet50\u003c/summary\u003e\n\n  ![resnet50 heatmaps](share/img/beacon_resnet50_various.webp)\n\u003c/details\u003e\n\n## Contributing\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for detailed instructions on how to contribute.\n\n## License\nZennit is licensed under the GNU LESSER GENERAL PUBLIC LICENSE VERSION 3 OR\nLATER -- see the [LICENSE](LICENSE), [COPYING](COPYING) and\n[COPYING.LESSER](COPYING.LESSER) files for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchr5tphr%2Fzennit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchr5tphr%2Fzennit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchr5tphr%2Fzennit/lists"}