Abstract:In order to enable the inspection robot to efficiently and accurately identify small, dense, morphologically variable, numerous and unevenly distributed pests, a pest recognition method based on the improved YOLO v7 was proposed. CSP Bottleneck was combined with a selfattentional mechanism based on shift window transformer (Swin Transformer), which improved the ability of the model to obtain the location information of dense pests. A fourth detection branch was added to the path aggregation part to improve the detection performance of the model on small targets. The convolutional attention module (CBAM) was integrated into the YOLO v7 model to make the model pay more attention to the pest area, suppress the background and other general feature information, and improve the recognition accuracy of blocked pests. Focal EIoU Loss function was used to reduce the influence of positive and negative sample imbalance on detection results and improve the recognition accuracy. According to the experimental results, the accuracy rate, recall rate and mAP of the improved algorithm were 91.6%, 82.9% and 88.2%, respectively by using the data set established based on the actual farmland environment, which was 2.5, 1.2 and 3 percentage points higher than that of the original model. Compared with other mainstream models, the experimental results showed that the proposed method was more effective in the actual detection of pests, and it had practical application value in solving the problem of accurate identification of pests in complex farmland environment.