## 3 Methodology
### The Detection Module of Materials  
In the multi-crane visual sorting system, we apply the YOLOv5 algorithm to locate the materials on the conveyor belt, the architecture of which is shown in Figure 3, which consists of backbone, neck, and prediction. The backbone aims to learn significant features of the original images. In the neck, a path aggregation network is applied to generate feature pyramids and achieve more useful features from the low and high layers. The prediction module outputs the coordinates, classification, and confidence score of the predicted bounding box, which are \((x_{1},y_{1},x_{2},y_{2},\ C,\ P)\). \((x_{1},y_{1})\) denotes the lower-left corner coordinates and \((x_{2},y_{2})\) represents the upper-right coordinates of the bounding box. \(C\) is the classification of the bounding box. \(P\) is the confidence score that reflects how accurate the bounding box is predicted. These five vectors can be utilized to calculate the loss to optimize the network. The total loss of YOLOv5 contains regression loss, classification loss, and confidence loss. **Regression Loss. ** We use the diagonal coordinates \((x_{1},\ \ y_{1},\ \ x_{2},\ \ y_{2})\) of the predicted and truth values for the bounding box regression. The generalized intersection over union (GIoU) method is used as the regression loss to let the predicted coordinate close to the truth coordinate. Compared with IoU, GIoU can solve the problem that the loss value is 0 when the predicted bounding box and the truth bounding box do not overlap. The diagram of IoU and GIoU are shown in Figure 4, in which \(A\) is the predicted bounding box and \(B\) is the truth bounding box. We first calculate IoU, that is the ratio of intersection area and union area between \(A\) and \(B\). Then, we find the smallest box \(C\) that includes \(A\) and \(B\). The  
Figure 3: The YOLOv5-based detection network of Chinese cheses. Figure 2: Example of CNN structure. difference between area \(C\) and the union area is obtained. GIoU is the ratio of the difference and area C. The regression loss is given by:  
\[L_{reg}=1-GloU=1+\frac{A^{C}-A^{U}}{A^{C}}-IoU \tag{1}\]  
where \(A^{C}\) is the area of \(C\) that is the smallest box that includes \(A\) and \(B\). \(A^{U}\) is the area of the union between the truth box \(A\) and the prediction box \(B\). **Classification Loss. ** Binary Cross-Entropy with Logits Loss is used to recognize and optimize the classification of the materials. The classification loss is summarized as:  
\[L_{cls}=\frac{1}{N}\sum_{i=1}^{N}[\hat{C}_{i}ln(sigmoid(C_{i}))+\big{(}1- \hat{C_{i}}\big{)}ln(1-sigmoid(C_{i}))] \tag{2}\]  
where \(N\) is the value of the min-batch, \(C_{i}\) is the predicted class, and \(\hat{C_{i}}\) is the truth class. _sigmoid_ is the sigmoid function that is [0, 1]. **Confidence Loss**. Binary Cross-Entropy with Logits Loss is used to optimize the confidence of the bounding box. The confidence loss is summarized as:  
\[L_{con}=\frac{1}{N}\sum_{i=1}^{N}[\hat{P}_{i}ln(sigmoid(P_{i}))+\big{(}1- \hat{P_{i}}\big{)}ln(1-sigmoid(P_{i}))] \tag{3}\]  
where \(N\) is the value of the min-batch, \(P_{i}\) is the prediction of the confidence, and \(\hat{P_{i}}\) is the truth of the confidence. The value of \(\hat{P_{i}}\) is [0,1]. The total loss of YOLOv5 is:  
\[L_{total}=\lambda_{1}L_{reg}+\lambda_{2}L_{cls}+\lambda_{3}L_{con} \tag{4}\]  
where \(\lambda_{1}\), \(\lambda_{2}\), and \(\lambda_{3}\) are weights of the three losses. We only obtain the pixel coordinates of objects that cannot be used by cloud PLC. Camera calibration [17] is used to describe the collection between the pixel coordinate system and the world coordinate. We define the pixel coordinate system (\(u\), \(v\)) and the world coordinate system (\(X_{w}\), \(Y_{w}\), \(Z_{w}\)). \(P_{w}\) presents a real P point. The relation between the pixel coordinate system and the world coordinate system can be obtained as:  
\[Z_{c} \begin{bmatrix}u\\ v\\ 1\end{bmatrix} =