# YOLOv7 Optimization Model Based on Attention Mechanism Applied in Dense Scenes
## 5 Application
### Detection in Tomato Dataset  
In the field of object detection, there have been many studies about fruit detection; for example, in [44], there is a systematic summary of the development of picking robots, where the importance of fruit identification techniques is emphasized and the characteristics of different target detection techniques are analyzed to illustrate the feasibility and necessity of the application of target detection techniques in picking robots. On the other hand, in [45], some problems are encountered and the directions for solving them using Nano Aerial Bee (NAB) in agricultural environments are investigated, and the effectiveness of YOLOv7 in practical applications in agricultural environments is tested on the flower detection dataset, demonstrating the robustness of YOLOv7 and the feasibility of its application. In general fruit detection applications for picking robots, it is common to encounter problems such as more complex real-world scenes, too many fruit and vegetable targets, small targets, and a large amount of occlusion, resulting in poor accuracy of the final results and difficulty in accurately identifying fruits. Currently, fruit detection requires high model accuracy and robustness, and the original object detection model can hardly meet its requirements. Therefore, this paper verifies the effectiveness of the above model by applying the application scenario of tomato fruit detection in a dense scene. To verify the superiority of the YOLOv7B-CBAM model in dense scenarios, we completed comparative experiments on the tomato dataset. There are 895 images in the dataset, including 695 images for training, 95 images for validation, and 105 images for testing. The hardware and software environments for the experiments are consistent with those described in Section 4. Figure 5 is the original image of the tomato dataset, and Figure 6 is the image after the detection of the dataset using the YOLOv7B-CBAM model. It can be seen that the blocked tomato in the lower left corner can be accurately identified, and the recognition effect of small objects in dense scenes in the upper right corner image is also very good. Specific experimental data are shown in Table 3. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Model** & **mAP50** & **Parameters (M)** & **GFLOPs** \\ \hline YOLOv5s & 0.9 & 7.01 & 15.8 \\ YOLOv7 & 0.913 & 36.48 & 103.3 \\ YOLOv7H-CA & 0.889 & 36.47 & 103.1 \\ YOLOv7H-SimAM & 0.869 & 36.47 & 103.1 \\ YOLOv7H-CBAM & 0.91 & 36.48 & 103.3 \\ YOLOv7B-CBAM & 0.919 & 36.48 & 103.5 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Results of tomato dataset. Table 3 shows the results obtained for the YOLOv5s, the original YOLOv7 model, and optimized YOLOv7 models by using the attention mechanism on this dataset. The following conclusions can be drawn from the analysis results. As shown in Figure 7, compared with the YOLOv7 model with the attention mechanism added, the accuracy of the proposed YOLOv7B-CBAM model is the best, which  
Figure 5: Image of tomato dataset before detection. Figure 6: Results after identification of YOLOv7B-CBAM model. is 0.6% higher than that of the original YOLOv7 model and 0.9% higher than that of YOLOv7H-CBAM. It is proved that the CBAM module is effective and the model in this paper can identify small objects in complex and dense scenes more accurately. In contrast, YOLOv7H-CA and YOLOv7H-SimAM models performed poorly and had low accuracy in this dataset. The reason may be that the robustness of these two attention mechanisms was poor, and it was difficult to ensure accuracy in dense or complex scenes, which hurt accuracy. The comparison shows that the improved YOLOv7B-CBAM model in this paper has higher robustness and can still maintain a high recognition rate in dense scenes and accurately identify tomatoes. The model can be integrated into an intelligent tomato-picking robot in practical applications to automate the tomato-picking process.