Occlusion-Based Saliency Maps for CNN
Occlusion-Based Saliency Maps for CNN
1
Contents
1 Introduction 3
1.1 General introduction . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Interpretability and completeness . . . . . . . . . . . . . . . . 3
1.3 Importance of an interpretable neural networks . . . . . . . . 4
1.4 Project introduction . . . . . . . . . . . . . . . . . . . . . . . 4
2 Related work 5
2.1 Occlusion based saliency maps . . . . . . . . . . . . . . . . . . 5
2.2 LIME/Anchor . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 DeepLIFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Method 7
3.1 Method introduction . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.1 Size of filter . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.2 Number of filters and type of filter method . . . . . . . 10
3.2.3 Optimization and comparison . . . . . . . . . . . . . . 11
5 Conclusions 22
6 Appendix 23
2
1 Introduction
1.1 General introduction
Machine learning is a fast growing and wide field. There are many divisions
of the field that are paramount, artificial neural networks (ANN) being one of
them. The model of the ANN is loosely built on how the human brain works,
and one of the applications that ANNs are most known for is computer vision.
In computer vision it is common to use convolutional neural networks (CNN),
which uses sparsely connected, shared weights [1]. As the CNNs become more
complex, it is also harder to have an intuition of what they base their decision
on. This project will be working with explanatory artificial intelligence (XAI)
of CNNs with the use of saliency maps.
3
tory models without human interaction. This is then called functionally-
grounded evaluation. All of this is visualized in [3] using the figure seen in
figure 1.
4
the interpretability. For ANNs that means looking at layers independently, or
even nodes. The second approach is to have explanation-producing systems,
where the networks themselves are interpretable to a higher degree. Exam-
ples are attention-based networks or disentanglement representation [2]. The
third and final focuses on the processing of the model, and tries to simplify
it. One possible way to do so is to use linear proxy models such as LIME
[5]. A proxy model is useful for some domains where its characteristics can
be explained in a simpler fashion. Decision trees often aim to simplify ex-
planation of how models work, although unfortunately they tend to become
quite complex in themselves. However, this project will focus on saliency
maps. Saliency maps give weighted values to the inputs on how important
they are for the output. Saliency maps belong to the third category of XAI
that explains the processes of the model [2].
This project aims to visualize what a CNN, built for classification, bases
its predictions on. The CNN will be built and trained to acquire a high test
accuracy. The test images will then be slightly perturbed before being used
as inputs. The difference in output, relative to the output of the unperturbed
image, is then stored. This will be repeated several times until a saliency
map of the pixels can be obtained. The method will be used on the MNIST
database [6]. The desired effect of the perturbations is to occlude parts of
the image to see how important they are for the classification. Therefore,
the method will also be called occlusion based. A detailed description of
the project is given in section 3. The evaluation will mainly be application-
grounded.
Comparison will primarily be done with backpropagating saliency maps.
Simply put, the backpropagating saliency maps are created by starting with
an output and then step by step going backwards through the network until
the input-layer is reached. However, the values in the input-layer will not
recreate the image but rather give values of importance for the classification.
These are then used to create the saliency maps. Note that there is a funda-
mental difference between the occlusion based and backpropagating methods,
as the first is a black box model and the latter is not. This is because the
weights are needed to propagate backwards through the network.
2 Related work
2.1 Occlusion based saliency maps
The most common use for occlusion saliency maps is to have them as a
reference map to check if the backpropagating saliency maps give an accurate
5
result. This is due to the larger computational power required to create
occlusion saliency maps compared to backpropagating models. Examples of
this use of occlusion maps can be seen in the paper by M. Ancona et al.
[7], where the occlusion maps are used as a reference but are not the main
topic of research. One example of occlusion based saliency map can be seen
in the work by Matthew D. Zeiler et al. [8], where it is used to investigate
the individual layers to gain knowledge about how the CNN functions. This
is a mixture of the main categories of XAI discussed in section 1.4, as the
processes of specific parts of the network is studied. However, in most of
the studies the research is limited to the occlusion methods with a square
of background colour travelling across the image. Since there is no/little
variation regarding the filter, size of filter, number of filters and placement
of filters a void of information appears to prevail.
Some human-grounded studies on saliency maps give insight on how much
interpretability is gained from using these maps. Even though they use an
algorithm called Layerwise Relevance Propagation and not occlusion, the
knowledge gained should apply to all saliency maps. They arrive at the
conclusion that while saliency maps are helpful, they need to be a part of
a larger explanatory model. The need for a non-instance based explanatory
model is evident [9].
2.2 LIME/Anchor
Contrary to this project, LIME uses a proxy model for interpretability. The
proxy model in use can vary, but it should be a local interpretable model-
agnostic explanation. This is what the acronym LIME stands for. The
proxy model needs to be interpretable. That is the main point of it, that
humans can understand what happens in that local area. These interpretable
models can be constructed to allow the complexity to decrease at a local level.
Often a linear approximation is used. Another key factor to LIME is that
it is model-agnostic. The main idea of LIME is to construct an explanatory
model which does not depend on the machine learning model [5]. When
LIME is used for image classifying CNNs, super-pixels will be constructed.
Super-pixels are pixels that have approximately the same contributions to
the classification, which then will be grouped together to create a super-
pixel. The pixel values in a super-pixel is set to the same value, that is the
average of the pixels in that super-pixel. One super-pixel should correspond
to one feature. The explanation model that will be obtained in LIME is
usually which super-pixels are the most useful for a specific classification.
The super-pixels that are essential to the classification together constructs
what is called the anchor. Everything except the anchor could be changed
6
Figure 2: Image from Ribeiro (2018) discussion on anchors. The anchor
constitutes what the CNN ”defines” as a beagle in this case. [10]
2.3 DeepLIFT
DeepLIFT is a backpropagating explanation model. First, reference values
for inputs and outputs will be defined. A reference input value can be some
default value or some other natural base value for the model. Inputs reference
values for MNIST is an image with all black pixels. The reference output
values is then the values from having the network predict with the reference
inputs. The choice of the reference input value is crucial for the model. For a
prediction, the difference between an output value and its reference value can
be calculated. This difference can then be attributed, based on contribution,
to the various input-reference differences. The sum of all contributions is the
prediction output. When all is done, there is one contribution value for each
input. These contribution values can be plotted to create a saliency map
[11].
3 Method
3.1 Method introduction
There are two general ideas behind getting a saliency map over the image.
The first is a perturbation driven approach. This is done by introducing
various perturbations in the input, and tracking how that affects the output.
7
The second is by backpropagating through the gradients of the network. In
this project a brute force perturbation method will be used. It will sometimes
be referred to as occlusion based also, since the idea is to block out features
that the CNN uses to classify.
In this project the MNIST citegawd dataset was used. It contains 70000
handwritten digits in images with the size of 28x28 pixels. The CNN will be
trained on a subset of the total images, and then tested on another subset.
A network of the CNN model with two convolutional layers, and maxpooling
in-between was used. An MLP connected the convolutional layers to the
output nodes. A test accuracy of 99% was obtained. Since this project aims
to work with XAI this short description of the network will be sufficient.
The evaluation of the interpretability will be application-based. This is
because the dataset in use is MNIST, and anyone can make an assessment
of what constitutes a specific digit. Attempts of functionally-grounded eval-
uations were made, when comparing the result with deepLIFT. The main
evaluations will still be a qualitative assessment, focusing on whether or not
the features that the saliency map presents are plausible.
Figure 3: Showing the procedure to create the saliency map, with the dazed
lined procedures being done once all iterations are finished.
The trained CNN was used to predict digits on perturbed MNIST images.
Much of this project’s work was done by qualitatively investigating methods
8
to perturb the images. The perturbation methods will be discussed below
in section 3.2. The pixels that were perturbed was noted in an array. Once
the image is perturbed it was used as an input for the trained CNN. The
difference between the output value obtained from the perturbed image and
the original image was then stored in an array with the saliency map values.
However, since pixels are chosen randomly in many of the filters there is a
need to keep track of how many times a pixel has been used for normalization
purposes. Figure 3 visualizes the procedure. Each iteration will build up the
value array and the normalization array, but only once all the iterations were
done was the saliency map created. This procedure is iterated many times,
where the results seem to converge at 105 − 106 iterations for the majority
of the filters. An iteration contains all the steps seen in figure 3, except
the dazed-line steps. These two final steps is where the normalization array
and value array together create the saliency map. This is done after all the
iterations have been done. There is one iteration per filtered image.
3.2 Filters
The main idea behind selecting filters is to visualize what the defining features
are for each digit. Features are attributes that the digits posses, which may
or may not be important for the classification. Features can also be a lack of
certain attributes. A feature for the digit one might be that it has a straight
line, but another might be that it has nothing else around it. To be able to
find the important features the filter needs to block them. If too much is
filtered, noise can take the upper hand. It is therefore important to select
the optimal filter.
9
size is preferred. This is because the number of pixels used to block out a
feature completely is probably larger. Therefore, if a certain filter size is
the most proficient in feature extraction, it is then only applicable on this
specific dataset. Since features can be smaller or larger in the image, even
in the same dataset, it could be of interest to make multiple filter sizes when
working on a new dataset. When using only one filter there is no need for a
large number of iterations, instead the filter simply travels across the entire
image once. Since there is no random factor there is nothing to gain in doing
more iterations.
(a) Many 1 pixel flips. (b) Three 3x3 flip filters. (c) One 3x3 random.
10
3.2.3 Optimization and comparison
The final addition to the filters was optimization. The idea was that the
interesting data will mainly be around the digit, and not at the edge of the
image. By reducing the number of inputs that is far from the digit, the
desired results can be obtained quicker. The first attempt of an optimization
was done by adding all the grayscale values together in an array. The array is
the sum of all the MNIST images together. This leads to each array element
being the sum of the corresponding grayscale values in the MNIST figures
together. This can then be used as a probability distribution for drawing
values at where to place the filter. This is visualized in figure 5. Here the first
two MNIST images are added together, and then printed. Since the figure
5.c will have pixel values over the maximal of 255 it gives a false picture, but
helps to visualize the idea. All the MNIST images were added together, and
not just these two. However, this method was abandoned, since values at
the edge of where digits appear in the images would often only be used once.
All pixels need to be drawn many times to have a statistical foundation. If
a saliency map of one of the digits that are at the edge of the probability
distribution is desired, the map would look completely inaccurate.
A simpler optimization was done with a check if the filter was within
the digit or not. If it was not within the digit it had a probability of being
rejected. One thing to keep in mind is the domain of the CNN. If there are
no digits in the training set at the edge of the image, but in the filtration
that area is suddenly flipped, it might give strange/incorrect results.
From the various tests a filter method was established, and then com-
pared to deepLIFT and LIME/anchor. DeepLIFT was compared with this
11
project’s method by the use of structural similarity index(SSIM), but be-
cause of the fundamental differences between the methods, the SSIM scores
did not contain much valuable information.
12
4.1.1 How many pixels should be flipped?
Two examples when random pixels were flipped are presented in figure 6.
Figure 6.a and 6.c show examples of how an occlusion can look. As can
clearly be seen, the percentage of filtered pixels cannot be too large, otherwise
the noise will be too dominant. It is important to note that the figures are
normalized individually, and does not share intensity-value relations. While
comparing figure 6.b and 6.d, it might seem intuitive that figure 6.c gives
a better map since more of it is of higher intensity. This is however false,
the general higher intensity is noise from coupling high impact pixels with
all the rest. While there still are features that can be extracted from the
saliency map, they are less clear against the background. Indeed, this is
what intuition also tells us, flipping too many pixels should yield more noise.
There should be a larger possibility of the 10% flip to catch more of the larger
feature, but none can be seen here that were not captured by the 1% flip.
From now on a few percentages of the image will be filtered.
(a) 1% flipped (b) 1% flipped (c) 10% flipped (d) 10% flipped
Figure 6: The percentage of filtered pixels tested, here using 1x1 flipping
filters.
13
sizes. The 2x2 filter gives a more detailed view of individual pixels, while the
bigger filters seem to emphasize the feature in the middle of the image more.
Which filter size that yields the highest completeness depends on whether
the middle feature actually is the most important or not.
Moving forward, the smaller filters, 2x2 and 3x3, will be regarded as the
superior size for MNIST as they still detected all the features.
Figure 7: Testing of filter size, with filtered inputs and saliency maps.
14
rigorous feature in between the peaks. This can be seen in figure 16 in the
appendix.
The same tendencies can be seen with the 3x3 filters. All the features
were detected although the features cover a larger area. When using two 3x3
filters there seem to be less noise in the general background. In both figure
15.g and 16.g the same effect can be seen, where the features are slightly
larger but the map otherwise have less noise. Not much was gained from
using three 3x3 filters, but more noise was added. For this dataset three 2x2
or two 3x3 filters seem to give the most complete result.
(a) 3st 2x2 (b) 4st 2x2 (c) 2st 3x3 (d) 3st 3x3
(e) 3st 2x2 (f) 4st 2x2 (g) 2st 3x3 (h) 3st 3x3
Figure 8: Testing number of filters, with filtered inputs and saliency maps.
15
detected. However, it does give more details over the digit itself. For filters
with random pixel values (figure 9.c) the results looks like a combination
between the saliency maps seen in figure 7.e and 7.g. It gives a bit more
detail than the simple flip, and out of the tested alternations the random
value seems to yield the most satisfactory results.
16
if the network is more interpretable.
In some cases it is easily understood why that features is dominant. One
of the clearest examples is images with a number four. In figure 10 the
saliency map of fours can be seen. What they all have in common is that
the area between the two peaks in a four is the high intensity area. This is
because if a filter fills in this area it becomes a nine instead. Indeed, the four
is the only figure with two independent peaks with an area between them.
This gives an interpretable explanation of what information the CNN uses
to classify a figure as a four.
(a) (b)
(c) (d)
In some other cases it is not as clear. For example, sevens can be seen
having as sharply defined feature, but the reason behind it is not as clear.
Figures 11.a and 11.b give the information that there seems to be two crucial
points in the figure. This is not what would be expected, since these parts
of the seven are identical to parts of a slightly tilted number one. Perhaps it
could be explained by looking at the saliency maps of the ones, as in figure
11.c and 11.d. Here some clarity is gained since the ones seems to have their
main features in the background around them. The CNN seems to define
ones as a line without anything around it, and if there is anything around,
it stops being a one. Now the sevens saliency map makes more sense. With
that said, it could very well be a simple case of overtraining when it comes
to the seven.
17
(a) Saliency map of seven (b) Saliency map of seven
(c) Negative space illustrated by ones (d) Negative space illustrated by ones
Figure 11: The features of the number seven and the number one.
Various digits with less dominant features is shown in figure 12. Here the
saliency maps does not provide clearly interpretable features. Figure 12.a
shows a digit two, with a few features having high intensity. Meanwhile,
figure 12.b shows many features of equal importance. A possible explanation
for the bottom feature of figure 12.a is the resemblance of the digit 3, if the
area of this feature is filled with white pixels.
Two chaotic examples are shown in figure 12.c and 12.d. Here the ran-
domized filters are almost as likely to make the image look more like a four
as it is to make it look less like a four. As mentioned before, the blue areas
are where changing the image results in better classification.
18
(a) two with concentrated feature (b) Two with spread features
Figure 12: Detected feature in the number two and chaotic numbers.
19
difference between deepLIFT and this project’s method. The same drawback
can be seen with the number one in figure 13.a. The space around the
number cannot be accounted for, and therefore deepLIFT seems to loose
completeness.
In other cases where the features are within the digit itself deepLIFT
should be as complete or even more complete than this project’s method.
Examples of this can be seen in figure 13.c and 13.d. From the study of
the features of sevens, it is known that they are within the digit itself. In
deepLIFT a detailed map over each pixel can be seen. From figure 13.c it
seems like it was the middle feature from figure 7.a-7.d that indeed was the
most important. For the number nine in figure 13.d the top part can be
seen as being important, which is what is expected since it would create a
four otherwise. It can also be seen that the left part of the circle in the nine
is important, perhaps because it starts looking like a three if that part is
removed. Here it seems more beneficial to use deepLIFT then any occlusion
method.
A functionally-based evaluation was done using structural similarity index
(SSIM). One example of SSIM evaluation is shown in figure 14. Figure 14.a
shows the background for the number 5. Figure 14.b shows the saliency
map obtained using a 1 pixel background filter. In figure 14.c the occlusion
saliency map can be seen when the background is taken into account, and
next to it in figure 14.d is the deepLIFT saliency map. These two images
were then evaluated using SSIM. Since this is a sidetrack from the main
method the math of SSIM will not be discussed. However, if a value of 0 is
obtained then there is no similarity between the images, and if a value of 1
is obtained it is the same image. SSIM between figure 14.c and 14.d gave
a value of 0.4. While this value seems low, some similarities in the general
structure can still be seen in when qualitatively comparing figure 14.c and
14.d.
20
(a) Background (b) Occlusion (c) Combination (d) DeepLIFT
LIME and anchor are closer to this project’s method in its results since it
can detect the features seen in the background around the figure. However, it
will not yield a saliency map that can be compared using SSIM or any other
functionally-based evaluation tool. One possible way to construct LIME
super pixels is to divide the image into the parts which contribute positively
to the classification, and those that contribute negatively. This binary system
results in high interpretability, but lower completeness.
21
how a classifying CNN works multiple tools should be used, where saliency
maps is one of them.
5 Conclusions
When using CNN it is crucial to be able to interpret its output. A useful tool,
when it comes to visual classifying CNN’s, is creating saliency maps of what
parts are of importance. These should be seen as a part of a larger explana-
tory model, partly because no model is perfect, and gaps of completeness
should be expected, and partly because its nature as instance based explana-
tory model is limited. It needs to be combined with a global explanatory
model. Nonetheless, saliency maps give a rare combination of high com-
pleteness and interpretability.
Occlusion based saliency maps are limited in its practical use since they
require much computational power. Therefore, the future is probably in gra-
dient based methods, such as deepLIFT. For now, occlusion based methods
do have higher general completeness and therefore there are still some niche
uses for them. The first being the use of the occlusion methods results as a
way to correct the gradient based methods. The second being when a saliency
map needs to have very high completeness in itself, such as for self-driving
cars.
This project evolved a method through testing various filters. The result
ended up being that a few smaller sized filters with random grayscale values
gave the most complete result. Some parts of the selection is obvious, while
other parts is harder. If two filters contradict one and other, and it is not
obvious which one gives the more complete picture, the decision becomes
hard.
It has throughout this project been shown that even in occlusion maps
there are many variables that can be altered. Generally it is a trade-off
between having higher feature detection and more noise. Larger and more
filters are able to construct more complex filters, which then in turn can
detect more complex features. However, as the size and number of filters
increase so does the noise. The noise will heavily alter the values of all the
non-essential areas, and therefore decrease the completeness in these areas. If
occlusion maps are desired, then the best approach would be to test various
filters to find the sweet spot for that dataset.
22
6 Appendix
(a) 3st 2x2 (b) 4st 2x2 (c) 2st 3x3 (d) 3st 3x3
(e) 3st 2x2 (f) 4st 2x2 (g) 2st 3x3 (h) 3st 3x3
Figure 15: Testing number of filters, with filtered inputs and saliency maps.
(a) 3st 2x2 (b) 4st 2x2 (c) 2st 3x3 (d) 3st 3x3
(e) 3st 2x2 (f) 4st 2x2 (g) 2st 3x3 (h) 3st 3x3
Figure 16: Testing number of filters, with filtered inputs and saliency maps.
23
References
[1] Ian Goodfellow, Yoshua Bengio, and Aaron Courville. Deep Learning.
MIT Press, 2016. [Link]
[2] Leilani H. Gilpin, David Bau, Ben Z. Yuan, Ayesha Bajwa, Michael
Specter, and Lalana Kagal. Explaining explanations: An overview of
interpretability of machine learning. 2018 IEEE 5th International Con-
ference on Data Science and Advanced Analytics (DSAA), pages 80–89,
2018.
[3] Finale Doshi-Velez and Been Kim. Towards a rigorous science of inter-
pretable machine learning. arXiv, 2017.
[5] Marco Tulio Ribeiro, Sameer Singh, and Carlos Guestrin. “why should
i trust you?”: Explaining the predictions of any classifier. In Proceed-
ings of the 22nd ACM SIGKDD International Conference on Knowledge
Discovery and Data Mining, KDD ’16, page 1135–1144, New York, NY,
USA, 2016. Association for Computing Machinery.
[6] Yann LeCun and Corinna Cortes. MNIST handwritten digit database.
2010.
[7] Marco Ancona, Enea Ceolini, A. Cengiz Öztireli, and Markus H. Gross.
A unified view of gradient-based attribution methods for deep neural
networks. CoRR, abs/1711.06104, 2017.
[8] Matthew D. Zeiler and Rob Fergus. Visualizing and understanding con-
volutional networks. In David Fleet, Tomas Pajdla, Bernt Schiele, and
Tinne Tuytelaars, editors, Computer Vision – ECCV 2014, pages 818–
833, Cham, 2014. Springer International Publishing.
[10] Marco Tulio Ribeiro, Sameer Singh, and Carlos Guestrin. Anchors:
High-precision model-agnostic explanations. In Thirty-Second AAAI
Conference on Artificial Intelligence, 2018.
24
[11] Avanti Shrikumar, Peyton Greenside, and Anshul Kundaje. Learning
important features through propagating activation differences. CoRR,
abs/1704.02685, 2017.
25