Deep learning-based flower production place detection method and model building method thereof
By optimizing the YOLOv10 model, the windmill convolution PConv and the double-layer routing attention mechanism were introduced, and combined with the full adaptation threshold focus loss function, the efficiency and accuracy problems in the adulteration detection in the flower production site were solved, achieving efficient and stable detection effects.
Patent Information
- Application Number
- CN202510641578.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-19
- Publication Date
- 2025-08-08
AI Technical Summary
The prior art is inefficient in the detection of adulteration in flower production sites and is susceptible to human factors, making it difficult to achieve efficient and accurate detection, especially for the problems of color, morphology and sensitivity of peanut grains.
The YOLOv10-BAPNet model based on deep learning is adopted, and the feature extraction capability is enhanced by introducing the wind turbine convolution PConv module, combining the two-layer routing attention mechanism and the fully adapted threshold focus loss function, the YOLOv10 model is optimized to improve detection accuracy and robustness.
It realizes accurate identification of adulteration detection in flower production sites, improves detection accuracy and model adaptability in complex environments, reduces calculation costs, and meets real-time monitoring needs.
Smart Images

Figure CN120451746A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing and detection of computer vision, and in particular relates to a flower production site detection method based on deep learning and a model building method thereof. Background Art
[0002] Peanuts, as a key cash crop in agricultural production, have garnered widespread attention. Laixi peanuts, thanks to their unique geographical location (irrigation by water systems like the Dagu River and a long frost-free season) and advanced cultivation techniques (such as the promotion of high-oleic acid varieties), are characterized by plump kernels, low aflatoxin content, and high oil yield. They have been designated a nationally protected agricultural product with a geographical indication, and their annual export volume accounts for over a quarter of the national total. However, their higher price than ordinary peanuts and strong market demand have made them a prime target for profiteering by adulteration. Current methods of detecting adulteration in peanut production rely on manual screening or chemical analysis, which are inefficient and costly. For example, manual visual inspection is susceptible to subjective factors and can hardly distinguish between visually similar varieties. While laboratory testing is accurate, it is time-consuming and cannot meet the real-time monitoring requirements of large-scale distribution.
[0003] In recent years, target detection technology has been widely used in the field of agricultural product quality inspection due to its superior performance in vision-guided recognition. However, compared with other crops, peanut kernels are highly similar in color, morphology and other characteristics, and their particle size is small, which is easily affected by external environmental factors such as changes in lighting conditions. These problems significantly increase the difficulty of detecting peanut adulteration based on traditional visual methods. The manual inspection methods commonly used in the market at this stage are not only inefficient, but also easily restricted by human factors, making it difficult to achieve efficient and accurate detection requirements. Therefore, the research and development of an efficient, stable and suitable peanut adulteration detection method for complex environments has important practical significance and application value.
[0004] YOLOv10, a next-generation object detection model with superior performance in the YOLO family, boasts significant improvements in detection accuracy and inference speed, making it widely used in a variety of object detection tasks and demonstrating strong performance. However, direct application of the standard YOLOv10 model to peanut kernels presents limitations due to issues such as high similarity, small object size, unclear features, and sensitivity to lighting changes, making it unable to meet the practical needs of high-precision adulteration detection. Summary of the Invention
[0005] To address the above problems, the present invention optimizes the YOLOv10 model in a targeted manner to improve its adaptability and robustness in the task of adulteration detection in flower production areas.
[0006] The first aspect of the present invention provides a method for building a flower production site detection model based on deep learning, comprising the following steps: Step 1: Collect original image data of peanut kernels under different lighting scenes from different production areas, use production areas as labels, construct a dataset, and divide it into training and test sets; Step 2: Perform image enhancement on the dataset to obtain enhanced standard model input data; Step 3: Based on the basic YOLOv10 detection model, a YOLOv10-BAPNet model was constructed that can identify the characteristics of peanut kernels from different origins. A pinwheel convolutional layer (PConv) module was introduced into the backbone network to enhance the feature extraction capability of peanut kernels in the early stages. PConv has stronger directional perception and asymmetric receptive field, and can more effectively capture key features such as peanut surface texture, contour edges, and particle shape. A two-layer routing attention mechanism was introduced into the neck network. The upper layer uses a global self-attention mechanism to effectively capture the long-range connections and contextual information of peanut kernels in their spatial distribution. In particular, when processing multiple peanut kernels with densely arranged and similar shapes, the lower layer uses local self-attention to focus on the feature interactions of neighboring regions, especially the detailed information such as the edge contours and surface texture of the peanut targets, thereby improving the network's extraction accuracy of fine-grained features in the shallow semantic stage. In step 4, the loss function is improved using the fully adaptive threshold focal loss (ATFL) function, and the YOLOv10-BAPNet model in step 3 is trained using the dataset to complete the final detection model construction.
[0007] Preferably, the image enhancement operation in step 2 is specifically: S1: Read a peanut kernel image with appropriate brightness as the reference image and calculate the average value of the grayscale image pixel value , batch read the image to be processed, calculate the brightness of the current image, if the current input image The value is not equal to the baseline image value, then the image is enhanced in brightness and enters S2; if the input image The value is equal to the baseline image The value is directly input into the trained YOLOv10-BAPNet model; S2, using image brightness enhancement, aligns the image brightness to the reference image brightness through the brightness scale factor. >1, the image will become brighter. When <1, the image will become darker and enter S3; S3 uses image contrast enhancement, and uses the standard deviation of the image pixel grayscale value to measure the contrast. When the image pixel changes greatly, the contrast enhancement factor will become larger, and when the image pixel changes slightly, the contrast enhancement factor will become smaller. The contrast with the image is dynamically adjusted through the contrast enhancement factor; S4, input the corrected and enhanced standard image into the trained YOLOv10-BAPNet model.
[0008] Preferably, the average value of the grayscale image pixel values is calculated , is achieved by converting the image into a grayscale image and then taking the average of the grayscale values of all pixels. The pixel value of the grayscale image represents the brightness, which usually ranges from 0 to 255. The specific calculation method is:
[0009] in, refers to the average brightness; Refers to the total number of image pixels; Refers to pixels Gray value of Image brightness enhancement is to adjust the overall brightness of the image by scaling the pixel values. It is a method of adjusting the enhancement factor by brightness. The calculation method for scaling the brightness of all pixels is as follows: The brightness adjustment factor is calculated as:
[0010] Scale the brightness of all pixels by this factor:
[0011] in, Refers to the average brightness of the current image; Refers to the brightness of the target image; when the brightness factor >1, the image will become brighter; when the brightness factor When <1, the image will be darker; The image contrast enhancement is to enhance the visual clarity of the image by making the bright parts of the image brighter and the dark parts darker. The specific calculation method is: Contrast is measured by the standard deviation of the grayscale values of the image pixels:
[0012] The enhancement factor is defined as:
[0013] in, is the standard deviation of the grayscale values of the image pixels, is the enhancement factor.
[0014] Preferably, the YOLOv10-BAPNet model includes a backbone network, a neck network and a prediction end; The backbone network is used to extract initial features from the input image. After the input layer receives the image, a series of modules are used to extract features, including the C3k2_Pconv module, the selective channel downsampling module (SCDown), the spatial pyramid pooling fast module (SPPF), and the partial self-attention module (PSA). The C3k2_Pconv module inherits the C2f branch part of the features through multiple bottleneck modules (Bottleneck) and then fuses them with the unprocessed part of the features to realize the processing and extraction of input features. The selective channel downsampling module performs spatial downsampling and channel adjustment to reduce computational costs. The spatial pyramid pooling fast module enhances the detection ability of objects of different sizes through multi-scale pooling operations. Finally, the partial self-attention module improves feature representation by modeling global features by introducing multi-head self-attention. The neck network is used to process and fuse features extracted from the backbone network and then pass them to the prediction layer. The neck network adopts a path aggregation network structure (PAN) and contains several key modules, including an upsampling module, a selective channel downsampling module, a feature cascade module (Concat), a C3k2_Pconv module, and a two-layer routing attention mechanism. By performing multi-level feature fusion and extracting complex features, the algorithm's detection capability and feature representation are enhanced; The prediction end is used to convert the feature map processed by the neck network into actual detection output, including origin classification and target frame positioning.
[0015] Preferably, windmill-type convolution PConv is introduced into the backbone network, specifically: The C2f module in the original YOLOv10 backbone network is replaced with the C3k2_PConv module. PConv uses asymmetric padding in four directions and multi-shaped convolution kernels to specifically capture the spatial Gaussian distribution characteristics of small peanut kernel targets. Grouped convolution reduces the number of parameters and compresses computational costs. Parallel branching and concatenation operations are used to achieve complementary fusion of multi-directional and multi-scale features. Preferably, a two-layer routing attention mechanism is introduced into the neck network, specifically: The Bi-Level Routing Attention module is introduced during model construction to enhance the modeling capabilities of multi-scale semantic information during the feature fusion stage. This module first divides the input features into multiple spatial regions. At the region level, a lightweight scoring network scores the importance of each region, selecting candidate regions with high semantic value. Subsequently, fine-grained token-level self-attention operations are performed within the selected regions to refine features at key locations. The entire attention process uses a gating mechanism to dynamically control the computational paths between regions and tokens, effectively suppressing invalid feature interference and strengthening dependencies between information channels. Structurally, this module is embedded in the feature fusion path between FPN and PAN, interacting with feature maps at different scales to achieve coarse-to-fine, local-to-global hierarchical attention aggregation, thereby improving the model's discriminative and feature expression capabilities for peanut object detection.
[0016] Preferably, in step 4, the fully adaptive threshold focus loss ATFL function is used to improve the loss function, which is to adaptively adjust the loss weight according to the characteristics of each sample and the output of the model, and dynamically adjust the threshold according to the difference between the predicted result and the true label. At the same time, by introducing a focus mechanism, the focus on difficult-to-classify samples is enhanced, specifically: Adaptive threshold generation: Use sliding average EMA to track the distribution of positive sample prediction confidence and generate dynamic thresholds :
[0017] in, is the predicted probability of the positive sample, is the smoothing coefficient; Dynamic focus weight:
[0018] If the positive sample prediction probability , that is, difficult samples, or negative sample prediction probability , that is, false positive, is given a higher weight; among them, is the focus factor, which is used to adjust the steepness of the weight curve; ATFL loss function:
[0019] in, =1, that is, a positive sample, which is the probability of being predicted as a positive class; =0, that is, negative sample, is the probability of predicting the negative class, that is, 1 positive category; is the category balancing factor.
[0020] The second aspect of the present invention provides a method for detecting adulteration of flower production sites based on deep learning, wherein the YOLOv10-BAPNet model constructed by the construction method described in the first aspect is deployed on the back end of the detection system, and includes the following steps: Real-time capture of peanut kernel image data; The captured peanut kernel image data is input into the YOLOv10-BAPNet model for peanut adulteration detection; Output detection information, including the specific location information of the peanut kernels in the captured peanut image, the confidence score of each peanut kernel, and the origin information; The adulteration rate is analyzed according to the pre-set threshold value to obtain the final adulteration detection result of the flower production site.
[0021] Compared with the prior art, the present invention has the following beneficial effects: First, the present invention uses deep learning methods to achieve accurate identification of flower production site adulteration, solving the current problem of low accuracy in manual visual identification of flower production site adulteration. This provides strong support for improving the accuracy of flower production site adulteration identification and has high practical application value. Second, the present invention proposes an image enhancement technology that batch adjusts brightness and contrast based on an adaptive correction method for image brightness and contrast of a reference image to improve image quality and model detection accuracy.
[0022] Third, the present invention introduces pinwheel convolution (PConv) in the model backbone network to replace the traditional convolution operation to better capture the characteristics of peanuts and enhance the ability to extract the underlying peanut kernel features; Fourth, the present invention introduces a two-level routing attention mechanism Bi-Level RoutingAttention in the model neck network. This mechanism reduces the computational redundancy of global self-attention through a dynamic routing strategy while retaining the ability to model long-distance dependencies. Fifth, the present invention uses the fully adaptive threshold focal loss (ATFL) function to improve the loss function, which reduces the influence of easy-to-classify samples, increases the attention to difficult-to-classify samples, and improves the performance of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 This is a schematic diagram of the overall structure of the detection model of the present invention.
[0024] Figure 2 Schematic diagram of the data acquisition system of the present invention.
[0025] Figure 3 This is a detailed diagram of the overall structure of the YOLOv10-BAPNet model proposed in this invention.
[0026] Figure 4This is the structural diagram of the improved C3k2_PConv module proposed in the present invention.
[0027] Figure 5 This is a structural diagram of the Bi-Level Routing Attention module used in the present invention.
[0028] Figure 6 This is a workflow diagram of the image enhancement operation proposed in the present invention.
[0029] Figure 7 Schematic diagram of the detection results of an embodiment of the present invention. DETAILED DESCRIPTION
[0030] To better intelligently detect peanut adulteration, address the current technical difficulties in visually identifying peanut adulteration, save labor costs, and improve recognition efficiency and accuracy, this paper proposes a deep learning-based peanut adulteration detection model for a cloud-based peanut adulteration identification platform to enhance peanut kernel detection accuracy. The main invention involves a YOLOv10-BAPNet model construction method. Compared to the original YOLOv10 model, this new model significantly improves peanut adulteration detection accuracy without increasing model complexity. This provides strong support for the precise detection of peanut adulteration using the platform, and to some extent addresses the low accuracy of existing manual peanut adulteration identification methods.
[0031] The method for building a flower production adulteration detection model based on deep learning has the following general process: Step 1: Collect original peanut image data in a dark box using light to simulate different lighting scenes, create a dataset, and divide it into a training set and a test set according to a certain ratio; Step 2: Use annotation tools to annotate the images in the training set to obtain the annotated training set, and perform image enhancement operations on the collected data set; Step 3: Build a YOLOv10-BAPNet model that can identify the characteristics of peanut kernels from different origins, such as Figure 1As shown in the figure, the YOLOv10-BAPNet model addresses the challenges of peanut kernel origin identification, such as high feature similarity, small particle size, and environmental interference. Through dual-dimensional technological innovation, it achieves high-precision detection in complex scenarios. The pinwheel-type convolution (PConv) is introduced into the backbone network to better capture peanut features and enhance the underlying peanut kernel feature extraction capabilities. A dual-level routing attention mechanism, Bi-Level Routing Attention, is introduced into the neck network. The upper routing layer uses a global self-attention mechanism to capture global dependencies between images / sequences, while the lower routing layer uses local self-attention to focus on feature interactions in adjacent areas (such as object edges and textures), improving the accuracy of fine-grained feature extraction. Step 4: Use the fully adaptive threshold focal loss (ATFL) function to improve the loss function and train the YOLOv10-BAPNet model in step 3 with the dataset in step 2. Step 5: Use the image data in the test set to test the YOLOv10-BAPNet model to complete the final model construction.
[0032] This example further illustrates the specific process of building the flower production site adulteration detection model of the present invention through a specific experimental process.
[0033] 1. Obtaining raw data The original image data of peanuts is collected in a dark box using light to simulate different lighting scenes, such as Figure 2 As shown, peanut pictures from different origins, different angles, and different brightness conditions are used as raw data. The high-definition camera shoots at a distance of 30-50cm. The peanuts are photographed as realistically as possible, and a data set is created at a ratio of 8:2 for model training and testing.
[0034] 2. Image Data Preprocessing The collected peanut image dataset is used to annotate the peanut kernels in the image using the image annotation tool labelme. The annotation standard is single kernel annotation, and the annotated label file is saved in TXT format.
[0035] 3. Model Building Based on the YOLOv10 model structure, a YOLOv10-BAPNet model is built to accurately identify the characteristics of different varieties of peanut kernels. The YOLOv10-BAPNet model mainly consists of a backbone network, a neck network, and a prediction end. Figure 3As shown in the figure, the backbone network is mainly responsible for extracting initial features from the input image. After the input layer receives the image, a series of modules are used for feature extraction, including the C3k2_Pconv module, the selective channel downsampling module (SCDown), the spatial pyramid pooling fast module (SPPF) and the partial self-attention module (PSA). Specifically, the C3k2_Pconv module inherits some features from the C2f branch, which are combined with multiple bottleneck modules (Bottleneck) and then fused with the unprocessed features to realize the processing and extraction of input features. The selective channel downsampling module (SCDown) retains key information in the downsampling process by introducing a channel selection mechanism. The spatial pyramid pooling fast module (SPPF) uses a multi-level maximum pooling operation to fuse features of different scales. Degree-space information. Finally, the partial self-attention module (PSA) introduces a lightweight attention mechanism to improve the model's ability to model context. The C2f structure improves the efficiency of information flow through feature branch connections, while the Bottleneck module compresses and expands feature channels through residual connections, effectively reducing computational costs while enhancing feature expression. The neck network plays a vital role in connecting the backbone network and the head network, mainly by further processing and fusing the features extracted from the backbone network and then passing them to the prediction layer. The neck network adopts a path aggregation network (PAN) structure and contains several key modules, including an upsampling module, an SCDown module, a feature cascade (Concat) module, a C3k2_Pconv module, and a Bi-Level Routing Attention mechanism. These modules work together to achieve multi-level feature fusion and extract complex features, thereby enhancing the algorithm's detection capability and feature representation. The prediction end is mainly responsible for converting the feature maps processed by the neck network into actual detection outputs, especially for object classification and positioning.
[0036] (1) In the backbone network, although the original YOLOv10 has improved efficiency and performance in terms of convolution design through improvements such as depth-wise separable convolution and partial self-attention modules, it still has significant limitations. The fixed geometric structure of its conventional convolution leads to rigid sampling positions, making it impossible to adaptively adjust the receptive field to cope with target deformation, and the method of relying on manual stacking to expand the receptive field is not flexible enough. In order to improve the detection accuracy of the model, the present invention introduces the C3k2_Pconv module designed by windmill-type convolution PConv. C3k2_Pconv uses asymmetric padding and multi-shape convolution kernels in four directions to specifically capture the spatial Gaussian distribution characteristics of small targets, and reduces the number of parameters through grouped convolution, further compressing the computational cost to make the model more lightweight and efficient; at the same time, parallel branches and splicing operations are used to achieve complementary fusion of multi-directional and multi-scale features to improve the model's ability to focus on features; Furthermore, during the training process, the specific process is as follows Figure 4 As shown, the processing flow is as follows: This module is mainly used to efficiently process and reconstruct the input features, and its overall logic consists of five consecutive steps. First, the received input tensor has a four-dimensional structure, which includes the batch size, number of channels, height, and width. In the first stage, a convolution operation is used to reduce the number of input channels from the original value to a certain proportion of the target number of channels. The proportion is controlled by parameters, thereby obtaining an intermediate representation with twice the number of intermediate channels. Next, the intermediate tensor will be evenly divided into two parts along the channel dimension, one part will be used as a static reference for subsequent splicing, and the other part will enter the feature extraction process.
[0037] The feature extraction method varies depending on the module configuration parameter C3k. If set to True, the more complex C3k module is used to achieve stronger feature representation capabilities; if set to False, the more concise Bottleneck module is used. The feature extraction process stacks the input tensor multiple times, maintaining the output size constant for each step to simplify subsequent concatenation. After all features are extracted, the initially separated static portion is concatenated with the outputs of the multiple extraction modules along the channel dimension to form a new tensor that combines the initial features with the deep features.
[0038] Finally, to integrate the concatenated multi-channel features into the desired output form, the fused tensor is processed through another convolutional layer, regressing the number of channels to the set output channel number c2. The resulting tensor not only retains the spatial resolution of the original structure but also integrates multi-scale information from shallow and deep layers, offering enhanced expressive power. This serves as the module's final output for further processing in the subsequent network structure.
[0039] (2) The Bi-Level Routing Attention module is introduced during model construction to improve the modeling capability of multi-scale semantic information in the feature fusion stage. This module first divides the input features into multiple spatial regions, scores the importance of each region through a lightweight scoring network at the regional level, and selects candidate regions with higher semantic value. Subsequently, a fine-grained self-attention operation at the token level is further performed within the selected region to refine the features of key positions. The entire attention process uses a gating mechanism to dynamically control the calculation path between regions and tokens, effectively suppressing invalid feature interference and strengthening the dependency between information channels. Structurally, this module is embedded in the feature fusion path between FPN and PAN, interacting with feature maps of different scales to achieve coarse-to-fine, local-to-global hierarchical attention aggregation, thereby improving the model's discrimination and feature expression capabilities in peanut target detection, such as Figure 5Its core idea is to hierarchically screen important regions and dynamically allocate computing resources at both coarse-grained (region-level) and fine-grained (token-level) levels. Therefore, it enjoys advantages in both good performance and high computational efficiency, especially in dense prediction tasks. Furthermore, Bi-Level Routing Attention achieves efficient sparse attention through a hierarchical strategy of "regional screening and local focusing." This design excels in complex visual tasks such as object detection and semantic segmentation, balancing accuracy and efficiency, especially in scenarios with limited computing resources or high real-time requirements.
[0040] 4. Model Training The loss function is improved using the fully adaptive threshold focal loss (ATFL) function, and the preprocessed training set is used to train the constructed YOLOv10-BAPNet model.
[0041] Experimental platform: Pytorch deep learning framework, Windows 10 64-bit operating system, RTX 4060 Ti (24GB) GPU, 12th Gen Intel(R) Core(TM) i5-12490F 3.00 GHz CPU, 16GB of RAM. The number of training images per batch was set to 16, the number of epochs was set to 300, the learning rate was initialized to 0.001, and stochastic gradient descent (SGD) was used to optimize network parameters during training.
[0042] In this embodiment, the following processes are included: Initial weight parameters are obtained through pre-training on the dataset, laying the foundation for subsequent model training. Based on transfer learning, the pre-trained weights are loaded into the YOLOv10-BAPNet model as initialization parameters. This strategy not only effectively suppresses the loss value and large fluctuations of the loss function during training, but also significantly improves the convergence efficiency of the object detection network. The training set is loaded into the YOLOv10-BAPNet network model, and the fully adaptive threshold focus loss (ATFL) function is used to improve the loss function. The loss weight is adaptively adjusted according to the characteristics of each sample and the output of the model. The threshold can be dynamically adjusted according to the difference between the predicted results and the true labels, so that the model pays more attention to difficult-to-classify samples during training. At the same time, by introducing the focus mechanism, the influence of easy-to-classify samples is reduced, and the focus on difficult-to-classify samples is increased. This mechanism helps to improve the overall performance of the model. Specifically: Adaptive threshold generation: Use the sliding average (EMA) to track the distribution of positive sample prediction confidence and generate a dynamic threshold
[0043]
[0044] in, is the predicted probability of the positive sample, is the smoothing coefficient (e.g. 0.99); Dynamic focus weight:
[0045] If the positive sample prediction probability (difficult samples), or negative sample prediction probability (false positive), it is given a higher weight. is the focus factor (usually 0), used to adjust the steepness of the weight curve; ATFL loss function:
[0046] in, =1 (positive sample), it is the probability of predicting the positive class; = 0 (negative sample), is the probability of predicting the negative class (ie 1 positive category); is the category balance factor (usually positive samples >0.5, negative samples <0.5); 5. Model testing and application instructions The YOLOv10-BAPNet model sets an image enhancement module at the image input end, so that the model can perform image enhancement in real time when it is actually used. Figure 6 As shown, the specific process is: S1: Read a peanut kernel image with appropriate brightness as the reference image and calculate the average value of the grayscale image pixel value , batch read the image to be processed, calculate the brightness of the current image, if the current input image The value is not equal to the baseline image value, then the image is enhanced in brightness and enters S2; if the input image The value is equal to the baseline image The value is directly input into the trained YOLOv10-BAPNet model; S2, using image brightness enhancement, aligns the image brightness to the reference image brightness through the brightness scale factor. >1, the image will become brighter. When <1, the image will become darker and enter S3; S3 uses image contrast enhancement, and uses the standard deviation of the image pixel grayscale value to measure the contrast. When the image pixel changes greatly, the contrast enhancement factor will become larger, and when the image pixel changes slightly, the contrast enhancement factor will become smaller. The contrast with the image is dynamically adjusted through the contrast enhancement factor; S4, input the corrected and enhanced image into the trained YOLOv10-BAPNet model; Calculate the average pixel value of a grayscale image , by converting the image into a grayscale image and then taking the average of the grayscale values of all pixels. The pixel value of the grayscale image represents the brightness, which usually ranges from 0 (black) to 255 (white). The specific calculation method is:
[0047] in, refers to the average brightness; Refers to the total number of image pixels; Refers to pixels Gray value of Image brightness enhancement is to adjust the overall brightness of the image by scaling the pixel values. It is a method of adjusting the enhancement factor by brightness. The calculation method for scaling the brightness of all pixels is as follows: The brightness adjustment factor is calculated as:
[0048] Scale the brightness of all pixels by this factor:
[0049] in, Refers to the average brightness of the current image; Refers to the brightness of the target image; when the brightness factor >1, the image will become brighter; when the brightness factor When <1, the image will be darker; The image contrast enhancement is to enhance the visual clarity of the image by making the bright parts of the image brighter and the dark parts darker. The specific calculation method is: Contrast is measured by the standard deviation of the grayscale values of the image pixels:
[0050] The enhancement factor is defined as:
[0051] 6. Experimental results The peanut kernel dataset in this example was acquired using a darkroom camera, annotated using LabelMe, and then input into the model for recognition after image enhancement. Table 1 shows a model comparison table, showing that the improved network significantly outperforms the other original models in terms of P, R, and mAP. The improvements in P, R, and mAP demonstrate the improved YOLOv10-BAPNett network model proposed in this example, demonstrating the overall performance of the method presented in this example.
[0052] Table 1 Model comparison
[0053] As shown in Table 1, the results of model comparison show that the proposed YOLOv10-BAPNet module is effective, and the final detection effect is as follows Figure 7 shown.
[0054] The YOLOv10-BAPNet model built in this embodiment can be applied to specific application scenarios after completing this step of testing, and includes the following process: Real-time capture of peanut image data; Input the captured peanut image data into the constructed peanut production site detection model to detect peanut adulteration; Output detection information, including the specific location information of the peanuts in the captured peanut image, the confidence level of each peanut kernel, and the final estimated adulteration rate; The adulteration rate is analyzed according to the pre-set threshold value to obtain the final adulteration detection result of the flower production site.
[0055] The above description is merely a preferred embodiment of the present application and is not intended to limit the present application. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of the present application shall be included within the scope of protection of the present application.
[0056] Although the above describes the specific implementation methods of the present invention, it does not limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.
Claims
1. A method for building a flower production site detection model based on deep learning, characterized in that: The following processes are included: Step 1: Collect original image data of peanut kernels under different lighting scenes from different production areas, use production areas as labels, construct a dataset, and divide it into training and test sets; Step 2: Perform image enhancement on the dataset to obtain enhanced standard model input data; Step 3: Based on the basic YOLOv10 detection model, a YOLOv10-BAPNet model was constructed to identify the characteristics of peanut kernels from different origins. The windmill-type convolutional PConv module was introduced into the backbone network to enhance the feature extraction capability of peanut kernels at an early stage, capturing key features such as peanut surface texture, contour edges, and kernel shape. A two-layer routing attention mechanism is introduced in the neck network. The upper layer uses a global self-attention mechanism to capture the long-range connections and contextual information of the peanut particles in their spatial distribution, especially when dealing with scenes with multiple peanut particles densely arranged and similar in shape. The lower layer uses local self-attention to focus on the feature interactions of neighboring regions, especially the edge contours and surface texture details of the peanut objects. In step 4, the loss function is improved using the fully adaptive threshold focal loss (ATFL) function, and the YOLOv10-BAPNet model in step 3 is trained using the dataset to complete the final detection model construction.
2. A method for building a flower production site detection model based on deep learning as claimed in claim 1, characterized in that: The image enhancement operation in step 2 is specifically as follows: S1: Read a peanut kernel image with appropriate brightness as the reference image and calculate the average value of the grayscale image pixel value , batch read the image to be processed, calculate the brightness of the current image, if the current input image The value is not equal to the baseline image value, then the image is enhanced in brightness and enters S2; if the input image The value is equal to the baseline image The value is directly input into the trained YOLOv10-BAPNet model; S2, using image brightness enhancement, aligns the image brightness to the reference image brightness through the brightness scale factor. >1, the image will become brighter. When <1, the image will become darker and enter S3; S3 uses image contrast enhancement, and uses the standard deviation of the image pixel grayscale value to measure the contrast. When the image pixel changes greatly, the contrast enhancement factor will become larger, and when the image pixel changes slightly, the contrast enhancement factor will become smaller. The contrast with the image is dynamically adjusted through the contrast enhancement factor; S4, input the corrected and enhanced standard image into the trained YOLOv10-BAPNet model.
3. The method for building a flower production location detection model based on deep learning according to claim 3, characterized in that: The calculation of the average value of the grayscale image pixel value , is achieved by converting the image into a grayscale image and then taking the average of the grayscale values of all pixels. The pixel value of the grayscale image represents the brightness, which usually ranges from 0 to 255. The specific calculation method is: in, refers to the average brightness; Refers to the total number of image pixels; Refers to pixels Gray value of Image brightness enhancement is to adjust the overall brightness of the image by scaling the pixel values. It is a method of adjusting the enhancement factor by brightness. The calculation method for scaling the brightness of all pixels is as follows: The brightness adjustment factor is calculated as: Scale the brightness of all pixels by this factor: in, Refers to the average brightness of the current image; Refers to the brightness of the target image; when the brightness factor >1, the image will become brighter; when the brightness factor When <1, the image will be darker; The image contrast enhancement is to enhance the visual clarity of the image by making the bright parts of the image brighter and the dark parts darker. The specific calculation method is: Contrast is measured by the standard deviation of the grayscale values of the image pixels: The enhancement factor is defined as: in, is the standard deviation of the grayscale values of the image pixels, is the enhancement factor.
4. The method for building a flower production location detection model based on deep learning according to claim 1, characterized in that: The YOLOv10-BAPNet model includes a backbone network, a neck network, and a prediction end; The backbone network is used to extract initial features from the input image. After the input layer receives the image, a series of modules are used to extract features, including the C3k2_Pconv module, the selective channel downsampling SCDown module, the spatial pyramid pooling fast SPPF module, and the partial self-attention PSA module. The C3k2_Pconv module inherits the C2f branch part of the features through multiple bottleneck modules and then fuses them with the unprocessed part of the features to realize the processing and extraction of the input features. The SCDown module performs spatial downsampling and channel adjustment to reduce computational costs. The SPPF module performs multi-scale pooling operations by using convolutional layers and three MaxPooling 2D layers to enhance the detection ability of targets of different sizes. Finally, the PSA module improves feature representation by modeling global features by introducing multi-head self-attention MHSA. The neck network is used to process and fuse the features extracted from the backbone network and then pass them to the prediction layer. The neck network adopts a path aggregation network (PAN) structure and contains several key modules, including an upsampling module, an SCDown module, a feature cascade Concat module, a C3k2_Pconv module, and a two-layer routing attention mechanism. By performing multi-level feature fusion and extracting complex features, the algorithm's detection capability and feature representation are enhanced. The prediction end is used to convert the feature map processed by the neck network into actual detection output, including origin classification and target frame positioning.
5. The method for building a flower production site detection model based on deep learning according to claim 1, characterized in that: Introduce windmill convolution PConv into the backbone network, specifically: The C3k2_PConv module is used to replace the C2f module in the original YOLOv10 backbone network. The PConv uses asymmetric padding in four directions and multi-shape convolution kernels to specifically capture the spatial Gaussian distribution characteristics of small peanut kernel targets. Grouped convolution is used to reduce the number of parameters and compress computational costs. At the same time, parallel branching and splicing operations are used to achieve complementary fusion of multi-directional and multi-scale features.
6. The method for building a flower production site detection model based on deep learning according to claim 1, characterized in that: A two-layer routing attention mechanism is introduced in the neck network, specifically: The Bi-Level Routing Attention module is introduced during model construction to enhance the modeling capabilities of multi-scale semantic information during the feature fusion stage. This module first divides the input features into multiple spatial regions. At the region level, a lightweight scoring network scores the importance of each region, selecting candidate regions with high semantic value. Subsequently, fine-grained token-level self-attention operations are performed within the selected regions to refine features at key locations. The entire attention process uses a gating mechanism to dynamically control the computational paths between regions and tokens, effectively suppressing invalid feature interference and strengthening dependencies between information channels. Structurally, this module is embedded in the feature fusion path between FPN and PAN, interacting with feature maps at different scales to achieve coarse-to-fine, local-to-global hierarchical attention aggregation, thereby improving the model's discriminative and feature expression capabilities for peanut object detection.
7. The method for building a flower production site detection model based on deep learning according to claim 1, characterized in that: In step 4, the fully adaptive threshold focus loss (ATFL) function is used to improve the loss function. The loss weight is adaptively adjusted according to the characteristics of each sample and the output of the model. The threshold is dynamically adjusted according to the difference between the predicted result and the true label. At the same time, the focus mechanism is introduced to enhance the attention to difficult-to-classify samples. Specifically: Adaptive threshold generation: Use sliding average EMA to track the distribution of positive sample prediction confidence and generate dynamic thresholds : in, is the predicted probability of the positive sample, is the smoothing coefficient; Dynamic focus weight: If the positive sample prediction probability That is, difficult samples, or negative sample prediction probability That is, false positive, it is given a higher weight; among them, is the focus factor, which is used to adjust the steepness of the weight curve; ATFL loss function: in, =1, that is, a positive sample, which is the probability of being predicted as a positive class; =0, that is, negative sample, is the probability of predicting the negative class, that is, 1 positive category; is the category balancing factor.
8. A flower production location detection method based on deep learning, characterized in that: The YOLOv10-BAPNet model constructed by the construction method according to any one of claims 1 to 7 is deployed on the back end of the detection system, and includes the following processes: Real-time capture of peanut kernel image data; The captured peanut kernel image data is input into the YOLOv10-BAPNet model for peanut adulteration detection; Output detection information, including the specific location information of the peanut kernels in the captured peanut image, the confidence score of each peanut kernel, and the origin information; The adulteration rate is analyzed according to the pre-set threshold value to obtain the final adulteration detection result of the flower production site.
Citation Information
Cited By
Deep learning-based densely stacked green pellet particle size distribution visual measurement method
CN122089814A