Search

CN-121982704-A - Fruit sorting method and system based on improved attention mechanism

CN121982704ACN 121982704 ACN121982704 ACN 121982704ACN-121982704-A

Abstract

The invention discloses a fruit sorting method and system based on an improved attention mechanism, which belong to the field of intersection of computer vision and agricultural automation technology and comprise the steps of acquiring fruit images to be sorted, inputting the fruit images to be sorted into a trained fruit sorting model, and outputting the types and quality states of fruits, wherein training of the fruit sorting model comprises the steps of constructing a fruit image data set, constructing a fruit sorting model, introducing improved cascading group attention based on an existing YOLOv model, and training the fruit sorting model on the constructed data set to obtain the trained fruit sorting model. The invention is specially designed aiming at the automatic sorting scene of fruits, can effectively solve the problems of real-time identification and accurate sorting under the complex conditions of multi-category fruits mixing, various appearance states and the like, and provides core technical support for intelligent upgrading of modern agricultural sorting equipment.

Inventors

  • FAN YU
  • LIU JIAMING
  • WANG JIEMING
  • CHEN BINGYI

Assignees

  • 肇庆学院

Dates

Publication Date
20260505
Application Date
20260123

Claims (10)

  1. 1. A method of sorting fruit based on an improved attention mechanism, comprising: acquiring a fruit image to be sorted; inputting a fruit image to be sorted into a trained fruit sorting model, and outputting the category and quality state of the fruit, wherein the training of the fruit sorting model comprises the following steps: constructing a fruit image dataset; The fruit sorting model is constructed by introducing an improved cascade group attention replacement part convolution module based on the existing YOLOv model, wherein the improved cascade group attention is added with a dynamic grouping strategy based on the original cascade group attention, and input features are segmented into dynamic grouping numbers in a channel dimension for enhancing feature characterization capability and reducing calculation complexity; training the fruit sorting model on the constructed fruit image dataset to obtain a trained fruit sorting model.
  2. 2. A fruit sorting method based on an improved attention mechanism according to claim 1, characterized in that inputting the fruit image to be sorted into a trained fruit sorting model comprises: Converting the extracted feature images of the fruit images to be sorted into binary images, removing noise and selecting target contours; based on the target contour, calculating an aspect ratio by using a minimum circumscribed rectangle, and further calculating to obtain compactness; Calculating a target form factor according to the aspect ratio and the compactness; Dynamic grouping is carried out based on the target form factors, and feature group division is carried out on the binary image in the channel dimension according to the group number of the dynamic grouping; And performing cascade attention calculation according to the divided feature groups.
  3. 3. A fruit sorting method based on an improved attention mechanism according to claim 1, characterized in that calculating the target form factor from the feature map comprises: , In the formula, Representing the target form factor, AR representing the aspect ratio, compactness representing the compactness.
  4. 4. A method of sorting fruit based on an improved attentiveness mechanism as claimed in claim 1, in which the dynamic grouping is based on a target form factor, comprising: , In the formula, The target form factor is represented by a set of values, <0.4 For near circular fruits, 0.4< <0.7 Represents a near-oval fruit, >0.7 Represents a near-elongate fruit, Indicating the number of packets.
  5. 5. A fruit sorting method based on an improved attention mechanism according to claim 1, characterized by cascade attention computation based on partitioned feature sets, comprising: processing the divided feature groups sequentially by adopting cascade serial, wherein the output of the former attention head is used as the input of the latter attention head; based on the processed feature set, an aggregate feature representation is obtained by self-attention computation.
  6. 6. A fruit sorting method based on an improved attention mechanism as claimed in claim 5, wherein the deriving the aggregate feature representation by self-attention computation based on the processed feature set comprises: performing linear transformation on the processed feature set to obtain a query tensor, a key tensor and a value tensor; and calculating by adopting a normalized exponential function based on the query tensor, the key tensor and the value tensor to obtain the aggregation characteristic representation.
  7. 7. A fruit sorting system based on an improved attention mechanism, comprising: The data acquisition module is used for acquiring fruit images to be sorted; the fruit sorting module is used for inputting fruit images to be sorted into a trained fruit sorting model and outputting the category and quality state of the fruits, wherein the training of the fruit sorting model comprises the following steps: constructing a fruit image dataset; The fruit sorting model is constructed by introducing an improved cascade group attention replacement part convolution module based on the existing YOLOv model, wherein the improved cascade group attention is added with a dynamic grouping strategy based on the original cascade group attention, and input features are segmented into dynamic grouping numbers in a channel dimension for enhancing feature characterization capability and reducing calculation complexity; training the fruit sorting model on the constructed fruit image dataset to obtain a trained fruit sorting model.
  8. 8. An electronic device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor, when executing the computer program, implements the steps of the improved attention mechanism based fruit sorting method of any one of claims 1-6.
  9. 9. A computer readable storage medium having stored thereon a computer program, characterized in that the computer program when executed by a processor implements the steps of the improved attention mechanism based fruit sorting method of any of claims 1 to 6.
  10. 10. A computer program product comprising instructions which, when run on a computer, cause the computer to perform the steps of the improved attention mechanism based fruit sorting method of any one of claims 1 to 6.

