Using Grad, Grad-CAM or Grad-CAM++ for visualizing feature maps of Deep Convolutional Networks
[1] CAM: Learning Deep Features for Discriminative Localization
[2] GradCAM: Visual Explanations from Deep Networks via Gradient-based Localization
[3] Grad-CAM++: Improved Visual Explanations for Deep Convolutional Networks
CNNs_visualization_pytorch
|
├── models
| ├── definitions # including all definition of models
| └── weights # including all trained weights for loading into models.
|
├── modules
| ├── CAM
| | ├── class_activation_map.py
| | └── config.yaml
| ├── gradCAM
| | ├── gradCAM.py
| | └── config.yaml
| └── gradCAMpp
| ├── gradCAMpp.py
| └── config.yaml
├── run.py
└── utils.py
- Adding Class Activation Map method for visualizing the last convolutional layer in CNNs with AveragePooling.
- Adding Grad-CAM method for visualizing any convolutional layer in CNNs.
- Applying GuidedBackprop method which is proposed in paper[2].
- Applying grad-CAM++ method which is proposed in paper[3].
- Adding .flake8 to check coding style.
- Adding mypy to check my code and find common bugs.
- Adding pre-commit to solve hook issues.
CAM, Grad-CAM using model which is trained with custom model and cifar 10 dataset (10 classes).
- CAM
python run.py <image_path> --show-image --config-path module/CAM/config.yaml --module-name cifar_10
python run.py <image_dir> --pattern <image_pattern> --show-image --config-path module/CAM/config.yaml --module-name cifar_10
- Grad-CAM
python run.py <image_path> --show-image --config-path module/gradCAM/config.yaml --module-name cifar_10
python run.py <image_dir> --pattern <image_pattern> --show-image --config-path module/gradCAM/config.yaml --module-name cifar_10
CAM, Grad-CAM using
torchvision.models.resnet18
with pretrained weight and imagenet dataset (1000 classes).
- CAM
python run.py <image_path/image_dir> --show-image --config-path module/CAM/config.yaml --module-name image_net
python run.py <image_dir> --pattern <image_pattern> --show-image --config-path module/CAM/config.yaml --module-name image_net
- Grad-CAM
python run.py <image_path> --show-image --config-path module/gradCAM/config.yaml --module-name image_net
python run.py <image_dir> --pattern <image_pattern> --show-image --config-path module/gradCAM/config.yaml --module-name image_net
Method | CIFAR 10 | IMAGE NET |
---|---|---|
CAM | ||
grad-CAM | ||
CAM | ||
grad-CAM |
Xuan-Phung Pham