# Steel Surface Defect Diagnostics Using Deep Convolutional Neural Network and Class Activation Map
## 2 Background
### Fundamentals of CNN and CAM  
A convolutional neural network (CNN) is a type of deep neural network using successive operations across a variety of layers, which is specified to deal with a two-dimensional image. CNN, firstly introduced in [26], is known to be a successful neural network algorithm for image processing and recognition. The CNN architecture is typically made up of two main stages, i.e., feature extraction and classification, while it is learned to describe spatial information of the images across the layers.  
Figure 1: Feature extraction methods in image processing, GLCM and HOG. (**a**) An example of calculating the GLCM from the original image. (**b**) A process of determining the gradient based histogram from the cell within the image. The direction of an arrow describes the gradient orientation, while the gradient magnitude is depicted as the length.  
Extracted feature representations are fed into the latter part of the architecture, where the model draws a probability for belonging to a certain class. Likewise, weights and biases of the model are optimized by training the neural network via the back propagation algorithm.  
There are conventionally three different types of layers in the CNN architecture, i.e., convolutional, pooling and fully-connected layer (see Figure 2). The convolutional layer utilizes convolution operation to extract spatial features of the image, herein feature maps are computed by utilizing element-wise multiplication between the input image and the operator called kernel or filter. The pooling layer is carried out as a sub-sampling technique, followed by the convolution layer. It is aimed at downsizing the convoluted feature maps to reduce the number of trainable parameters, as well as to improve invariance for shift and distortion. A typical pooling method, i.e., max pooling, is used by taking the highest-value tensors from each certain region in the feature maps. Lastly, the fully-connected layer utilizes intensive features created through two types of layers, i.e., convolutional and pooling layers, for categorizing the input images into classes.  
A class activation map (CAM) method can be deployed to the CNN architecture using global average pooling for enhancing the visual explanation of the deep neural network-based model [27]. The attention map is activated in a way of class-discriminative regions, highlighting the significance within the image for the classification. Through the supplementary analysis on which region the CNN model concentrates for classification, it provides interpretability to judge the black-box model, besides the insights can be obtained to establish the CNN model with more enhanced performance. The CAM can be obtained by taking a linear sum of the feature maps that passes through the last convolutional and pooling layer as follows.  
\[M_{c}(x,y)=\sum_{k}w_{k}^{c}f_{k}(x,y) \tag{7}\]  
where \(M_{c}\) is the class activation map for a certain class \(c\). \(w_{k}^{c}\) denotes the weight value corresponding to \(c\) for \(k^{th}\) unit, while \(f_{k}(x,y)\) represents the \(k^{th}\) feature map at spatial location \((x,y)\).