Giter Club home page Giter Club logo

karol-g / gcam Goto Github PK

View Code? Open in Web Editor NEW
50.0 3.0 6.0 92.52 MB

Gcam is an easy to use Pytorch library that makes model predictions more interpretable for humans. It allows the generation of attention maps with multiple methods like Guided Backpropagation, Grad-Cam, Guided Grad-Cam and Grad-Cam++.

License: MIT License

Python 100.00%
pytorch gradcam gradcam-plus-plus grad-cam guided-backpropagation guidedgradcam visualization saliency cnn-visualization guided-grad-cam

gcam's Introduction

Gcam (Grad-Cam)

License Docs PyPI version Python package

New version of this repo at https://github.com/MECLabTUDA/M3d-Cam

Gcam is an easy to use Pytorch library that makes model predictions more interpretable for humans. It allows the generation of attention maps with multiple methods like Guided Backpropagation, Grad-Cam, Guided Grad-Cam and Grad-Cam++.
All you need to add to your project is a single line of code:

model = gcam.inject(model, output_dir="attention_maps", save_maps=True)

Features

  • Works with classification and segmentation data / models
  • Works with 2D and 3D data
  • Supports Guided Backpropagation, Grad-Cam, Guided Grad-Cam and Grad-Cam++
  • Attention map evaluation with given ground truth masks
  • Option for automatic layer selection

Installation

Documentation

Gcam is fully documented and you can view the documentation under:
https://karol-g.github.io/Gcam

Examples

#1 Classification (2D) #2 Segmentation (2D) #3 Segmentation (3D)
Image
Guided backpropagation
Grad-Cam
Guided Grad-Cam
Grad-Cam++

Usage

# Import gcam
from gcam import gcam

# Init your model and dataloader
model = MyCNN()
data_loader = DataLoader(dataset, batch_size=1, shuffle=False)

# Inject model with gcam
model = gcam.inject(model, output_dir="attention_maps", save_maps=True)

# Continue to do what you're doing...
# In this case inference on some new data
model.eval()
for batch in data_loader:
    # Every time forward is called, attention maps will be generated and saved in the directory "attention_maps"
    output = model(batch)
    # more of your code...

Demos

Classification

You can find a Jupyter Notebook on how to use Gcam for classification using a resnet152 at demos/Gcam_classification_demo.ipynb or opening it directly in Google Colab: Open In Colab

2D Segmentation

TODO

3D Segmentation

You can find a Jupyter Notebook on how to use Gcam with the nnUNet for handeling 3D data at demos/Gcam_nnUNet_demo.ipynb or opening it directly in Google Colab: Open In Colab

gcam's People

Contributors

camilagbustillo avatar karol-g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gcam's Issues

update 3d segmentation demos

Hi, Karol-G,
Thanks for your work.
It seems that you have updated gcam_inject.py and modified many parameters. But the demo of 3d segmentation did not update. It is hard to run the demo. On the other hand, the nnUNet also updates class segmentation_export.py, and I can't find a suitable place to modify the source code.
Could you please update the 3d segmentation demo or write a new simple but easy to read 3d demo?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.