Skip to main content
QUICK REVIEW

[Paper Review] M3d-CAM: A PyTorch library to generate 3D data attention maps for medical deep learning

Karol Gotkowski, Camila González|arXiv (Cornell University)|Jul 1, 2020
COVID-19 diagnosis using AIMedicine9 references20 citations
TL;DR

M3d-CAM is a PyTorch library that enables easy generation of 3D and 2D attention maps for medical deep learning models, supporting classification and segmentation tasks. It integrates seamlessly via a single-line injection, offering multiple attention methods like Grad-CAM, Guided Backpropagation, Guided Grad-CAM, and Grad-CAM++, with minimal code changes and full compatibility with existing models.

ABSTRACT

M3d-CAM is an easy to use library for generating attention maps of CNN-based PyTorch models improving the interpretability of model predictions for humans. The attention maps can be generated with multiple methods like Guided Backpropagation, Grad-CAM, Guided Grad-CAM and Grad-CAM++. These attention maps visualize the regions in the input data that influenced the model prediction the most at a certain layer. Furthermore, M3d-CAM supports 2D and 3D data for the task of classification as well as for segmentation. A key feature is also that in most cases only a single line of code is required for generating attention maps for a model making M3d-CAM basically plug and play.

Motivation & Objective

  • To improve model interpretability in medical deep learning by enabling visualization of attention maps for 3D and 2D input data.
  • To provide a plug-and-play solution that requires minimal code changes to integrate into existing PyTorch models.
  • To support multiple attention map generation methods—Grad-CAM, Guided Backpropagation, Guided Grad-CAM, and Grad-CAM++—for both classification and segmentation tasks.
  • To enable evaluation of attention maps against ground truth masks using built-in metrics and exportable results.
  • To allow users to easily select specific layers or automatically detect the highest convolutional layer for attention visualization.

Proposed method

  • M3d-CAM injects into a pre-trained PyTorch model using a single line: `model = medcam.inject(model)`.
  • The library dynamically appends or replaces model functions to generate attention maps during every forward pass without altering model behavior.
  • It supports 2D and 3D data inputs and works with both classification and segmentation models.
  • Attention maps are generated using multiple backend methods: Grad-CAM, Guided Backpropagation, Guided Grad-CAM, and Grad-CAM++.
  • Layer selection is flexible—users can specify a single layer, a list of layers, or use 'auto' to select the highest convolutional layer.
  • Evaluation is supported via `model.forward(input, mask)` or direct use of `medcam.Evaluator`, with results exportable to Excel.

Experimental results

Research questions

  • RQ1How can attention maps be efficiently generated for 3D medical imaging data using deep learning models?
  • RQ2What is the minimal code overhead required to integrate interpretability into existing PyTorch-based medical models?
  • RQ3How do different attention map backends (e.g., Grad-CAM vs. Guided Grad-CAM) compare in visualizing model attention across 2D and 3D data?
  • RQ4Can attention map evaluation be systematically performed using ground truth masks to quantify model interpretability?
  • RQ5To what extent can attention maps be generated without modifying the model architecture or inference pipeline?

Key findings

  • M3d-CAM enables attention map generation with only a single line of code, making it highly accessible and compatible with existing models.
  • The library supports all major attention map backends—Grad-CAM, Guided Backpropagation, Guided Grad-CAM, and Grad-CAM++—for both 2D and 3D data.
  • Attention maps are generated automatically during inference, with options to save them to disk using the `output_dir` and `save_maps` parameters.
  • The library correctly identifies and excludes non-convolutional layers (e.g., fully connected) from attention map generation, as they cannot be projected back to input space.
  • Evaluation of attention maps against ground truth masks is natively supported through the `medcam.Evaluator` class, with results exportable to Excel.
  • Grad-CAM++ produces more precise attention maps than vanilla Grad-CAM, especially in cases with multiple instances of the same class in an image.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.