# Deep Learning-Based Oyster Packaging System
## 2 Oyster Packaging System
### Deep Learning-Based Oyster Detection Model
The backbone section is mainly for oyster feature extraction. Focus was replaced with an equivalent Conv for better exportability, and the C3 structure was mainly used in the backbone feature extraction network. The C3 module is based on the cross-stage partial architecture for learning residual features from the input image. The structure is divided into two paths, one path goes through three convolutional layers and multiple bottlenecks, while the other path goes through only one convolutional layer, and finally, the two paths are connected. There is also a spatial pyramid pooling (SPP) module at the end of the feature extraction, which uses a cascade of multiple small-size pooling kernels instead of a single large-size pooling kernel in the SPP module, resulting in the preservation of the original functionality. This approach fuses the feature maps of different sensory fields and further improves the running speed part in the case of enriching the expressive ability of the feature maps. Figure 3: Deep learning-based oyster detection model. The main purpose of the neck part of the model is to better utilize the oyster features extracted from the backbone for feature fusion and enhancement. Instead of blindly deepening the network, the residuals are no longer added to the C3 module. The neck part adopts a path aggregation network (PAN) structure, which improves the receptive field of the network and makes it more robust in oyster detection tasks by fusing the bottom- and top-level features and expanding the fused features by upsampling and downsampling the features. The prediction section of the model optimizes the predicted output by constructing multiple loss functions and NMS operations. The loss function is constructed to evaluate the difference between the true value and the prediction of the network. The loss function of this model consists of bounding box regression localization loss (\(b_{box_{loss}}\)), object classification loss (\(L_{cls_{loss}}\)), and confidence loss (\(L_{con_{loss}}\)). In target detection tasks, the regression loss typically uses the intersection over union (_IOU_) to calculate and label the coordinate distance between the true frame and the prediction frame of the network. In certain scenarios, there may be multiple possible ways for objects with the same _IOU_ to intersect, making it difficult to describe how the ground truth boxes and predicted boxes intersect. Therefore, YOLOv5 adopts generalized intersection over union (_GIOU_) to describe the localization loss of the bounding box. The _IOU_ and _GIOU_ are calculated as shown in Equations (1) and (2). \[IOU=\frac{A\cap B}{A\cup B} \tag{1}\]  
\[GIOU=\frac{A\cap B}{A\cup B}-\frac{|C-(A\cup B)|}{|C|} \tag{2}\]  
where \(A\) represents the labeled true frame, \(B\) represents the predicted frame of the model, and \(C\) represents the minimally convex closed frame of \(A\) and \(B\). The \(L_{cls_{loss}}\) evaluates the accuracy of the predicted category labels with respect to the true labels using binary cross entropy, which is shown in Equations (3) and (4). \[L_{cls_{loss}}=\frac{\sum_{i\in pos\sum_{j=cls}\left(O_{ij}\ln\left(\hat{c_{ ij}}+\left(1-O_{ij}\right)\ln\left(1-\hat{c_{ij}}\right)\right)\right)}}{N_{pos}} \tag{3}\]  
\[\hat{c_{ij}}=Sigmoid\left(C_{ij}\right) \tag{4}\]  
where \(O_{ij}\) represents whether the \(i\)-th prediction frame contains target \(j\), \(C_{ij}\) represents the target prediction probability, \(\hat{c_{ij}}\) represents the prediction confidence of \(C_{ij}\) calculated by the Sigmoid function, and Npos represents the number of positive samples. \(L_{con_{loss}}\) is also calculated using binary cross entropy as shown in Equations (5) and (6).