CN-122024228-A - Blueberry fruit detection method based on improved contrast loss
Abstract
The invention relates to a blueberry fruit detection method based on improved contrast loss, and belongs to the technical field of computer vision. The method comprises the steps of obtaining a blueberry image and preprocessing to obtain a blueberry image data set to be detected, improving a traditional YOLOv model to obtain a YOLOv-ERG model, wherein the improvement comprises the steps of constructing RCL loss based on SCL loss to obtain total loss, introducing a GD mechanism to improve a neck network of a traditional YOLOv model, introducing an EMA module into a shallow structure of a main network of the traditional YOLOv model, and inputting the blueberry image data set to be detected into the trained YOLOv-ERG model to obtain a blueberry fruit detection result output by the YOLOv-ERG model. The method aims at solving the technical problems that the prior art has large causal real-size difference, serious shielding and complex color in a complex scene, and the detection accuracy is difficult to ensure.
Inventors
- FU CHENGBIAO
- CHEN FAN
- TIAN ANHONG
- SUN YEJUN
Assignees
- 昆明理工大学
Dates
- Publication Date
- 20260512
- Application Date
- 20260204
Claims (4)
- 1. A blueberry fruit detection method based on improved contrast loss, the method comprising the steps of: step1, acquiring a blueberry image and preprocessing to obtain a blueberry image dataset to be detected; step2, improving a traditional YOLOv model to obtain a YOLOv-ERG model, wherein the improvement is as follows: The improvement is that the RCL loss is constructed based on SCL loss to obtain total loss; introducing GD mechanism to improve neck network of traditional YOLOv model; Introducing an EMA module into a shallow structure of a main network of a traditional YOLOv model; Step3, inputting the blueberry image dataset to be detected into a trained YOLOv-ERG model to obtain a blueberry fruit detection result output by the YOLOv-ERG model.
- 2. The method for blueberry fruit detection based on improved contrast loss as claimed in claim 1, wherein the improvement is specifically: Building weighting factors based on task consistency The expression is: ; Wherein, the Represent the first The intersection ratio of the predicted bounding box and the predicted real box obtained after the regression head is adopted by the characteristics, Represent the first The highest predicted score that the individual feature gets after passing the classification head, And A factor for adjusting the crossover ratio and the highest predictive score importance; The linear interval remapping strategy is used for applying a weighting factor based on task consistency, and the feature weight value larger than the threshold value is increased again by using conditional addition, specifically: ; ; Wherein, the Representing the weights after linear interval remapping adjustment, And is also provided with ; Represents the final weight value after conditional addition, The threshold value is indicated and the threshold value, Representing the offset; the RCL loss is obtained through the weighting of the anchor point level, and the expression is: ; Wherein, the For the loss of the RCL, The positive sample anchor sample index for all samples of a batch, Representing the number of anchor points for all pictures in a batch, Is the first The loss value of the individual samples is calculated, Representation and the first Weights with consistent categories and inconsistent indexes of the anchor points, Positive sample set to introduce difficult sample mining strategy, and , wherein, For the set of indices that result after sampling, Is the first The labels of the individual sample anchor points, Expressed and indexed as All other indices of the same anchor prediction class, Indicating all sample indexes except the current index, Is a temperature factor, is used to control the non-linear scaling degree of the similarity score, Representation and the first The anchor points are of the same category and are not indexed Is characterized by the other anchor point of (c), Representation and the first The characteristics of the anchors of different anchor categories, Is a hidden space feature; Combining the RCL loss with the loss of the conventional YOLOv model in a weighted sum manner yields the total loss The expression is: ; Wherein, the 、 、 The main task loss defined for the traditional YOLOv model is a positioning loss, a classification loss and a distribution focusing loss respectively, Representing the weights.
- 3. The blueberry fruit detection method based on improved contrast loss as claimed in claim 1, wherein the improvement is realized based on a GD mechanism, wherein the GD mechanism comprises a Low-GD module and a High-GD module, and the GD mechanism is used for collecting and fusing feature graphs from different layers, and then using an injection module Inject to fuse the fused features with original features of each layer, so as to complete a feature fusion process, wherein the Low-GD module and the High-GD module both comprise a feature alignment module FAM and an information fusion module IFM, specifically: The neck network aligns features from different levels of the backbone network in the FAM module of the Low-GD module , , , Then fusing in the IFM module of the Low-GD module, specifically by RepBlock Fusion is carried out to obtain Thereafter utilizing a channel splitting operation Will be Global features divided and injected into branches B3 and B4, named And , wherein, In order for the features to be aligned, For the number of channels from the feature map at different levels of the backbone network, For fusion features obtained after passing through the IFM module, the Inject module is used for connecting And Features injected into the B3 and B4 branches, and features of the B5 branch are directly filtered to form features L3, L4 and L5 fused for the first time; The FAM module of the High-GD module uses an average pooling layer to align the features L3, L4 and L5 fused for the first time to obtain Then will The FAM module is sent into the High-GD module, and the fusion characteristics are obtained by utilizing the transducer module to perform characteristic fusion Finally, using channel division operation Will be Divided into , , 、 Respectively fusing with the corresponding characteristics L4 and L5 to finish characteristic fusion, the multi-level characteristics R5, R4 and R3 finally fed into the detection head are obtained.
- 4. The blueberry fruit detection method based on improved contrast loss of claim 1, wherein the improvement is realized based on an EMA module, wherein the EMA module comprises a convolution kernel of size And In particular two parallel branches of (a) For input feature graphs , wherein, 、 、 The number of channels, the height of the feature map and the width of the feature map are respectively input to the EMA module, and the EMA module inputs the feature map according to the channels Divided into Sets of different sub-feature maps, each set comprising Channels, define Denoted as the first A sub-feature map in which All sub-feature graphs are fed into parallel Branching and Branching, where In the branches, the sub-feature map is sent into two parallel sub-branches, and the two parallel sub-branches firstly extract the vertical global features and the horizontal global features of the sub-feature map through a one-dimensional pooling layer respectively, and the expression is as follows: ; ; Wherein, the And Representation channel A horizontal and a vertical one-dimensional feature map on the upper surface, Is shown in the first A characteristic value of a certain position on each channel; Will be And Splice along vertical direction and pass through one The convolution module of the convolution kernel establishes the connection between the channel and the position information, the obtained fused feature map is divided into a vertical global feature and a horizontal global feature again, the vertical global feature and the horizontal global feature are activated by a Sigmoid function to obtain weights in the vertical direction and the horizontal direction respectively, the weights of the sub feature map are weighted to obtain the fused feature map, the fused feature map is subjected to group normalization processing, and then average pooling and soft maximum operation are sequentially carried out, so that the method is generated Is expressed as follows: ; In the formula, A global space feature map representing the c-th channel in the vertical direction and the horizontal direction; Will be Global space feature map of branches After a Softmax operation, and from Matrix multiplication and shape transformation of convolved sub-feature map features In another fused path, the group feature map is passed through The convolution is then carried out by a global pooling layer Global spatial feature map of branches, again with the data from And finally, the EMA module independently performs nonlinear mapping on each spatial position of the feature map after element-by-element addition of the two weighted feature maps by using a Sigmoid function to obtain a final weighted feature map, and multiplies the final weighted feature map with the sub-group feature map to obtain a final output feature map.
Description
Blueberry fruit detection method based on improved contrast loss Technical Field The invention relates to a blueberry fruit detection method based on improved contrast loss, and belongs to the technical field of computer vision. Background The blueberry belongs to the azalea family, is an economic crop with high value, can be manufactured into various products with unique flavor and rich nutrition, and is widely planted in the world. Research shows that the blueberry has strong nutritional value and medical use, and contains high-content bioactive compound (BAC) substances and rich phenolic compounds. BAC has been proposed to have inhibitory effects on pathogenic bacteria, while phenolic compounds, particularly anthocyanins, have many valuable health benefits including antioxidant properties, antidiabetic effects and antibacterial effects. However, the nutritional value and economic effect of blueberry fruits are greatly influenced by picking time, on one hand, blueberry is a jump breathing type fruit, the quality of the blueberry fruits after ripe picking is reduced along with the time, the blueberry fruits are easy to be infected by microbiota in the storage process, the postharvest service life of the blueberry fruits is usually short, on the other hand, the characteristic that the blueberry fruits in the same cluster are inconsistent in ripening time directly results in a longer picking period, and the picking cost is increased. Therefore, the proper picking time is selected and the picking period is shortened, so that the nutrition value and the economic effect of the blueberries can be improved. The identification and detection of the maturity of agricultural fruits plays an important role in intelligent agriculture and in the field of precise agriculture, can reduce the influence of labor force, production cost and environment, and simultaneously improves the resource efficiency to the greatest extent. In conclusion, the research on the detection of the maturity of the blueberry fruits has important value and significance for the development of the blueberry industry. Extensive research is directed to detection classification for fruits of different maturity, which can be broadly divided into traditional and depth model methods. Traditional methods rely on computer vision methods or manual extraction of features and use machine algorithms to detect or classify fruit maturity. The methods of Tan, lee, gu and Li are effective in limited scenes, but are limited by manual feature design, manual region-of-interest division and other problems, and have poor robustness in complex scenes. The deep learning method utilizes a deep learning network to automatically extract features, and is more universal and robust compared with the traditional method. In recent years, there has been little work on depth models for target detection of agricultural crops. Depth models have also been used in research of blueberry fruit related work, some of which utilize segmentation models and cluster detection models to perform fruit phenotype analysis on blueberry fruits. Although research by using a depth model achieves good results in some fields, the fruits are blocked in the blueberry detection task, and different colors and size differences of the fruits are caused by the blocking. Careful design of the model is also required for these specific problems. Therefore, the invention selects the YOLO series eighth generation algorithm YOLOv11, improves the YOLO series eighth generation algorithm YOLOv on the basis, and provides a YOLOv-ERG model for detecting blueberry fruits with different maturity under complex scenes. Disclosure of Invention The invention aims to provide a blueberry fruit detection method based on improved contrast loss, and aims to solve the technical problems that in the prior art, the causal real size difference is large, the shielding is serious, the color is complex, and the detection accuracy is difficult to guarantee under a complex scene. In order to achieve the aim, the technical scheme of the invention is that the blueberry fruit detection method based on improved contrast loss comprises the following steps: step1, acquiring a blueberry image and preprocessing to obtain a blueberry image dataset to be detected; step2, improving a traditional YOLOv model to obtain a YOLOv-ERG model, wherein the improvement is as follows: The improvement is that the RCL loss is constructed based on SCL loss to obtain total loss; introducing GD mechanism to improve neck network of traditional YOLOv model; Introducing an EMA module into a shallow structure of a main network of a traditional YOLOv model; Step3, inputting the blueberry image dataset to be detected into a trained YOLOv-ERG model to obtain a blueberry fruit detection result output by the YOLOv-ERG model. Optionally, the improvement is as follows: Building weighting factors based on task consistency The expression is: Wherein, the Represent the firstThe i