Description

Fruit sorting method and system based on improved attention mechanism Technical Field The invention belongs to the technical cross field of computer vision and agricultural automation, and particularly relates to a fruit sorting method and system based on an improved attention mechanism. Background Fruit sorting is a key link in an agricultural industry chain, and the traditional method mainly relies on manual sorting or traditional image processing technology based on colors and forms, and has the problems of low efficiency, high false detection rate, poor adaptability and the like. In recent years, a fruit sorting model (such as a YOLO series) based on deep learning is widely applied to fruit sorting tasks, but the problem still exists that the characteristic extraction is insufficient, the traditional convolutional neural network has limited receptive fields when processing occlusion, overlapping or low-resolution fruit images, and global context information is difficult to capture, so that missed detection or false detection is caused. The attention mechanism redundancy is that the existing transducer attention mechanism has the problem of multi-head redundancy in the calculation process, so that the calculation amount is large, the memory occupation is high, and the deployment in the edge equipment is difficult. The multi-category identification capability is weak, the existing model is optimized for single fruit varieties or states, and the unified identification capability for multi-category (such as apples, bananas and oranges) and quality states (high quality, poor quality and mixed quality) thereof is lacking. In the prior art, the YOLOv model has significantly improved detection speed and basic accuracy, but the feature fusion mechanism has insufficient integration efficiency of multi-scale context information, and the attention module has a problem of computational redundancy. The limitation of the architecture level leads to the challenge that the model is difficult to cope with fruit targets with complex spatial distribution such as overlapping and shielding on one hand, and the deployment capability on mobile equipment is restricted by larger calculation overhead on the other hand, so that the dual requirements of a modern agricultural sorting system on high-precision identification and light-weight operation cannot be met at the same time. Disclosure of Invention The invention aims to provide a fruit sorting method based on an improved attention mechanism aiming at the problems of insufficient feature extraction, redundant attention mechanism, high computational complexity, weak multi-class identification capability and the like in the existing fruit sorting technology, by constructing a fruit sorting model based on an improved attention mechanism, a cascading attention mechanism is provided, multi-category and multi-state identification is supported, and fruit types (apples, bananas and oranges) and quality states (high quality, poor quality and mixed quality) thereof can be identified at the same time, so that high-precision and light-weight target detection is realized. According to an aspect of the present description, there is provided a fruit sorting method based on an improved attention mechanism, comprising: acquiring a fruit image to be sorted; inputting a fruit image to be sorted into a trained fruit sorting model, and outputting the category and quality state of the fruit, wherein the training of the fruit sorting model comprises the following steps: constructing a fruit image dataset; The fruit sorting model is constructed by introducing an improved cascade group attention replacement part convolution module based on the existing YOLOv model, wherein the improved cascade group attention is added with a dynamic grouping strategy based on the original cascade group attention, and input features are segmented into dynamic grouping numbers in a channel dimension for enhancing feature characterization capability and reducing calculation complexity; training the fruit sorting model on the constructed fruit image dataset to obtain a trained fruit sorting model. Further, inputting the fruit image to be sorted into a trained fruit sorting model, comprising: Converting the extracted feature images of the fruit images to be sorted into binary images, removing noise and selecting target contours; based on the target contour, calculating an aspect ratio by using a minimum circumscribed rectangle, and further calculating to obtain compactness; Calculating a target form factor according to the aspect ratio and the compactness; Dynamic grouping is carried out based on the target form factors, and feature group division is carried out on the binary image in the channel dimension according to the group number of the dynamic grouping; And performing cascade attention calculation according to the divided feature groups. Further, calculating a target form factor from the feature map includes: In the