# Automatic Metallic Surface Defect Detection and Recognition with Convolutional Neural Networks
## 3 Detection Module
### CASAE Architecture  
AE networks are widely used for information coding and reconstruction [37]. In general, an AE network includes an encoder network and a decoder network, which consists of one or many blocks of decoder layers. The encoder network is a transformation unit, through which the input image is converted into a multi-dimensional feature image for feature extraction and representation. Rich semantic information exists in the acquired feature maps. On the contrary, the decoder network fine-tunes the pixel-level labels by merging the context information from the feature maps learned in all of the middle layers. Moreover, the decoder network can use an up-sampling operation to restore the final output to the same size as the input image. Since metallic surface defects are the local anomalies in the homogeneous texture, defects and background textures have different feature representations. We utilize the AE network to learn the representation of defect data and find the common features of metallic surface defects. Therefore, the problem of metallic surface defect detection is turned into an object segmentation problem. The input defect image is transformed to a pixel-wise prediction mask with the encoder-decoder architecture. In our CASAE, new image segmentation architecture is based on a cascade of two AE networks. These two AE networks share the same structure. As can be seen from Figure 2, the prediction mask of the first network serves as the input of the second network, and the further fine-tunes of the pixel labels are performed in the second network. In this way, the latter network can enhance the prediction results  
Figure 2: The pipeline of the proposed metallic surface defect inspection architecture. (**a**) Original image, (**b**) defect segment, (**c**) defect location, (**d**) cropped results, and (**e**) classification. of the previous one. The single AE architecture is illustrated in Figure 3. The same defects, such as damage spots, have different colors because of the different metal surface films. This ambiguous color can affect the training of the AE network. Therefore, the original color image is normalized to a 512 \(\times\) 512 grayscale image, and then inputted it into the AE network for reducing color interference and faster defect segmentation. The architecture consists of an encoder section (to the right) and a decoder section (to the left). The decoder network has a similar structure to the encoder network. The encoder section includes 10 convolution layers, with each containing 3 \(\times\) 3 convolution operations and subsequent rectified linear unit (RELU) non-linear operations. Each of the two convolutional layers is followed by a 2 \(\times\) 2 max pooling operation with stride 2. We double the number of features after each max pooling layer in order to reduce the loss of semantic information [38; 39]. After each of the two convolutional layers, a 2 \(\times\) 2 up-sampling operation is applied in the decoder section. The result of the up-sampling operation is concatenated to the corresponding feature map from the encoder section to obtain the final feature maps. At the final layer, a 1 \(\times\) 1 convolution with a softmax layer is attached to the AE network to transform the output to a probability map. The final prediction mask is the defect probability map, which is resized to the same size of the input image. There are stable convolution ranges in the above AE network. It is difficult for this network to \"see\" the entire defect and integrate a global context in producing the prediction mask. In a real industrial inspection environment, the size and shape of the defects are various. The above network would have no understanding that there are larger detection objects on the metallic surface, such as dust and fibers. Therefore, receptive fields of different sizes must be designed to accommodate this situation. In this paper, atrous convolution [40] is unitized to increase the receptive fields of the network for detecting large defects.