Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding IDGI to Captum #1284

Open
ShreeSinghi opened this issue May 24, 2024 · 4 comments
Open

Adding IDGI to Captum #1284

ShreeSinghi opened this issue May 24, 2024 · 4 comments

Comments

@ShreeSinghi
Copy link

ShreeSinghi commented May 24, 2024

(making a new PR since I missed creating the design doc earlier)
RE: #1246

IDGI API Design

Background

IDGI (Important Direction Integrated Gradients) is a generalized framework that can be applied on top of any Integrated Gradients method. It works by removing the explanation noise by only considering the "important direction" while calculating the Riemann Sum.
The method requires an underlying path/method to be defined. The original paper shows results for 3 underlying paths/methods: IG, BlurIG, GIG, and in all cases, IDGI + baseline method outperforms the standalone baseline by far.

Requires:

  • Model
  • X = Input
  • n = number of riemann integration steps
  • index = the index of the output class that the image belongs to (in case of classification algorithms)
  • baseline image

Pseudocode:

image

Proposed Captum API Design for IDGI:

The design will be very similar to that of the ‎IntegratedGradients class. The IDGI framework is very generic and works for any classification/regression model. For now, we only implement IDGI for the original IG method which defines the path as a linear interpolation between the baseline and input image, but in the future we can take an additional method argument and choose a different path as defined by GIG or BlurIG. The IDGI class inherits from GradientAttribution and contains complete implementation of the algorithm. The implementation

Constructor:

IDGI(forward_func: Callable) 

Argument Descriptions:

  • forward_func - torch.nn.Module corresponding to model for which attributions are desired. This is consistent with all other attribution constructors in Captum.

attribute:

attribute(inputs: TensorOrTupleOfTensorsGeneric, 
          baselines:  BaselineType,
          target: TargetType
          additional_forward_args: Any,
          n_steps: int,
          internal_batch_size: Union[None, int], 
          return_convergence_delta: bool)

Argument Descriptions:

These arguments follow standard definitions of the existing IntegratedGradients.
Here's a comparison of the existing methods (top) and IDGI (bottom)
image

@ShreeSinghi
Copy link
Author

@aobo-y I want to work on this feature addition. Should I get started? The paper is relatively new so it does not have too many citations but it outperforms existing Integrated Gradient methods by a great margin (as reported by their results and confirmed by my own experiments, along with great visual interpretation and multi-modality. It also follows most (but not all) axioms mentioned in the original Integrated Gradients paper

@aobo-y
Copy link
Contributor

aobo-y commented Jun 1, 2024

@ShreeSinghi thank you for sharing the work!

@vivekmig you may want to take a look and help?

@ShreeSinghi
Copy link
Author

Should I get started? @vivekmig

@ShreeSinghi
Copy link
Author

@vivekmig @aobo-y did you get time to go through my proposal?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants