# Rapid and Accurate Crayfish Sorting by Size and Maturity Based on Improved YOLOv5
## 3 Method  
### YOLOv5  
Developed by Ultralvtics LLC, YOLOv5 [25] is an object detection algorithm that utilizes deep learning. The lightweight network architecture of YOLOv5 is composed of three main components: feature extraction, fusion, and detection. Specifically, the feature extraction component serves as the Backbone network, the fusion component integrates multi-level features, and the detection component produces bounding boxes and class probabilities. Figure 3 depicts the structure of YOLOv5. The YOLOv5 Backbone architecture primarily consists of Convolution (Conv), Cross-Stage Partial Network (CSP) [26], and Spatial Pyramid Pooling Fast (SPPF). Within Conv, Conv2d, Batch Normalization, and Swish activation function are the primary components. As a critical feature extraction module in YOLOv5, the CSP module ensures the consistency of input and output, reduces the amount of calculation while improving the detection speed, and maintains good detection performance. The SPPF module replaces the single large pooling kernel used in the SPP module with multiple small kernels cascaded in a pyramid structure, which preserves the feature fusion capability and enhances the feature representation ability while further improving the processing speed. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Crayfish Dataset** & & & & **720 (Pixels) \(\times\) 540 (Pixels)** \\ \hline \multirow{6}{*}{Train Set (2725 images)} & Red crayfish & & & \\  & (1296 images) & & & \\  & Small & Medium & Large & Extra large \\  & (363 images) & (357 images) & (365 images) & (211 images) \\ \cline{1-1}  & (2725 images) & Green crayfish & & \\  & (1433 images) & & & \\  & Small & Medium & Large & Extra large \\  & (584 images) & (373 images) & (364 images) & (112 images) \\ \hline \multirow{6}{*}{Test Set (734 images)} & Red crayfish & & & \\  & (352 images) & & & \\ \cline{1-1}  & Small & Medium & Large & Extra large \\ \cline{1-1}  & (114 images) & (93 images) & (91 images) & (54 images) \\ \cline{1-1}  & Green crayfish & & & \\ \cline{1-1}  & (383 images) & & & \\ \cline{1-1}  & Small & Medium & Large & Extra large \\ \cline{1-1}  & (137 images) & (123 images) & (93 images) & (30 images) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Crayfish dataset. Figure 2: (**a**–**h**) Images represent the annotation results for green, small crayfish; green, medium crayfish; green, large crayfish; green, extra-large crayfish; red, small crayfish; red, medium crayfish; red, large crayfish; and red, extra-large crayfish; (**i**) represents the ID and coordinate information of the annotation of red, large crayfish in (**c**); the category corresponding to the ID is the sixth category, that is, the red, medium crayfish, coordinate information refers to the normalized coordinates of the bounding box. The Neck part of YOLOv5's feature fusion refers to the Feature Pyramid Network (FPN) [27] and the Path Aggregation Network (PANet) [28]. The Feature Pyramid Network (FPN) proposes an effective solution, which is to propagate the semantic information from deep features to shallow ones and improve the expression of multi-scale features' semantics. PANet is a multi-scale feature fusion method. Based on FPN, PANet introduces a bottom-up pathway that enables both top-down and bottom-up feature fusion with lateral connections. This enhances the representation of position and semantic information at various output levels, thereby optimizing the model's feature extraction capability. The Head section of YOLOv5 serves as the output layer of the object detection model, responsible for predicting the class and location of objects. For each feature map, the Head section expands the channel number and uses 1 \(\times\) 1 convolution to expand the channel number to (number of classes + 5) \(\times\) (number of anchors per detection layer), where 5 corresponds to the predicted bounding box's center coordinates, width, height, and confidence score.