{"id":28451560,"url":"https://github.com/hummat/saliency","last_synced_at":"2025-10-04T13:58:21.197Z","repository":{"id":105954475,"uuid":"229449704","full_name":"hummat/saliency","owner":"hummat","description":"PyTorch implementation of 'Vanilla' Gradient, Grad-CAM, Guided backprop, Integrated Gradients and their SmoothGrad variants.","archived":false,"fork":false,"pushed_at":"2024-12-09T13:59:48.000Z","size":10309,"stargazers_count":19,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-06T16:11:38.168Z","etag":null,"topics":["deep-learning","deep-learning-algorithms","deep-neural-networks","grad-cam","guided-backpropagation","integrated-gradients","machine-learning","machine-learning-algorithms","pytorch","saliency","smoothgrad","xrai"],"latest_commit_sha":null,"homepage":"https://hummat.github.io/saliency/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hummat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-12-21T15:53:36.000Z","updated_at":"2024-12-09T09:20:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"c953b7b3-d479-4256-8c45-464ae16f0cb3","html_url":"https://github.com/hummat/saliency","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hummat/saliency","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummat%2Fsaliency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummat%2Fsaliency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummat%2Fsaliency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummat%2Fsaliency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hummat","download_url":"https://codeload.github.com/hummat/saliency/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hummat%2Fsaliency/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278322146,"owners_count":25967874,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deep-learning","deep-learning-algorithms","deep-neural-networks","grad-cam","guided-backpropagation","integrated-gradients","machine-learning","machine-learning-algorithms","pytorch","saliency","smoothgrad","xrai"],"created_at":"2025-06-06T16:11:28.196Z","updated_at":"2025-10-04T13:58:21.192Z","avatar_url":"https://github.com/hummat.png","language":"Jupyter Notebook","readme":"# Saliency Methods\n## Overview\nThis repository contains code for the following saliency techniques:\n### 1. Vanilla Gradients\n![gradient](images/gradient.png)\n### 2. Guided Backpropogation (with Smoothgrad)\n![guided](images/guided_backrop_smoothgrad.png)\n### 3. Integrated Gradients\n![integrated](images/integrated_gradient.png)\n### 4. (Guided) Grad-CAM\n![gradcam](images/guided_grad_cam.png)\n### 5. XRAI\n![xrai](images/xrai.png)\n\n## Remarks\nThe methods should work with all models from the [torchvision](https://github.com/pytorch/vision) package. Tested models so far are:\n* VGG variants\n* ResNet variants\n* DenseNet variants\n* Inception/GoogLeNet*\n\n*In order for *Guided Backpropagation* and *Grad-CAM* to work properly with the *Inception* and *GoogLeNet* models, they need to by modified slightly, such that all *ReLUs* are modules of the model rather than function calls.\n\n```python\n# This class can be found at the very end of inception.py and googlenet.py respectively.\nclass BasicConv2d(nn.Module):\n\n    def __init__(self, in_channels, out_channels, **kwargs):\n        super(BasicConv2d, self).__init__()\n        self.conv = nn.Conv2d(in_channels, out_channels, bias=False, **kwargs)\n        self.bn = nn.BatchNorm2d(out_channels, eps=0.001)\n        self.relu = nn.ReLU(inplace=True)  # Add this line\n\n    def forward(self, x):\n        x = self.conv(x)\n        x = self.bn(x)\n        return self.relu(x)  # Replaces F.relu(x, inplace=True)\n```\n    \n## Examples\nFor a brief overview on how to use the package, please have a look at this short [tutorial notebook](https://github.com/hummat/saliency/blob/master/tutorial.ipynb). The bare minimum is summarized below.\n\n```python\n# Standard imports \nimport torchvision\n\n# Import desired utils and methods\nfrom ml_utils import load_image, show_mask\nfrom guided_backprop import GuidedBackprop\n\n# Load model and image\nmodel = torchvision.models.resnet50(pretrained=True)\ndoberman = load_image('images/doberman.png', size=224)\n\n# Construct a saliency object and compute the saliency mask.\nguided_backprop = GuidedBackprop(model)\nrgb_mask = guided_backprop.get_mask(image_tensor=doberman)\n\n# Visualize the result\nshow_mask(rgb_mask, title='Guided Backprop')\n```\n\n## Credits\nThe implementation follows closely that of the corresponding [TensorFlow saliency](https://github.com/PAIR-code/saliency) repository, reusing its code were applicable (mostly for the XRAI method).\n\nFurther inspiration has been taken from [this](https://github.com/utkuozbulak/pytorch-cnn-visualizations) repository.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhummat%2Fsaliency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhummat%2Fsaliency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhummat%2Fsaliency/lists"}