from pytorch_grad_cam import GradCAM, HiResCAM, ScoreCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM, FullGrad, EigenGradCAM, LayerCAM
import torchvision
import torch
import cv2
import matplotlib.pyplot as plt
from PIL import Image
[CAM]Other Methods
https://pythonrepo.com/repo/jacobgil-pytorch-grad-cam
https://github.com/jacobgil/pytorch-grad-cam
Method | What it does |
---|---|
GradCAM | Weight the 2D activations by the average gradient |
GradCAM++ | Like GradCAM but uses second order gradients |
XGradCAM | Like GradCAM but scale the gradients by the normalized activations |
AblationCAM | Zero out activations and measure how the output drops (this repository includes a fast batched implementation) |
ScoreCAM | Perbutate the image by the scaled activations and measure how the output drops |
EigenCAM | Takes the first principle component of the 2D Activations (no class discrimination, but seems to give great results) |
EigenGradCAM | Like EigenCAM but with class discrimination: First principle component of Activations*Grad. Looks like GradCAM, but cleaner |
LayerCAM | Spatially weight the activations by positive gradients. Works better especially in lower layers |
Import
from torchvision.models import resnet50
from fastai.vision.all import *
from torchvision import transforms
def label_func(f):
if f[0].isupper():
return 'cat'
else:
return 'dog'
Data
=Path('original_pet')
path=get_image_files(path)
files=ImageDataLoaders.from_name_func(path,files,label_func,item_tfms=Resize(512)) dls
=Path('random_pet_one') #랜덤박스넣은사진
path_r=get_image_files(path_r)
files_r=ImageDataLoaders.from_name_func(path_r,files_r,label_func,item_tfms=Resize(512)) dls_r
CAM
=cnn_learner(dls,resnet34,metrics=error_rate)
lrnr1) lrnr.fine_tune(
/home/csy/anaconda3/envs/temp_csy/lib/python3.8/site-packages/fastai/vision/learner.py:288: UserWarning: `cnn_learner` has been renamed to `vision_learner` -- please update your code
warn("`cnn_learner` has been renamed to `vision_learner` -- please update your code")
/home/csy/anaconda3/envs/temp_csy/lib/python3.8/site-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.
warnings.warn(
/home/csy/anaconda3/envs/temp_csy/lib/python3.8/site-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet34_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet34_Weights.DEFAULT` to get the most up-to-date weights.
warnings.warn(msg)
epoch | train_loss | valid_loss | error_rate | time |
---|---|---|---|---|
0 | 0.175802 | 0.017629 | 0.006089 | 00:35 |
epoch | train_loss | valid_loss | error_rate | time |
---|---|---|---|---|
0 | 0.044077 | 0.004809 | 0.002030 | 00:43 |
=lrnr.model[0]
net1=lrnr.model[1] net2
= torch.nn.Sequential(
net2 =1),
torch.nn.AdaptiveAvgPool2d(output_size
torch.nn.Flatten(),512,out_features=2,bias=False)) torch.nn.Linear(
=torch.nn.Sequential(net1,net2) net
=Learner(dls,net,metrics=accuracy) lrnr2
5) lrnr2.fine_tune(
epoch | train_loss | valid_loss | accuracy | time |
---|---|---|---|---|
0 | 0.247475 | 0.831850 | 0.725304 | 00:43 |
epoch | train_loss | valid_loss | accuracy | time |
---|---|---|---|---|
0 | 0.122386 | 0.438715 | 0.914750 | 00:43 |
1 | 0.114546 | 0.220883 | 0.916779 | 00:43 |
2 | 0.071775 | 0.079565 | 0.963464 | 00:43 |
3 | 0.032215 | 0.058077 | 0.977673 | 00:43 |
4 | 0.011436 | 0.050615 | 0.982409 | 00:43 |
=cnn_learner(dls_r,resnet34,metrics=error_rate)
lrnr_r1) lrnr_r.fine_tune(
epoch | train_loss | valid_loss | error_rate | time |
---|---|---|---|---|
0 | 0.117688 | 0.012863 | 0.005413 | 00:33 |
epoch | train_loss | valid_loss | error_rate | time |
---|---|---|---|---|
0 | 0.000532 | 0.000008 | 0.000000 | 00:43 |
=lrnr_r.model[0]
net1_r=lrnr_r.model[1] net2_r
= torch.nn.Sequential(
net2_r =1),
torch.nn.AdaptiveAvgPool2d(output_size
torch.nn.Flatten(),512,out_features=2,bias=False)) torch.nn.Linear(
=torch.nn.Sequential(net1_r,net2_r) net_r
=Learner(dls_r,net_r,metrics=accuracy) lrnr2_r
5) lrnr2_r.fine_tune(
epoch | train_loss | valid_loss | accuracy | time |
---|---|---|---|---|
0 | 0.008425 | 0.000942 | 1.000000 | 00:43 |
epoch | train_loss | valid_loss | accuracy | time |
---|---|---|---|---|
0 | 0.000006 | 0.000001 | 1.000000 | 00:43 |
1 | 0.000001 | 0.000000 | 1.000000 | 00:43 |
2 | 0.000001 | 0.000000 | 1.000000 | 00:43 |
3 | 0.000000 | 0.000000 | 1.000000 | 00:43 |
4 | 0.000000 | 0.000000 | 1.000000 | 00:43 |
= first(dls.test_dl([PILImage.create(get_image_files(path)[2])]))
x_cat, = x_cat.to('cpu') x_cat
= first(dls_r.test_dl([PILImage.create(get_image_files(path_r)[2])]))
x_cat_r, = x_cat_r.to('cpu') x_cat_r
= first(dls.test_dl([PILImage.create(get_image_files(path)[12])]))
x_dog, = x_dog.to('cpu') x_dog
= first(dls_r.test_dl([PILImage.create(get_image_files(path_r)[12])]))
x_dog_r, = x_dog_r.to('cpu') x_dog_r
GradCAM
Cat_GradCAM
Cat_GradCAM_Original
= GradCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) gradcam_original
= gradcam_original(input_tensor=x_cat,targets=None) cam_cat_gradcam_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_gradcam_original.squeeze(), alpha
Cat_GradCAM_Randombox
= GradCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) gradcam_randombox
= gradcam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_gradcam_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_gradcam_randombox.squeeze(), alpha
Dog_GradCAM
Dog_GradCAM_Original
= gradcam_original(input_tensor=x_dog,targets=None) cam_dog_gradcam_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_gradcam_original.squeeze(), alpha
Dog_GradCAM_Randombox
= gradcam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_gradcam_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_gradcam_randombox.squeeze(), alpha
HiResCAM
Cat_HiResCAM
Cat_HiResCAM_Original
= HiResCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) hirescam_original
= hirescam_original(input_tensor=x_cat,targets=None) cam_cat_hirescam_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_hirescam_original.squeeze(), alpha
Cat_HiResCAM_Randombox
= HiResCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) hirescam_randombox
= hirescam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_hirescam_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_hirescam_randombox.squeeze(), alpha
Dog_HiResCAM
Dog_HiResCAM_Original
= hirescam_original(input_tensor=x_dog,targets=None) cam_dog_hirescam_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_hirescam_original.squeeze(), alpha
Dog_HiResCAM_Random
= hirescam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_hirescam_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_hirescam_randombox.squeeze(), alpha
ScoreCAM
Cat_ScoreCAM
Cat_ScoreCAM_Original
= ScoreCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) scorecam_original
= scorecam_original(input_tensor=x_cat,targets=None) cam_cat_scorecam_original
100%|██████████| 32/32 [00:26<00:00, 1.23it/s]
100%|██████████| 32/32 [00:25<00:00, 1.27it/s]
100%|██████████| 32/32 [00:25<00:00, 1.26it/s]
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_scorecam_original.squeeze(), alpha
Cat_ScoreCAM_Randombox
= ScoreCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) scorecam_randombox
= scorecam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_scorecam_randombox
100%|██████████| 32/32 [00:25<00:00, 1.25it/s]
100%|██████████| 32/32 [00:25<00:00, 1.26it/s]
100%|██████████| 32/32 [00:25<00:00, 1.26it/s]
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_scorecam_randombox.squeeze(), alpha
Dog_ScoreCAM
Dog_ScoreCAM_Original
= scorecam_original(input_tensor=x_dog,targets=None) cam_dog_scorecam_original
100%|██████████| 32/32 [00:25<00:00, 1.25it/s]
100%|██████████| 32/32 [00:25<00:00, 1.27it/s]
100%|██████████| 32/32 [00:24<00:00, 1.30it/s]
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_scorecam_original.squeeze(), alpha
Dog_ScoreCAM_Randombox
= scorecam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_scorecam_randombox
100%|██████████| 32/32 [00:24<00:00, 1.30it/s]
100%|██████████| 32/32 [00:24<00:00, 1.30it/s]
100%|██████████| 32/32 [00:24<00:00, 1.29it/s]
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_scorecam_randombox.squeeze(), alpha
GradCAMPlusPlus
Cat_GradCAMPlusPlus
Cat_GradCAMPlusPlus_Original
= GradCAMPlusPlus(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) gradcamplusplus_original
= gradcamplusplus_original(input_tensor=x_cat,targets=None) cam_cat_gradcamplusplus_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_gradcamplusplus_original.squeeze(), alpha
Cat_GradCAMPlusPlus_Randombox
= GradCAMPlusPlus(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) gradcamplusplus_randombox
= gradcamplusplus_randombox(input_tensor=x_cat_r,targets=None) cam_cat_gradcamplusplus_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_gradcamplusplus_randombox.squeeze(), alpha
Dog_GradCAMPlusPlus
Dog_GradCAMPlusPlus_Original
= gradcamplusplus_original(input_tensor=x_dog,targets=None) cam_dog_gradcamplusplus_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_gradcamplusplus_original.squeeze(), alpha
Dog_GradCAMPlusPlus_Randombox
= gradcamplusplus_randombox(input_tensor=x_dog_r,targets=None) cam_dog_gradcamplusplus_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_gradcamplusplus_randombox.squeeze(), alpha
AblationCAM
Cat_AblationCAM
Cat_AblationCAM_Original
= AblationCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) ablationcam_original
= ablationcam_original(input_tensor=x_cat,targets=None) cam_cat_ablationcam_original
100%|██████████| 16/16 [00:28<00:00, 1.75s/it]
100%|██████████| 16/16 [00:28<00:00, 1.78s/it]
100%|██████████| 16/16 [00:27<00:00, 1.72s/it]
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_ablationcam_original.squeeze(), alpha
Cat_AblationCAM_Randombox
= AblationCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) ablationcam_randombox
= ablationcam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_ablationcam_randombox
100%|██████████| 16/16 [00:26<00:00, 1.63s/it]
100%|██████████| 16/16 [00:25<00:00, 1.60s/it]
100%|██████████| 16/16 [00:25<00:00, 1.60s/it]
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_ablationcam_randombox.squeeze(), alpha
Dog_AblationCAM
Dog_AblationCAM_Original
= ablationcam_original(input_tensor=x_dog,targets=None) cam_dog_ablationcam_original
100%|██████████| 16/16 [00:25<00:00, 1.61s/it]
100%|██████████| 16/16 [00:25<00:00, 1.58s/it]
100%|██████████| 16/16 [00:25<00:00, 1.58s/it]
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_ablationcam_original.squeeze(), alpha
Dog_AblationCAM_Randombox
= ablationcam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_ablationcam_randombox
100%|██████████| 16/16 [00:25<00:00, 1.60s/it]
100%|██████████| 16/16 [00:25<00:00, 1.60s/it]
100%|██████████| 16/16 [00:25<00:00, 1.59s/it]
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_ablationcam_randombox.squeeze(), alpha
XGradCAM
Cat_XGradCAM
Cat_XGradCAM_Original
= XGradCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) xgradcam_original
= xgradcam_original(input_tensor=x_cat,targets=None) cam_cat_xgradcam_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_xgradcam_original.squeeze(), alpha
Cat_XGradCAM_Randombox
= XGradCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) xgradcam_randombox
= xgradcam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_xgradcam_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_xgradcam_randombox.squeeze(), alpha
Dog_XGradCAM
Dog_XGradCAM_Original
= xgradcam_original(input_tensor=x_dog,targets=None) cam_dog_xgradcam_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_xgradcam_original.squeeze(), alpha
Dog_XGradCAM_Randombox
= xgradcam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_xgradcam_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_xgradcam_randombox.squeeze(), alpha
EigenCAM
Cat_EigenCAM
Cat_EigenCAM_Original
= EigenCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) eigencam_original
= eigencam_original(input_tensor=x_cat,targets=None) cam_cat_eigencam_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_eigencam_original.squeeze(), alpha
Cat_EigenCAM_Randombox
= EigenCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) eigencam_randombox
= eigencam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_eigencam_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_eigencam_randombox.squeeze(), alpha
Dog_EigenCAM
Dog_EigenCAM_Original
= eigencam_original(input_tensor=x_dog,targets=None) cam_dog_eigencam_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_eigencam_original.squeeze(), alpha
Dog_EigenCAM_Randombox
= eigencam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_eigencam_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_eigencam_randombox.squeeze(), alpha
FullGrad
Cat_FullGrad
Cat_FullGrad_Original
= FullGrad(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) fullgrad_original
Warning: target_layers is ignored in FullGrad. All bias layers will be used instead
= fullgrad_original(input_tensor=x_cat,targets=None) cam_cat_fullgrad_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_fullgrad_original.squeeze(), alpha
Cat_FullGrad_Randombox
= FullGrad(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) fullgrad_randombox
Warning: target_layers is ignored in FullGrad. All bias layers will be used instead
= fullgrad_randombox(input_tensor=x_cat_r,targets=None) cam_cat_fullgrad_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_fullgrad_randombox.squeeze(), alpha
Dog_FullGrad
Dog_FullGrad_Original
= fullgrad_original(input_tensor=x_dog,targets=None) cam_dog_fullgrad_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_fullgrad_original.squeeze(), alpha
Dog_FullGrad_Randombox
= fullgrad_randombox(input_tensor=x_dog_r,targets=None) cam_dog_fullgrad_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_fullgrad_randombox.squeeze(), alpha
EigenGradCAM
Cat_EigenGradCAM
Cat_EigenGradCAM_Original
= EigenGradCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) eigengradcam_original
= eigengradcam_original(input_tensor=x_cat,targets=None) cam_cat_eigengradcam_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_eigengradcam_original.squeeze(), alpha
Cat_EigenGradCAM_Randombox
= EigenGradCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) eigengradcam_randombox
= eigengradcam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_eigengradcam_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_eigengradcam_randombox.squeeze(), alpha
Dog_EigenGradCAM
Dog_EigenGradCAM_Original
= eigengradcam_original(input_tensor=x_dog,targets=None) cam_dog_eigengradcam_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_eigengradcam_original.squeeze(), alpha
Dog_EigenGradCAM_Randombox
= eigengradcam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_eigengradcam_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_eigengradcam_randombox.squeeze(), alpha
LayerCAM
Cat_LayerCAM
Cat_LayerCAM_Original
= LayerCAM(model=lrnr2.model.to('cpu'), target_layers=lrnr2.model[0][-1]) layercam_original
= layercam_original(input_tensor=x_cat,targets=None) cam_cat_layercam_original
0].squeeze().show()
dls.train.decode((x_cat,))[=0.7) plt.imshow(cam_cat_layercam_original.squeeze(), alpha
Cat_LayerCAM_Randombox
= LayerCAM(model=lrnr2_r.model.to('cpu'), target_layers=lrnr2_r.model[0][-1]) layercam_randombox
= layercam_randombox(input_tensor=x_cat_r,targets=None) cam_cat_layercam_randombox
0].squeeze().show()
dls.train.decode((x_cat_r,))[=0.7) plt.imshow(cam_cat_layercam_randombox.squeeze(), alpha
Dog_LayerCAM
Dog_LayerCAM_Original
= layercam_original(input_tensor=x_dog,targets=None) cam_dog_layercam_original
0].squeeze().show()
dls.train.decode((x_dog,))[=0.7) plt.imshow(cam_dog_layercam_original.squeeze(), alpha
Dog_LayerCAM_Randombox
= layercam_randombox(input_tensor=x_dog_r,targets=None) cam_dog_layercam_randombox
0].squeeze().show()
dls.train.decode((x_dog_r,))[=0.7) plt.imshow(cam_dog_layercam_randombox.squeeze(), alpha
Figure
Figure_Original
fig, ((ax1,ax2,ax3,ax4),
(ax5,ax6,ax7,ax8),
(ax9,ax10,ax11,ax12),
(ax13,ax14,ax15,ax16),= plt.subplots(5,4)
(ax17,ax18,ax19,ax20)) 'Original')
plt.title(#
0].squeeze().show(ax=ax1)
dls.train.decode((x_cat,))[=0.7)
ax1.imshow(cam_cat_gradcam_original.squeeze(), alpha"GradCAM CAT PART")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x_dog,))[=0.7)
ax2.imshow(cam_dog_gradcam_original.squeeze(), alpha"GradCAM DOG PART")
ax2.set_title(#
0].squeeze().show(ax=ax3)
dls.train.decode((x_cat,))[=0.7)
ax3.imshow(cam_cat_hirescam_original.squeeze(), alpha"HiResCAM CAT PART")
ax3.set_title(#
0].squeeze().show(ax=ax4)
dls.train.decode((x_dog,))[=0.7)
ax4.imshow(cam_dog_hirescam_original.squeeze(), alpha"HiResCAM DOG PART")
ax4.set_title(#
0].squeeze().show(ax=ax5)
dls.train.decode((x_cat,))[=0.7)
ax5.imshow(cam_cat_scorecam_original.squeeze(), alpha"ScoreCAM CAT PART")
ax5.set_title(#
0].squeeze().show(ax=ax6)
dls.train.decode((x_dog,))[=0.7)
ax6.imshow(cam_dog_scorecam_original.squeeze(), alpha"ScoreCAM DOG PART")
ax6.set_title(#
0].squeeze().show(ax=ax7)
dls.train.decode((x_cat,))[=0.7)
ax7.imshow(cam_cat_gradcamplusplus_original.squeeze(), alpha"GradCAMPlusPlus CAT PART")
ax7.set_title(#
0].squeeze().show(ax=ax8)
dls.train.decode((x_dog,))[=0.7)
ax8.imshow(cam_dog_gradcamplusplus_original.squeeze(), alpha"GradCAMPlusPlus DOG PART")
ax8.set_title(#
0].squeeze().show(ax=ax9)
dls.train.decode((x_cat,))[=0.7)
ax9.imshow(cam_cat_ablationcam_original.squeeze(), alpha"AblationCAM CAT PART")
ax9.set_title(#
0].squeeze().show(ax=ax10)
dls.train.decode((x_dog,))[=0.7)
ax10.imshow(cam_dog_ablationcam_original.squeeze(), alpha"AblationCAM DOG PART")
ax10.set_title(#
0].squeeze().show(ax=ax11)
dls.train.decode((x_cat,))[=0.7)
ax11.imshow(cam_cat_xgradcam_original.squeeze(), alpha"XGradCAM CAT PART")
ax11.set_title(#
0].squeeze().show(ax=ax12)
dls.train.decode((x_dog,))[=0.7)
ax12.imshow(cam_dog_xgradcam_original.squeeze(), alpha"XGradCAM DOG PART")
ax12.set_title(#
0].squeeze().show(ax=ax13)
dls.train.decode((x_cat,))[=0.7)
ax13.imshow(cam_cat_eigencam_original.squeeze(), alpha"EigenCAM CAT PART")
ax13.set_title(#
0].squeeze().show(ax=ax14)
dls.train.decode((x_dog,))[=0.7)
ax14.imshow(cam_dog_eigencam_original.squeeze(), alpha"EigenCAM DOG PART")
ax14.set_title(#
0].squeeze().show(ax=ax15)
dls.train.decode((x_cat,))[=0.7)
ax15.imshow(cam_cat_fullgrad_original.squeeze(), alpha"FullGrad CAT PART")
ax15.set_title(#
0].squeeze().show(ax=ax16)
dls.train.decode((x_dog,))[=0.7)
ax16.imshow(cam_dog_fullgrad_original.squeeze(), alpha"FullGrad DOG PART")
ax16.set_title(#
0].squeeze().show(ax=ax17)
dls.train.decode((x_cat,))[=0.7)
ax17.imshow(cam_cat_eigengradcam_original.squeeze(), alpha"EigenGradCAM CAT PART")
ax17.set_title(#
0].squeeze().show(ax=ax18)
dls.train.decode((x_dog,))[=0.7)
ax18.imshow(cam_dog_eigengradcam_original.squeeze(), alpha"EigenGradCAM DOG PART")
ax18.set_title(#
0].squeeze().show(ax=ax19)
dls.train.decode((x_cat,))[=0.7)
ax19.imshow(cam_cat_layercam_original.squeeze(), alpha"LayerCAM CAT PART")
ax19.set_title(#
0].squeeze().show(ax=ax20)
dls.train.decode((x_dog,))[=0.7)
ax20.imshow(cam_dog_layercam_original.squeeze(), alpha"LayerCAM DOG PART")
ax20.set_title(#
20)
fig.set_figwidth(20)
fig.set_figheight( fig.tight_layout()
Figure_Randombox
fig, ((ax1,ax2,ax3,ax4),
(ax5,ax6,ax7,ax8),
(ax9,ax10,ax11,ax12),
(ax13,ax14,ax15,ax16),= plt.subplots(5,4)
(ax17,ax18,ax19,ax20)) 'Randombox')
plt.title(#
0].squeeze().show(ax=ax1)
dls.train.decode((x_cat_r,))[=0.7)
ax1.imshow(cam_cat_gradcam_randombox.squeeze(), alpha"GradCAM CAT PART")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x_dog_r,))[=0.7)
ax2.imshow(cam_dog_gradcam_randombox.squeeze(), alpha"GradCAM DOG PART")
ax2.set_title(#
0].squeeze().show(ax=ax3)
dls.train.decode((x_cat_r,))[=0.7)
ax3.imshow(cam_cat_hirescam_randombox.squeeze(), alpha"HiResCAM CAT PART")
ax3.set_title(#
0].squeeze().show(ax=ax4)
dls.train.decode((x_dog_r,))[=0.7)
ax4.imshow(cam_dog_hirescam_randombox.squeeze(), alpha"HiResCAM DOG PART")
ax4.set_title(#
0].squeeze().show(ax=ax5)
dls.train.decode((x_cat_r,))[=0.7)
ax5.imshow(cam_cat_scorecam_randombox.squeeze(), alpha"ScoreCAM CAT PART")
ax5.set_title(#
0].squeeze().show(ax=ax6)
dls.train.decode((x_dog_r,))[=0.7)
ax6.imshow(cam_dog_scorecam_randombox.squeeze(), alpha"ScoreCAM DOG PART")
ax6.set_title(#
0].squeeze().show(ax=ax7)
dls.train.decode((x_cat_r,))[=0.7)
ax7.imshow(cam_cat_gradcamplusplus_randombox.squeeze(), alpha"GradCAMPlusPlus CAT PART")
ax7.set_title(#
0].squeeze().show(ax=ax8)
dls.train.decode((x_dog_r,))[=0.7)
ax8.imshow(cam_dog_gradcamplusplus_randombox.squeeze(), alpha"GradCAMPlusPlus DOG PART")
ax8.set_title(#
0].squeeze().show(ax=ax9)
dls.train.decode((x_cat_r,))[=0.7)
ax9.imshow(cam_cat_ablationcam_randombox.squeeze(), alpha"AblationCAM CAT PART")
ax9.set_title(#
0].squeeze().show(ax=ax10)
dls.train.decode((x_dog_r,))[=0.7)
ax10.imshow(cam_dog_ablationcam_randombox.squeeze(), alpha"AblationCAM DOG PART")
ax10.set_title(#
0].squeeze().show(ax=ax11)
dls.train.decode((x_cat_r,))[=0.7)
ax11.imshow(cam_cat_xgradcam_randombox.squeeze(), alpha"XGradCAM CAT PART")
ax11.set_title(#
0].squeeze().show(ax=ax12)
dls.train.decode((x_dog_r,))[=0.7)
ax12.imshow(cam_dog_xgradcam_randombox.squeeze(), alpha"XGradCAM DOG PART")
ax12.set_title(#
0].squeeze().show(ax=ax13)
dls.train.decode((x_cat_r,))[=0.7)
ax13.imshow(cam_cat_eigencam_randombox.squeeze(), alpha"EigenCAM CAT PART")
ax13.set_title(#
0].squeeze().show(ax=ax14)
dls.train.decode((x_dog_r,))[=0.7)
ax14.imshow(cam_dog_eigencam_randombox.squeeze(), alpha"EigenCAM DOG PART")
ax14.set_title(#
0].squeeze().show(ax=ax15)
dls.train.decode((x_cat_r,))[=0.7)
ax15.imshow(cam_cat_fullgrad_randombox.squeeze(), alpha"FullGrad CAT PART")
ax15.set_title(#
0].squeeze().show(ax=ax16)
dls.train.decode((x_dog_r,))[=0.7)
ax16.imshow(cam_dog_fullgrad_randombox.squeeze(), alpha"FullGrad DOG PART")
ax16.set_title(#
0].squeeze().show(ax=ax17)
dls.train.decode((x_cat_r,))[=0.7)
ax17.imshow(cam_cat_eigengradcam_randombox.squeeze(), alpha"EigenGradCAM CAT PART")
ax17.set_title(#
0].squeeze().show(ax=ax18)
dls.train.decode((x_dog_r,))[=0.7)
ax18.imshow(cam_dog_eigengradcam_randombox.squeeze(), alpha"EigenGradCAM DOG PART")
ax18.set_title(#
0].squeeze().show(ax=ax19)
dls.train.decode((x_cat_r,))[=0.7)
ax19.imshow(cam_cat_layercam_randombox.squeeze(), alpha"LayerCAM CAT PART")
ax19.set_title(#
0].squeeze().show(ax=ax20)
dls.train.decode((x_dog_r,))[=0.7)
ax20.imshow(cam_dog_layercam_randombox.squeeze(), alpha"LayerCAM DOG PART")
ax20.set_title(#
20)
fig.set_figwidth(20)
fig.set_figheight( fig.tight_layout()