Implementation of Concept Relevance Propagation with pytorch. check crp_notebook.ipynb for use case.
- The implemented CRP method is in the paper From "Where" to "What": Towards Human-Understandable Explanations through Concept Relevance Propagation
📦crp_pytorch
┣ 📂 src # includes all python files
┃ ┣ 📂 lrp # inclues lrp implementation
┃ ┃ ┣ 📂 modules
┃ ┃ ┃ ┣ 🐍 __init__.py
┃ ┃ ┃ ┣ 🐍 activation.py
┃ ┃ ┃ ┣ 🐍 conv2d.py # 🚀 CRP is implemented by masking here!
┃ ┃ ┃ ┣ 🐍 dropout.py
┃ ┃ ┃ ┣ 🐍 flatten.py
┃ ┃ ┃ ┣ 🐍 input.py
┃ ┃ ┃ ┣ 🐍 linear.py
┃ ┃ ┃ ┣ 🐍 pool.py
┃ ┃ ┃ ┗ 🐍 utils.py
┃ ┃ ┗ 🐍 __init__.py
┃ ┣ 🐍 data.py # ImageNet transform
┃ ┗ 🐍 lrp_for_vgg.py # construct lrp model for vgg 16
┣ 📜 .gitignore
┣ 🪙 LICENSE
┣ 📖 README.md
┣ 🏙 image.png
┗ 🪐crp_notebook.ipynb
Find the lines below in crp_notebook.ipynb,
Download ImageNet dataset or modify it for any other dataset.
# ============================================
# change!
data_path = "/data3/bumjin_data/ILSVRC2012_val"
testset = torchvision.datasets.ImageNet(root=data_path, split="val")
# ============================================
# ===================================
# Which CNN layer / CNN filter index / samples?
layer = 0
conept_ids = [43,44,45,46] # CNN filter indexes
samples = [5373, 5568, 5367, 5396, 5357] + [5586,5577,1411,5494,3391] # samples you want to check
# ===================================