Skip to content

This is a Pytorch project that implements gradcam from scratch. For the sake of simplicity I've used AlexNet and Resnet50 pretrained models on imagenet.

Notifications You must be signed in to change notification settings

irfanbykara/GradCam-Pytorch-Implementation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GradCam-Pytorch-Implementation

This is a PyTorch project that implements Grad-CAM (Gradient-weighted Class Activation Mapping) from scratch. For the sake of simplicity, the project uses pretrained models from ImageNet, including AlexNet and ResNet50.

Installation

Sample Result for an Elephant Image

To set up the project on your local machine, follow these steps:

  1. Clone the repository to your local machine:

    git clone https://github.com/your-username/GradCam-Pytorch-Implementation.git
  2. Navigate to the project directory:

    cd GradCam-Pytorch-Implementation
  3. Create a virtual environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows, use: venv\Scripts\activate
  4. Install the required Python packages using pip:

    pip install -r requirements.txt

Usage

To generate heatmaps for images using Grad-CAM, you can run the project with the following command-line arguments:

python main.py --class_choice <class_name> --img_path <image_path> --model_name <model_name>

Where:

class_choice: Choose the target class name (e.g., "elephant" or "bear"). img_path: Provide the path to the image file you want to visualize. model_name: Choose the model for generating heatmaps ("resnet" or "alexnet"). By default, the script uses the following values:

class_choice: "elephant" img_path: "ILSVRC2012_val_00025941.JPEG" model_name: "resnet" You can adjust these command-line arguments according to your specific use case.

If you like to use different models other than resnet50 and alexnet, make sure that you get the outputs of the last conv layer in the get_features function in utils.py and modify the tensor sizes for each architecture respectively.

About

This is a Pytorch project that implements gradcam from scratch. For the sake of simplicity I've used AlexNet and Resnet50 pretrained models on imagenet.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages