# Automated Surface Defect Inspection Based on Autoencoders and Fully Convolutional Neural Networks
## 2 The Proposed Algorithm
### Basic CNN, AE, and FCN  
A commonly used deep learning technique is CNN [2], where convolutional layers are included as hidden layers of the neural network. A convolutional layer convolves its input channels with a set of kernels and passes the results through an activation function as output channels to the next layer. A commonly used activation function for CNN is rectified linear unit (ReLU) [2]. In addition to convolutional layers, fully connected layers containing a number of fully connected neurons are also commonly used in CNN. A CNN network may support pooling or upsampling operations. A pooling operation reduces the dimension of its input channels. Maximum pooling is a typical example for a pooling operation. In contrast to a pooling operation, the goal of an upsampling operation is to increase the dimension of the input channels. Consider a CNN with \(Q\) layers. Because convolutional or fully connected operations can be realized by matrix multiplications [2; 22], each layer \(i\), \(i=1,...,Q\), can be defined as  
\[a_{i} = W_{i}u_{i}+b_{i}, \tag{1}\] \[v_{i} = z(a_{i}), \tag{2}\]  
where \(u_{i}\) is the vectorized input of the layer \(i\), \(a_{i}\) is the results of matrix multiplications, and \(v_{i}\) is the output of the layer \(i\). The function \(z\) for producing \(v_{i}\) from \(a_{i}\) in (2) is the activation function for the layer \(i\). When ReLU is the activation function for the CNN, the corresponding function \(z\) is given by  
\[z(a_{i})=\max(0,a_{i}). \tag{3}\]  
The function \(z\) for other types of activation functions can be found in [2]. The matrix \(W_{i}\) is determined by the weights associated with the convolutional or fully connected layers. When layer \(i\) is a convolutional layer, the matrix \(W_{i}\) is a Toeplitz matrix [22; 23] obtained from the weights of kernels associated with layer \(i\). The vector \(b_{i}\) denotes the bias vector. Let \(U=u_{1}\) and \(V=v_{Q}\). The \(U\) and \(V\) are then the input and output of the CNN network, respectively. Depending on the architecture of the CNN, the input \(u_{i}\) at layer \(i\), \(i=2,...,Q\) could be obtained directly from the output \(v_{i-1}\) at layer \(i-1\). Alternately, the \(u_{i}\) may also be a concatenation of the outputs from some of its previous layers. A basic AE is a neural network that is trained to replicate its input to its output [2]. As shown in Figure 1a, the network contains two parts: an encoder for feature extraction of its input and a decoder for reconstruction from the feature. Both the encoder and decoder contain convolutional layers and/or fully connected layers with operations shown in (1) and (2). Therefore, the basic AE can be regarded as a CNN with \(Q\) layers, where each layer \(i\) is defined in (1) and (2). In this study, the autoencoder is not trained to replicate its input \(U\) perfectly. It is restricted to ignoring defective portions of the input image \(U\) for image reconstruction. Only normal portions are copied to the output \(V\). A basic FCN is a neural network for the segmentation of the input image to a number of coherent regions [19]. The FCN network is also a CNN network relying only on convolutional layers for the exploitation of the correlation among local pixels. No fully connected layers are needed. The FCN can also be separated into two parts: an analysis network for  
Figure 1: The structure of basic AE and FCN: (**a**) Basic AE contains an encoder and a decoder; (**b**) Basic FCN consists of analysis network and synthesis network. correlation exploitation and a synthesis network for producing segmentation results, as revealed in Figure 1b. The basic FCN can also be viewed as a CNN with \(Q\) layers, where each layer \(i\) is defined in (1) and (2). Furthermore, because all the layers are convolutional layers, the matrix \(W_{i}\) for each layer \(i\), \(i=1,...,Q\), is a Toeplitz matrix.