## 3 Materials and Methods
### Improved YOLOv8 Model  
In the complex growth environment, due to the influence of many factors, such as similar background color, mutual occlusion between branches and fruit, or different fruit size, it is difficult to detect the target accurately, or the detection accuracy is not high by using the traditional detection method in the process of detecting tomato maturity. In order to more accurately locate tomato fruits and identify tomato maturity categories, we propose an improved YOLOv8 method. This method can improve the detection accuracy and efficiency of tomato ripeness.  
In this study, we made several key improvements to the YOLOv8 model to further enhance its performance in tomato ripeness detection. The structure of the improved model is shown in Figure 3. First, we introduced the Swin Transformer module in the backbone network part of YOLOv8. The core idea of this improvement is to enhance the global modeling capability of features with the help of the transformer mechanism. Especially when dealing with long-range dependencies, the self-attention mechanism of Swin Transformer can capture fine-grained contextual information more effectively. This feature is particularly important in the tomato ripeness detection task, as ripeness judgments are often based on subtle color variations and texture differences on the surface of tomato fruits, and Swin Transformer is able to improve the ability to discriminate between small and similar targets (e.g., tomatoes at different ripeness stages) in the presence of complex light variations and background noise, thus significantly improving the accuracy of ripeness detection.  
Second, in the neck section, we make an important adjustment to the convolution structure in C2f by using Distribution Shifting Convolution instead of the original standard convolution. Distribution Shifting Convolution enhances feature diversity and invariance through shifting operations, which is particularly effective in multi-scale tomato detection. Especially in the case of tomato fruits with irregular shapes and large size differences, the Distribution Shifting Convolution can better capture the local features at different scales, which improves the robustness and adaptability of the model, and makes it more discriminative when dealing with tomatoes at different stages of ripeness.  
Finally, for the loss function, we replace the original CIOU loss function with the Focal-CIOU loss function. This new loss function combines the weighting mechanism of Focal Loss with the accuracy-enhancing property of EIOU, which is more effective in facing the category imbalance problem. In the tomato ripeness detection task, there is a category imbalance between unripe and overripe tomatoes and the traditional loss function often finds it difficult to accurately distinguish between these categories.The Focal-CIOU loss function is able to dynamically adjust the weights of the difficult-to-classify samples, paying special attention to those tomatoes that are at the boundary of the ripeness judgment, which significantly improves the model's detection accuracy on the complex dataset. Compared with traditional CIOU, Focal-EIOU can more accurately optimize target localization and classification when dealing with small and distant targets, which further improves the accuracy of tomato ripeness determination.