import torch
from fastai.vision.all import *
import cv2 as cv
import fastbook
from fastbook import *
from fastai.vision.widgets import *
import os
from pytorch_grad_cam import GradCAM, HiResCAM, ScoreCAM, GradCAMPlusPlus, AblationCAM, XGradCAM, EigenCAM, FullGrad, EigenGradCAM, LayerCAM
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
import torchvision
from torchvision.models import resnet18
import torch.nn as nn
import matplotlib.pyplot as plt
from PIL import Image
from torchvision.models import resnet50
[CAM]other methods chest xray
scorecam nan 값 산출 문제찾는 중..
Import
Data
refer : https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia
# path=Path('./home/Dropbox/chest_xray/chest_xray')
= Path(os.path.expanduser(os.path.join('~', 'Dropbox/chest_xray/chest_xray'))) path
path.ls()
(#3) [Path('/home/csy/Dropbox/chest_xray/chest_xray/train'),Path('/home/csy/Dropbox/chest_xray/chest_xray/test'),Path('/home/csy/Dropbox/chest_xray/chest_xray/val')]
=get_image_files(path) files
= ImageDataLoaders.from_folder(path, train='train', valid_pct=0.2, item_tfms=Resize(224)) dls
dls.vocab
['NORMAL', 'PNEUMONIA']
=16) dls.show_batch(max_n
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = GradCAM(model=model, target_layers=target_layer) gradcam
/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)
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = HiResCAM(model=model, target_layers=target_layer) hirescam
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = ScoreCAM(model=model, target_layers=target_layer) scorecam
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = GradCAMPlusPlus(model=model, target_layers=target_layer) gradcamplusplus
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = AblationCAM(model=model, target_layers=target_layer) ablationcam
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = XGradCAM(model=model, target_layers=target_layer) xgradcam
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = EigenCAM(model=model, target_layers=target_layer) eigencam
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = FullGrad(model=model, target_layers=target_layer) fullgrad
Warning: target_layers is ignored in FullGrad. All bias layers will be used instead
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = EigenGradCAM(model=model, target_layers=target_layer) eigengradcam
= resnet34(pretrained=True)
model
= [model.layer4[-1]]
target_layer = LayerCAM(model=model, target_layers=target_layer) layercam
1번째 시도
= PILImage.create(get_image_files(path)[304]) img
= first(dls.test_dl([img])) #이미지 텐서화
x, = x.to('cpu') x
= gradcam(input_tensor=x,targets=None) cam_gradcam
= hirescam(input_tensor=x,targets=None) cam_hirescam
= scorecam(input_tensor=x,targets=None) cam_scorecam
100%|██████████| 32/32 [00:03<00:00, 9.20it/s]
= gradcamplusplus(input_tensor=x,targets=None) cam_gradcamplusplus
= ablationcam(input_tensor=x,targets=None) cam_ablationcam
100%|██████████| 16/16 [00:03<00:00, 4.14it/s]
= xgradcam(input_tensor=x,targets=None) cam_xgradcam
= eigencam(input_tensor=x,targets=None) cam_eigencam
= fullgrad(input_tensor=x,targets=None) cam_fullgrad
= eigengradcam(input_tensor=x,targets=None) cam_eigengradcam
= layercam(input_tensor=x,targets=None) cam_layercam
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_gradcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART GradCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_gradcam.squeeze(),alpha"DISEASE PART GradCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_hirescam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART HiResCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_hirescam.squeeze(),alpha"DISEASE PART HiResCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_scorecam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART ScoreCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_scorecam.squeeze(),alpha"DISEASE PART ScoreCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_gradcamplusplus.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART GradCAMPlusPlus")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_gradcamplusplus.squeeze(),alpha"DISEASE PART GradCAMPlusPlus")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_ablationcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART AblationCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_ablationcam.squeeze(),alpha"DISEASE PART AblationCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_xgradcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART XGradCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_xgradcam.squeeze(),alpha"DISEASE PART XGradCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_eigencam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART EigenCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_eigencam.squeeze(),alpha"DISEASE PART EigenCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_fullgrad.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART FullGrad")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_fullgrad.squeeze(),alpha"DISEASE PART FullGrad")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_layercam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART LayerCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_layercam.squeeze(),alpha"DISEASE PART LayerCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
2번째 시도
= PILImage.create(get_image_files(path)[3031]) img
= first(dls.test_dl([img])) #이미지 텐서화
x, =x.to('cpu') x
= gradcam(input_tensor=x,targets=None) cam_gradcam
= hirescam(input_tensor=x,targets=None) cam_hirescam
= scorecam(input_tensor=x,targets=None) cam_scorecam
100%|██████████| 32/32 [00:03<00:00, 9.06it/s]
= gradcamplusplus(input_tensor=x,targets=None) cam_gradcamplusplus
= ablationcam(input_tensor=x,targets=None) cam_ablationcam
100%|██████████| 16/16 [00:03<00:00, 4.18it/s]
= xgradcam(input_tensor=x,targets=None) cam_xgradcam
= eigencam(input_tensor=x,targets=None) cam_eigencam
= fullgrad(input_tensor=x,targets=None) cam_fullgrad
= eigengradcam(input_tensor=x,targets=None) cam_eigengradcam
= layercam(input_tensor=x,targets=None) cam_cat_layercam
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_gradcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART GradCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_gradcam.squeeze(),alpha"DISEASE PART GradCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_hirescam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART HiResCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_hirescam.squeeze(),alpha"DISEASE PART HiResCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_scorecam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART ScoreCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_scorecam.squeeze(),alpha"DISEASE PART ScoreCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_gradcamplusplus.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART GradCAMPlusPlus")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_gradcamplusplus.squeeze(),alpha"DISEASE PART GradCAMPlusPlus")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_ablationcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART AblationCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_ablationcam.squeeze(),alpha"DISEASE PART AblationCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_xgradcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART XGradCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_xgradcam.squeeze(),alpha"DISEASE PART XGradCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_eigencam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART EigenCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_eigencam.squeeze(),alpha"DISEASE PART EigenCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_fullgrad.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART FullGrad")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_fullgrad.squeeze(),alpha"DISEASE PART FullGrad")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_layercam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART LayerCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_layercam.squeeze(),alpha"DISEASE PART LayerCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
3번째 시도
= PILImage.create(get_image_files(path)[3107]) img
= first(dls.test_dl([img])) #이미지 텐서화
x, =x.to('cpu') x
= gradcam(input_tensor=x,targets=None) cam_gradcam
= hirescam(input_tensor=x,targets=None) cam_hirescam
= scorecam(input_tensor=x,targets=None) cam_scorecam
100%|██████████| 32/32 [00:03<00:00, 9.22it/s]
= gradcamplusplus(input_tensor=x,targets=None) cam_gradcamplusplus
= ablationcam(input_tensor=x,targets=None) cam_ablationcam
100%|██████████| 16/16 [00:03<00:00, 4.23it/s]
= xgradcam(input_tensor=x,targets=None) cam_xgradcam
= eigencam(input_tensor=x,targets=None) cam_eigencam
= fullgrad(input_tensor=x,targets=None) cam_fullgrad
= eigengradcam(input_tensor=x,targets=None) cam_eigengradcam
= layercam(input_tensor=x,targets=None) cam_cat_layercam
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_gradcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART GradCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_gradcam.squeeze(),alpha"DISEASE PART GradCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_hirescam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART HiResCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_hirescam.squeeze(),alpha"DISEASE PART HiResCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_scorecam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART ScoreCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_scorecam.squeeze(),alpha"DISEASE PART ScoreCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_gradcamplusplus.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART GradCAMPlusPlus")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_gradcamplusplus.squeeze(),alpha"DISEASE PART GradCAMPlusPlus")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_ablationcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART AblationCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_ablationcam.squeeze(),alpha"DISEASE PART AblationCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_xgradcam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART XGradCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_xgradcam.squeeze(),alpha"DISEASE PART XGradCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_eigencam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART EigenCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_eigencam.squeeze(),alpha"DISEASE PART EigenCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_fullgrad.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART FullGrad")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_fullgrad.squeeze(),alpha"DISEASE PART FullGrad")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()
= plt.subplots(1,2)
fig, (ax1,ax2) 0].squeeze().show(ax=ax1)
dls.train.decode((x,))[-cam_layercam.squeeze(),alpha=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax1.imshow("NORMAL PART LayerCAM")
ax1.set_title(#
0].squeeze().show(ax=ax2)
dls.train.decode((x,))[=0.5,extent=(0,224,224,0),interpolation='bilinear',cmap='cool')
ax2.imshow(cam_layercam.squeeze(),alpha"DISEASE PART LayerCAM")
ax2.set_title(#
8)
fig.set_figwidth(8)
fig.set_figheight( fig.tight_layout()