Skip to content

Commit b07b60f

Browse files
author
KentaItakura
committed
update README: add general description
1 parent 18431d4 commit b07b60f

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

README.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# Explainable AI: interpreting the classification using score-CAM
22

3-
This example shows how to use score-CAM (class activation mapping) [1] to investigate and explain the predictions of a deep convolutional neural network for image classification. This code was created with reference to Matlab official document [2].
3+
**[English]**
44

5-
[1] Wang, H., Du, M., Yang, F. and Zhang, Z., 2019. Score-CAM: Improved Visual Explanations Via Score-Weighted Class Activation Mapping. *arXiv preprint arXiv:1910.01279*.
5+
This example shows how to use score-CAM (class activation mapping) [1] to investigate and explain the predictions of a deep convolutional neural network for image classification. The algorithm like CAM [2] and grad-CAM [3] are popular for explainable AI with image classification, but Score-CAM proposed a "gradient-free" method for the explanation. [The original implementation can be found here](https://github.com/haofanwang/Score-CAM).
6+
7+
**[Japanese]**
8+
9+
このスクリプトでは、畳み込み込みニューラルネットワーク(CNN)を用いて画像分類を行ったときの、その分類の判断根拠の可視化を行います。Score-CAMと呼ばれる手法を実装したいと思います。[著者らによるオリジナルの実装のページはこちら](https://github.com/haofanwang/Score-CAM)です。
610

7-
[2] MATLAB documentation: "[Investigate Network Predictions Using Class Activation Mapping](https://jp.mathworks.com/help/deeplearning/ug/investigate-network-predictions-using-class-activation-mapping.html)"
11+
なお、本内容は、[こちらのブログ](https://kentapt.hatenablog.com/entry/2021/12/16/105958)でより詳しく、日本語で書かれています。よろしければぜひご覧ください。
812

9-
[3] Zhou, B., Khosla, A., Lapedriza, A., Oliva, A. and Torralba, A., 2016. Learning deep features for discriminative localization. In *Proceedings of the IEEE conference on computer vision and pattern recognition* (pp. 2921-2929).
13+
14+
15+
**Keywords**: classification, deep learning, explainable AI, gradient, Score-CAM
16+
17+
[1] Wang, H., Du, M., Yang, F. and Zhang, Z., 2019. Score-CAM: Improved Visual Explanations Via Score-Weighted Class Activation Mapping. *arXiv preprint arXiv:1910.01279*.
1018

11-
**The official implementation of Score-CAM is located [here](https://github.com/haofanwang/Score-CAM).**
19+
[2] Zhou, B., Khosla, A., Lapedriza, A., Oliva, A. and Torralba, A., 2016. Learning deep features for discriminative localization. In *Proceedings of the IEEE conference on computer vision and pattern recognition* (pp. 2921-2929).
1220

21+
[3] [Selvaraju, R.R., Cogswell, M., Das, A., Vedantam, R., Parikh, D. and Batra, D., 2017. Grad-cam: Visual explanations from deep networks via gradient-based localization. In Proceedings of the IEEE international conference on computer vision (pp. 618-626).](https://openaccess.thecvf.com/content_iccv_2017/html/Selvaraju_Grad-CAM_Visual_Explanations_ICCV_2017_paper.html)
1322

1423
# Load Pretrained Network
1524

@@ -36,14 +45,15 @@ layerName = activationLayerName(netName);
3645
Compute the activations of the resized image in the ReLU layer that follows the last convolutional layer of the network.
3746

3847
```matlab:Code
48+
addpath('testImg\')
3949
im = imread('CatImg.png');
4050
imResized = imresize(im,[inputSize(1:2)]);
4151
```
4252

4353
# Classify the target image into a category
4454

4555
```matlab:Code
46-
[PredCategory,~]=classify(net,imResized);
56+
[PredCategory,scoreBaseLine]=classify(net,imResized);
4757
PredCategory
4858
```
4959

@@ -106,16 +116,19 @@ Use `classify` function to predict and extract the score for the target class
106116

107117
```matlab:Code
108118
% specify minibatch size. Return an error if the memory is not enough
119+
% score: (the number of test image)-by-(the number of class (1000))
109120
[PredCategory,score]=classify(net,uint8(maskedInputImg),'MiniBatchSize',32);
110121
score_target_class=score(:,classIdx);
122+
CIC=score_target_class-scoreBaseLine(classIdx);
123+
CIC_norm=softmax(CIC);
111124
```
112125

113126
# Multiply the featuremap with the score with corresponding input mask image
114127

115128
Generate course heat map for your final result. The size of the course map is identical to the size of the feature map.
116129

117130
```matlab:Code
118-
score_CAM_prep=featureMap_normalized.*reshape(score_target_class,[1 1 numel(score_target_class)]);
131+
score_CAM_prep=featureMap_normalized.*reshape(CIC_norm,[1 1 numel(CIC_norm)]);
119132
score_CAM_sum=sum(score_CAM_prep,3);
120133
```
121134

README_images/figure_0.png

-155 Bytes
Loading

README_images/figure_1.png

362 KB
Loading

README_images/figure_2.png

147 Bytes
Loading

scoreCAM.mlx

722 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)