|
9 | 9 | import numpy as np |
10 | 10 | import torch |
11 | 11 | import torch.nn.functional as F |
| 12 | +from mmengine import Config |
12 | 13 | from mmengine.model import revert_sync_batchnorm |
13 | 14 | from PIL import Image |
14 | | -from pytorch_grad_cam import GradCAM, LayerCAM, XGradCAM, GradCAMPlusPlus, EigenCAM, EigenGradCAM |
| 15 | +from pytorch_grad_cam import GradCAM |
15 | 16 | from pytorch_grad_cam.utils.image import preprocess_image, show_cam_on_image |
16 | 17 |
|
17 | | -from mmengine import Config |
18 | 18 | from mmseg.apis import inference_model, init_model, show_result_pyplot |
19 | 19 | from mmseg.utils import register_all_modules |
20 | 20 |
|
@@ -56,21 +56,15 @@ def main(): |
56 | 56 | default='prediction.png', |
57 | 57 | help='Path to output prediction file') |
58 | 58 | parser.add_argument( |
59 | | - '--cam-file', |
60 | | - default='vis_cam.png', |
61 | | - help='Path to output cam file') |
| 59 | + '--cam-file', default='vis_cam.png', help='Path to output cam file') |
62 | 60 | parser.add_argument( |
63 | 61 | '--target-layers', |
64 | 62 | default='backbone.layer4[2]', |
65 | 63 | help='Target layers to visualize CAM') |
66 | 64 | parser.add_argument( |
67 | | - '--category-index', |
68 | | - default='7', |
69 | | - help='Category to visualize CAM') |
| 65 | + '--category-index', default='7', help='Category to visualize CAM') |
70 | 66 | parser.add_argument( |
71 | | - '--device', |
72 | | - default='cuda:0', |
73 | | - help='Device used for inference') |
| 67 | + '--device', default='cuda:0', help='Device used for inference') |
74 | 68 | args = parser.parse_args() |
75 | 69 |
|
76 | 70 | # build the model from a config file and a checkpoint file |
@@ -116,8 +110,7 @@ def main(): |
116 | 110 | # Grad CAM(Class Activation Maps) |
117 | 111 | # Can also be LayerCAM, XGradCAM, GradCAMPlusPlus, EigenCAM, EigenGradCAM |
118 | 112 | targets = [ |
119 | | - SemanticSegmentationTarget(category, mask_float, |
120 | | - (height, width)) |
| 113 | + SemanticSegmentationTarget(category, mask_float, (height, width)) |
121 | 114 | ] |
122 | 115 | with GradCAM( |
123 | 116 | model=model, |
|
0 commit comments