# Prediction of Residual Stress of Carburized Steel Based on Machine Learning
## 3 Method  
### Data Processing  
1. Data processing: The image resolutions in the dataset were not uniform; their lengths and widths ranged between 200 and 550 pixels. The minibatch training method requires the input image size to be consistent; therefore, the input images needed to be cropped. First, the long side of the image was left unchanged, and padding was added to both sides of the image (pixels with 0 values were added). Then, nearest-neighbor interpolation was used to scale the image to 384 \(\times\) 384. This processing step not only yields input images of the same size but also ensures that the aspect ratio of the original image is unchanged and that the structural information of the target is retained to the utmost degree. Although this method adds considerable padding, the network treats it as redundant information; thus, the added pixels are not used during training. It should be noted that the original images were also cropped, and the ground truth labels of the image needed to be cropped accordingly.
2. Data enhancement: Although the CNN greatly reduces the number of parameters that must be learned due to its weight sharing function, the number of parameters in the network still reaches hundreds of millions. This enormous number of parameters requires large amounts of data; training from too few data samples will lead to insufficient network generalizability, overfitting, and other problems. To enrich the data samples, the following data augmentation operations were performed on the training set: (1) horizontal flipping: during the training process, each iteration flipped the image left or right at a probability of 0.5; (2) panning: the input image was randomly translated horizontally and vertically within a range of 20 pixels; (3) rotation: the image was rotated randomly at an angle, ranging from \(-20\) to \(20^{\circ}\); (4) noise: Gaussian random noise with a mean of 0.2 and a variance of 0.3 was added to the image.
3. Data set labeling and production: To identify steel microstructures, it was first necessary to use a labeling tool such as LabelMe to manually mark the positions of acicular martensite, retained austenite, and lath martensite in the original image data, as shown in Figure 3. A total of 1200 material microstructure pictures were marked. During the marking process, the microstructure label information of the microstructure was stored in an XML file format that included the path and file name of the original picture, the size of the picture, the label names \"Acicular martensite\", \"Retained austenite\", and \"Batten martensite\" (the same categories as in SegModel-MOS training) and the positional information of each label box. The file format applied with the PASCAL VOC data format, which includes two main folders: Annotations and JPEGImages. The former is mainly used to store the XML files containing the tags, and the latter is used to store the original image data. Finally, the PASCAL VOC data format was converted into a TFRecord data file, which is a binary file that combines images and labels together to make better use of the memory in TensorFlow [25] and achieve fast copy, move, store, read, and other data operations.  
Figure 3: Manual labeling of microstructure pictures: (**a**) original picture; (**b**) manually marked picture (red marked as lath martensite, green marked as retained austenite, black (not marked) as acicular martensite).