# FIQ: A Fastener Inspection and Quantization Method Based on Mask FRCN
## 4 FiQ--A Fastener System Inspection and Quantization Method Based on Mask FRCN
### A Quantization Method Based on Random Forest to Estimate Fastener Status  
In this section, we proposed the Fully Refined Convolutional Network (FRCN), a deep learning-based image segmentation module. Traditional segmentation methods tend to result in blurry and imprecise boundaries at the edges of rail fasteners, which leads to a decrease in segmentation accuracy and precision. To address this issue, the present study proposes the use of FRCN to optimize the boundaries of image segmentation. Although the data have already undergone segmentation, the boundaries of the segmentation are not precise enough, and hence, further optimization using FRCN is necessary to improve the accuracy and precision of the segmentation. Here is the paragraph split into several parts:  
We propose a method for evaluating the quality of fasteners based on random forest. The method includes the following steps:  
1. Selecting six feature points, including the top, bottom, and leftmost and rightmost points, as well as the top vertex and bottom point of the boundary, by segmenting the boundary of the fastener. 2. Calculating the Euclidean distance between each pair of feature points and the angles between the points, which yields four lines \(P_{1}P_{2}\), \(P_{1}P_{3}\), \(P_{2}P_{4}\), and \(P_{3}P_{4}\), as well as the angles \(\theta P_{5}P_{3}P_{4}\), \(\theta P_{6}P_{3}P_{2}\), respectively. The Euclidean distance between two points \((x_{1},y_{1})\) and \((x_{2},y_{2})\) is calculated using the formula:  
\[d=\sqrt{(x_{2}-x_{1})^{2}+(y_{2}-y_{1})^{2}}. \tag{5}\]  
\[theta=\cos^{-1}\left(\frac{\vec{v_{1}}\cdot\vec{v_{2}}}{|\vec{v_{1}}||\vec{v_{ 2}}|}\right). \tag{6}\]  
3. Using random forest to calculate the weights of the image features that determine the state of the fastener by annotating the fasteners in the existing dataset as normal, damaged, or missing. Random forest is a type of ensemble learning method based on decision trees that can improve the robustness and generalization of the model by randomly sampling and selecting features to construct multiple decision trees. 4. Assigning weights to the features to obtain a preliminary evaluation system that can preliminarily assess the quality of the fastener. The physical quantities used in this method include the Euclidean distances \(P_{1}P_{2}\), \(P_{1}P_{3}\), \(P_{2}P_{4}\), \(P_{3}P_{4}\), \(P_{1}P_{4}\), \(P_{2}P_{4}\), the angles \(\angle P_{1}P_{3}P_{4}\) and \(\angle P_{1}P_{2}P_{3}\), as well as the fastener-connected component area, fastener detection box length, and fastener detection box height. 5. Combining the evaluation system with the fastener template with the highest score obtained by evaluating the existing dataset using the system and using a second random forest weight assignment to obtain the final evaluation system. This can more accurately assess the quality of the fastener and improve the objectivity and accuracy of the evaluation. The weight of each feature contributes to the final evaluation system and can be calculated using the following formula:  
\[w_{i}=\frac{1}{n}\sum_{j=1}^{n}\frac{\partial L(y_{j},f(x_{j}))}{\partial x_{ij}}. \tag{7}\]  
where \(n\) is the number of training samples, \(f(x_{j})\) is the predicted value of the \(j\)-th sample, \(y_{j}\) is the true label of the \(j\)-th sample, \(L(y_{j},f(x_{j}))\) is the loss function that measures the difference between \(y_{j}\) and \(f(x_{j})\), and \(\frac{\partial L(y_{j}f(x_{j}))}{\partial x_{ij}}\) is the gradient of the loss function with respect to the \(i\)-th feature of the \(j\)-th sample. The proposed method for evaluating the quality of fasteners based on random forest has several advantages. Firstly, the method selects feature points and calculates image features that can more comprehensively reflect the state of the fastener. Secondly, the random forest algorithm is used to calculate the weights of the image features, which can more accurately evaluate the quality of the fastener.