Mildew detection method for peanut screening and related device
By combining the detection methods of images and volatile gas data, and using a pre-trained peanut mold feature extraction model and comprehensive mold index judgment, the accuracy and efficiency problems of peanut mold detection are solved, and accurate identification and efficient screening of peanuts that do not show obvious mold characteristics are achieved.
Patent Information
- Application Number
- CN202510872191.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-26
- Publication Date
- 2025-09-05
AI Technical Summary
Existing peanut mold detection technology has problems such as poor reliability of detection results, high computational complexity, and difficulty in identifying peanut kernels that do not show obvious moldy characteristics, resulting in reduced screening accuracy and slow calculation speed.
A detection method combining image data and volatile gas data was adopted. Mold features were extracted through a pre-trained peanut mold feature extraction model (the DynamicResBlock module was inserted into the ResNet model and a gating mechanism was adopted). The comprehensive mold index was calculated by combining the mold spot area and volatile gas data to determine the mold level.
It achieves accurate detection of peanut kernels that do not show obvious signs of mold, improves the accuracy and efficiency of detection, avoids misjudgment, reduces manpower and time costs, and the system has automation capabilities.
Smart Images

Figure CN120594773A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of peanut mildew detection, and in particular to a mildew detection method and related devices for peanut screening. Background Art
[0002] In the peanut kernel quality sorting process, mold detection is a critical step in ensuring food safety and product quality. Currently, peanut kernel sorting equipment primarily relies on convolutional neural networks (CNNs) to extract features from peanut kernel images to identify moldy kernels. However, as the depth of this algorithm increases, it is prone to vanishing gradients or overfitting problems, resulting in the model's inability to effectively extract peanut kernel features, particularly those of moldy kernels. This significantly reduces screening accuracy and prevents accurate identification of moldy kernels. Furthermore, the high computational complexity results in slow detection system speeds, making it difficult to meet the requirements of efficient sorting. Furthermore, traditional detection methods, which primarily rely on visual inspection, can only identify peanut kernels that have already become moldy. Peanut kernels that have not yet exhibited obvious signs of mold but are contaminated with aflatoxin are difficult to accurately identify through image detection. This results in some contaminated kernels being mixed in with normal peanut kernels, compromising product quality and increasing the burden of subsequent screening.
[0003] Therefore, it is necessary to design a mold detection method for peanut screening to solve the problems existing in the current technology. Summary of the Invention
[0004] In view of the problem of poor reliability of peanut mold detection results in the prior art, the present invention provides a mold detection method and related devices for peanut screening.
[0005] In order to achieve the above object, the present invention adopts the following technical solutions: The present invention provides a method for detecting mildew for peanut screening, comprising: Obtain image data and volatile gas data of peanuts to be tested; The image data is input into a pre-trained peanut mold feature extraction model to obtain peanut mold features, and an initial peanut mold label is determined based on the peanut mold features. The peanut mold feature extraction model is obtained by inserting a DynamicResBlock module after each convolutional layer in a ResNet model, and the DynamicResBlock module uses a gating mechanism to select whether to enable residual connections. According to the initial moldy peanut label and volatile gas data, the moldy comprehensive index is obtained, and the moldy grade of the peanuts to be tested is determined based on the moldy comprehensive index.
[0006] Optionally, a pre-training process of a peanut mold feature extraction model is also included, and the filter_dataset function is used to filter the training set and the validation set during the pre-training process of the peanut mold feature extraction model.
[0007] Optionally, the method further includes preprocessing the image data of the peanuts to be detected, wherein the preprocessing includes random rotation, random cropping and scaling, random horizontal flipping, random vertical flipping, color jittering, random grayscale conversion and random affine transformation.
[0008] Optionally, the peanut mold characteristics include the mold spot area, and the method for determining the peanut mold initial label according to the peanut mold characteristics is: When the peanut mold spot area is greater than zero, the initial label of peanut mold is severe mold; When the area of peanut mold spots is equal to zero, the initial label of peanut mold is suspected mold.
[0009] Optionally, the method for obtaining the comprehensive mildew index based on the peanut mildew initial label and volatile gas data is: When the initial label of peanut mold is suspected mold, the gas mold weight coefficient is determined based on the volatile gas data. :
[0010] According to the gas mildew weight coefficient, the comprehensive mildew index is obtained :
[0011] in, For the The distance between the volatile gas detection point and the peanuts to be detected; For the The concentration of volatile gases detected by each volatile gas detection point; is the standard deviation; is the total number of volatile gas detection points.
[0012] Optionally, the method for determining the mildew grade of the peanuts to be tested based on the comprehensive mildew index is: When the comprehensive mildew index is less than or equal to the first preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be mildew-free; When the comprehensive mildew index is greater than the first preset comprehensive mildew index and less than or equal to the comprehensive mildew threshold, the quality grade of the peanuts to be tested is determined to be slightly contaminated; When the comprehensive mildew index is greater than the comprehensive mildew threshold and less than or equal to the second preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be slightly mildewed; When the comprehensive mildew index is greater than the second preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be moderately mildewed; The first preset comprehensive mildew index is smaller than a comprehensive mildew threshold, and the comprehensive mildew threshold is smaller than a second preset comprehensive mildew index.
[0013] The present invention provides a mildew detection system for peanut screening, comprising an image acquisition device, a volatile gas acquisition device, a conveying device and a data processing unit; The conveying device is used to convey peanuts to be tested; The image acquisition device is arranged on both sides of the conveying device, and is used to obtain image data of the peanuts to be inspected and transmit it to the data processing unit; The volatile gas collection device is arranged on one side of the image collection device, and is used to obtain the volatile gas data of the peanuts to be tested and transmit it to the data processing unit; The processing unit includes a receiving module, a judging module and an evaluating module; The receiving module is used to receive image data and volatile gas data of peanuts to be detected; The judgment module is used to input image data into a pre-trained peanut mold feature extraction model to obtain peanut mold features, and determine the initial peanut mold label based on the peanut mold features; wherein the peanut mold feature extraction model is obtained by inserting a DynamicResBlock module after each convolutional layer in the ResNet model, and the DynamicResBlock module uses a gating mechanism to select whether to enable residual connections; The evaluation module is used to obtain a comprehensive mildew index based on the initial mildew label of the peanuts and the volatile gas data, and to determine the mildew grade of the peanuts to be tested.
[0014] Optionally, the volatile gas collection device is an electronic nose with a concentration and enrichment structure.
[0015] A terminal device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0016] A computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the above method when executed by a processor.
[0017] Compared with the prior art, the present invention has the following beneficial effects: The present invention provides a mold detection method for peanut screening. The method obtains image data and volatile gas data of peanuts to be detected; then, the image data is input into a pre-trained peanut mold feature extraction model to obtain peanut mold features, and an initial peanut mold label is determined based on the peanut mold features; finally, a comprehensive mold index is obtained based on the initial peanut mold label and the volatile gas data, and the mold grade of the peanuts to be detected is determined based on the comprehensive mold index. This method uses visual information to preliminarily judge the moldiness of the peanuts to be tested, and then calculates the comprehensive mold index based on volatile gas data. This method makes up for the defect that aflatoxin contamination cannot be accurately identified through visual information alone, and realizes the accurate detection of peanut kernels that have not yet shown obvious moldy characteristics but have been contaminated by aflatoxin. The method integrates data from two different modes of visual information and odor information, and comprehensively considers information on both the appearance characteristics and internal chemical changes of peanuts, making the determination of moldiness level more scientific and accurate. It realizes a comprehensive assessment of the moldiness of peanuts from multiple angles, avoiding the one-sidedness brought by a single data source, and greatly improving the accuracy and reliability of detection. This method can not only accurately eliminate moldy peanuts, but also identify peanuts that may be moldy in advance, prevent the spread of contamination, reduce the process of repeated screening, and further improve the efficiency of peanut mold screening. Among them, the peanut mold feature extraction model adopted is improved based on the ResNet model. The DynamicResBlock module is inserted after each convolutional layer, and a gating mechanism is used to select whether to enable the residual connection. This dynamic residual connection method can automatically adjust the network connection method according to the characteristics of the input data. When processing peanut images with different features, the model can flexibly choose whether to use the residual information, thereby more effectively extracting the key features of peanut mold, improving the accuracy and efficiency of feature extraction, and helping to more accurately determine the initial label of peanut mold. Compared with the traditional CNN network, it can avoid the problems of gradient vanishing and overfitting while maintaining a deeper network structure, thereby improving the accuracy and stability of image feature extraction.
[0018] The peanut screening mold detection method also includes a pre-training process of a peanut mold feature extraction model. During the pre-training process of the peanut mold feature extraction model, a filter_dataset function is used to filter the training set and the validation set, retaining only the data types of interest, thereby reducing the complexity of the data and the workload of training. At the same time, the peanut mold feature extraction model can be more focused on feature learning of specific categories, thereby improving the classification accuracy of the image data of the peanuts to be detected.
[0019] The pre-training process of the peanut mold feature extraction model also includes pre-processing of the original data set, which includes random rotation, random cropping and scaling, random horizontal flipping, random vertical flipping, color jittering, random grayscale and random affine transformation. These image enhancement methods not only expand the diversity of the data, enabling the peanut mold feature extraction model to learn a wider range of image features and improve the generalization ability, but also can effectively prevent overfitting of the peanut mold feature extraction model, thereby further improving the performance and reliability of the peanut mold feature extraction model.
[0020] Using the area of mold spots as a key feature to determine the initial mold label is a simple and direct method that can quickly perform preliminary classification of peanuts. This method based on a single feature and with clear judgment logic can greatly improve detection efficiency, reduce detection time, and reduce manpower and time costs. At the same time, the detection of mold spot area can be achieved through conventional image processing technology without the need for complex analysis processes and equipment. This makes the method of determining the initial mold label highly operational in practical applications, with a low risk of misjudgment and high initial screening efficiency.
[0021] In the process of obtaining the comprehensive mold index based on the initial peanut mold label and volatile gas data, the distance between the volatile gas detection point and the peanuts to be tested is introduced through the gas mold weight coefficient. In actual scenarios, volatile gases diffuse from moldy peanuts. The farther the distance, the less the gas concentration is affected by the peanut mold. Through this exponential decay weight calculation method, the data of the detection points closer to the peanuts contribute more to the comprehensive mold index, while the data of the detection points farther away contribute relatively less. This makes the acquisition of the comprehensive mold index more in line with the actual situation, reduces the error caused by gas diffusion, and greatly improves the accuracy of judging the mold degree of suspected moldy peanuts; the gas concentration detected by the volatile gas detection point is multiplied by the corresponding gas mold weight coefficient and the sum is calculated. The volatile gas concentration is one of the important indicators reflecting the mold condition of peanuts. The higher the concentration, the greater the possibility of peanut mold. By combining concentration and weight, the contribution of different detection points to the judgment of peanut mold can be comprehensively considered, and the degree of peanut mold can be quantified more accurately. The impact of abnormal data or accidental errors at a single detection point on the final mold comprehensive index can be effectively reduced, and data from multiple detection points can be supplemented and verified with each other, so that the mold comprehensive index can better reflect the actual mold situation of peanuts, thereby improving the stability and reliability of the test results.
[0022] The method for determining the mold grade of peanuts to be tested based on the mold comprehensive index is to set a first preset mold comprehensive index, a mold comprehensive threshold, and a second preset mold comprehensive index, thereby clarifying the dividing boundaries between different quality grades and dividing the quality grades of the peanuts to be tested into four grades: no mold, light contamination, light mold, and moderate mold. This makes the peanut mold grade classification more objective and accurate. Different grades correspond to different degrees of mold in peanuts, which can more accurately reflect the actual quality status of the peanuts, provide a more detailed basis for subsequent peanut processing, and help improve the accuracy of peanut screening.
[0023] The present invention also provides a mildew detection system for peanut screening, which integrates an image acquisition device, a volatile gas acquisition device, a conveying device and a data processing unit; each device has a clear division of labor and works in coordination, and the conveying device ensures that the peanuts to be detected can pass through the detection area in an orderly manner; the image acquisition device and the volatile gas acquisition device respectively obtain relevant information of the peanuts from different dimensions, providing a comprehensive and accurate data basis for subsequent mildew detection, thereby improving the reliability and accuracy of the detection; the data processing unit highly integrates a receiving module, a judgment module and an evaluation module; wherein the receiving module can quickly and accurately receive data from the image acquisition device and the volatile gas acquisition device, ensuring the integrity and Timeliness; the judgment module utilizes a peanut mold feature extraction model derived by inserting a DynamicResBlock module after each convolutional layer in the ResNet model. A gating mechanism is used to select whether to enable residual connections. This improvement enables the model to adaptively adjust the state of the residual connections based on the characteristics of the input data, thereby better extracting peanut mold features. The extracted peanut mold features are then used to determine the initial peanut mold label, providing an important reference for subsequent comprehensive judgment. The assessment module comprehensively considers the initial peanut mold label and volatile gas data to obtain a comprehensive mold index and determine the mold grade of the peanuts being tested, providing a more comprehensive and accurate reflection of the peanut mold condition. Through a rational hardware design and advanced data processing unit, this system automates peanut mold detection, reduces manual intervention, and significantly improves detection efficiency. In large-scale peanut screening processes, it can quickly and accurately complete the detection of large quantities of peanuts, reducing both labor and time costs and achieving significant economic benefits.
[0024] The volatile gas collection device is an electronic nose with a concentration and enrichment structure. The electronic nose itself has a certain gas detection capability. With the concentration and enrichment structure, it can effectively concentrate and enrich the low concentration of volatile gases in the air around the peanuts to be detected, thereby enhancing the signal strength of the volatile gases, increasing the sensitivity and accuracy of the electronic nose, and further improving the accuracy and reliability of peanut mold detection.
[0025] The present invention also provides a terminal device, including a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the processor executes the computer program, the steps of the above method are implemented; the processor can quickly execute processes such as the above-mentioned peanut mold feature extraction and mold comprehensive index acquisition to ensure the accuracy of peanut mold detection.
[0026] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the above method. The computer-readable storage medium (such as a solid-state drive (SSD) and a Flash memory) has high-speed reading capabilities and can quickly load the computer program into the processor for execution, thereby ensuring the timeliness and efficiency of the peanut mold detection process. It has the characteristics of flexibility and portability, high reliability and stability, support for large-scale data storage, easy integration and expansion, reduced development and maintenance costs, high security, energy saving and environmental protection, support for multiple application scenarios, and promotion of standardization and regularization. It provides strong support for the field of peanut mold detection and has broad application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 The figure is a flow chart of a method for detecting mildew in peanut screening according to the present invention.
[0028] Figure 2 This is a structural diagram of a mold detection system for peanut screening according to the present invention. DETAILED DESCRIPTION
[0029] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0030] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0031] The present invention will be further described in detail below with reference to specific embodiments, which are intended to explain the present invention rather than to limit it.
[0032] See also Figure 1 The present invention discloses a method for detecting mildew in peanut screening, comprising: S1: Obtain image data and volatile gas data of the peanuts to be tested, specifically: An image data set is established by acquiring all images and volatile gas data of the peanuts to be detected. The image data of the peanuts to be detected includes all image data of the peanuts to be detected; and the volatile gas data includes volatile gas concentration data of detection points at different distances from the peanuts to be detected.
[0033] S2: Input the image data into the pre-trained peanut mold feature extraction model to obtain peanut mold features, and determine the initial peanut mold label based on the peanut mold features, specifically: The image data is input into a pre-trained peanut mold feature extraction model, and a peanut mold vector of each image data is extracted as a peanut mold feature. Preferably, the peanut mold feature is the mold spot area, and the initial labels of peanut mold include severe mold and suspected mold; when the peanut mold spot area is greater than zero, the initial label of peanut mold is severe mold; when the peanut mold spot area is equal to zero, the initial label of peanut mold is suspected mold.
[0034] It's understandable that the precise calculation of mold spot area enables rapid identification of severely moldy peanuts, while also avoiding the omission of potentially aflatoxin-contaminated peanut kernels that would otherwise be missed by relying solely on visual inspection. Compared to traditional binary classification methods (which distinguish only between moldy and non-moldy), the addition of a "suspected moldy" classification helps improve the accuracy and reliability of screening. This enhances the intelligence of peanut mold detection and reduces the workload of subsequent manual screening.
[0035] The peanut mold feature extraction model is obtained by inserting a DynamicResBlock module after each convolutional layer in the ResNet model. The DynamicResBlock module uses a gating mechanism (gating weights are calculated based on global average pooling features) to select whether to enable residual connections. When the gating weight exceeds the threshold, the residual connection is executed; otherwise, the input is directly returned. This can adaptively adjust the model's calculation path based on data features, reduce unnecessary computational overhead, and improve the model's computational efficiency and performance. The establishment process is as follows: Establish the input matrix input peanut mold feature extraction model input layer, input matrix : ; Where H represents the height of the image data, W represents the width of the image data, C represents the number of channels, and R represents the image data; Use a 7×7 convolution kernel for preliminary feature extraction and a maximum pooling with a stride of 2;
[0036] in, represents the Depthwise convolution kernel, represents the convolution operation, Represents the bias term, f represents the ReLU activation function, f(a)=max(0,a), a represents the input of the ReLU activation function, Represents the image data after convolutional layer processing; Perform residual block settings;
[0037]
[0038] in, Represents the image data after processing by the convolution layer and the pooling layer, represents the first layer of convolution kernel, represents the second layer of convolution kernel, represents the first bias term, represents the second bias term, represents the features obtained after two layers of convolution, and y represents the residual learning result; Depthwise Separable Convolution:
[0039] Among them, Y represents the depth-wise separable convolution result, represents the depth convolution kernel, represents the point-by-point convolution kernel, Represents the input feature map of the current layer; Global average pooling:
[0040] in, Represents the number of pixels of the feature map of the depth-wise separable convolution result, Indicates the depth-wise separable convolution result. The value of the pixel, represents the output feature vector, Represents the index on the spatial dimension of the feature map, traversing all pixel positions; The peanut mold feature extraction model was built by training based on historical inspection images. In preprocessing the training data, in addition to the common Random Rotation, Random Resized Crop, and Random Horizontal Flip operations, Random Vertical Flip, Color Jitter, Random Grayscale, and Random Affine transformations were added. These operations expanded the diversity of the training data, enabling the model to learn a wider range of image features, thereby improving its generalization ability. Training on the original dataset and filtering the training and validation sets using the filter_dataset function to retain only the data categories of interest reduced data complexity and training workload, while enabling the model to focus on learning features for specific categories, thereby improving classification accuracy for these relevant data. The DynamicResBlock (dynamic sparse residual connection module) is introduced and added to each convolutional layer. A gating mechanism (gating weights calculated based on global average pooling features) dynamically selects whether to enable residual connections. When the gating weight exceeds a threshold, the residual connection is executed; otherwise, the input is directly returned. This adaptively adjusts the model's computational path based on data characteristics, reducing unnecessary computational overhead and improving the model's computational efficiency and performance. The present invention preferably modifies the ResNet152 model by adjusting the parameters of the conv1 layer and inserting a DynamicResBlock module after each convolutional layer. Simultaneously, the final fully connected layer is modified to adapt its output dimensions to the selected data. These structural adjustments make the model more suitable for the current dataset and task, enhancing the model's ability to extract and classify data features. StratifiedKFold is used for stratified K-fold cross-validation (k=5), ensuring that the sample ratios of each category in the training and validation sets for each fold remain consistent with those in the original dataset. This allows for more effective evaluation of the model's performance under different data distributions, improving the reliability and stability of model evaluation.An early stopping mechanism is introduced during the training process. By setting a patience threshold, when the accuracy of the validation set does not improve during the training cycle within the threshold, the training is terminated early to avoid model overfitting and save training time and resources. The AdamW optimizer is used, which combines the Adam optimizer and weight decay technology. It can effectively prevent overfitting while optimizing model parameters. It is paired with the CosineAnnealingLR learning rate scheduler, which can dynamically adjust the learning rate according to the number of training epochs. It maintains a large learning rate at the beginning of training to achieve rapid convergence, and gradually reduces the learning rate as training progresses, so that the model can adjust parameters more finely and improve training effects.
[0041] Mixed-precision training is implemented using autocast and GradScaler in the torch.cuda.amp library. Autocast automatically switches computations to half-precision mode during forward propagation, reducing memory usage and computation time. GradScaler dynamically adjusts gradient scaling during backward propagation to prevent gradient vanishing or exploding, effectively reducing training memory overhead and enabling the model to be trained in larger batches. This also improves training speed, shortening the training time per epoch from approximately 5 seconds initially to a stable 1.4-2.0 seconds. This improves training efficiency and facilitates rapid model convergence without sacrificing performance. For each data sample to be predicted, the best model from each fold (best_fold_0_epoch_50.pth to best_fold_4_epoch_50.pth) outputs a probability distribution vector for each class that the sample belongs to. Assume there are N models (N=5 in 5-fold cross-validation), and the probability distribution vector output by the i-th model for a certain sample is Pi=[Pi1,Pi2,Pi3] (here taking a three-category data classification task as an example), where Pij represents the probability that the i-th model believes the sample belongs to the j-th category. The average weighted mechanism calculates the weighted average of the predictions of all models to obtain the final probability distribution vector P=[P1,P2,P3]. The calculation formula is: Pj=(P1j+P2j+P3j+P4j+P5j) / 5. That is, for each category j, the probabilities predicted by all models for the sample belonging to that category are added together and averaged. This average weighted approach comprehensively considers the learning results of different models on the data in different folds of training, fully utilizing the advantages of multiple models to make the final prediction results more robust and accurate.
[0042] The results of model training are as follows: Initially, the model's accuracy improved rapidly. In single-fold training, the accuracy at Epoch 1, which was relatively low (e.g., 0.3786) (initial training without cross-validation), increased significantly after several rounds to validation set accuracy of approximately Epoch 10, generally exceeding 0.85, with some epochs even exceeding this. This demonstrates that the model is able to quickly learn the key features of the data, and that strategies such as data augmentation and structural optimization contribute to faster model convergence.
[0043] As training continued, the accuracy continued to rise and gradually stabilized at a high level. Across the cross-validation folds, the best validation accuracy reached 1.0000, with an average best validation accuracy of 0.9929. This demonstrates that the model achieves excellent performance under different data partitioning conditions, confirming the effectiveness of stratified K-fold cross-validation and other optimization strategies, and demonstrating the model's strong learning and generalization capabilities.
[0044] In the early stages of training, the training time for a single epoch is relatively long. For example, Epoch 1 may take around 5 seconds (initial training without cross-validation). However, as training progresses and the optimization strategy takes effect, the training time for subsequent epochs is significantly shortened, mostly stabilizing between 1.4 and 2.0 seconds. This is mainly due to the reduced data processing required by dataset filtering, the reduced computational complexity achieved by the dynamic sparse residual connection module, and the accelerated model convergence achieved by the optimizer and learning rate scheduler.
[0045] In the 5-fold cross-validation, while the training time for each fold varied, it remained within a reasonable range. For example, fold 1 took 52.96 seconds, and fold 2 took 41.35 seconds. Overall, the model was able to complete cross-validation training in a relatively short time while maintaining high accuracy, demonstrating that the algorithm improvements have achieved good results in improving training efficiency.
[0046] In the prediction stage, the best model saved in each fold is loaded to predict the validation set, and the prediction results of each model are fused using a weighted average method. The final inference accuracy is 0.9836.
[0047] Specifically, in the peanut mold feature extraction model application, the image data of the peanuts to be detected is first converted into an input matrix before entering the peanut mold feature extraction model. , whose dimensions are After the input layer, a 7×7 convolution kernel is used to perform preliminary feature extraction on the image data. Max pooling with a stride of 2 is then applied to reduce the data dimensionality while retaining key features. This operation reduces computational effort, improves model efficiency, and enhances feature representation. The core feature of ResNet is residual learning, which addresses the vanishing gradient and degradation issues caused by increased depth through cross-layer connections. Therefore, the ReLU activation function is used to enhance the model's nonlinear representation capabilities. To reduce computational effort and increase detection speed, depthwise separable convolution is introduced. Its computational process consists of two steps: depthwise convolution, which uses a separate convolution kernel to convolve each channel to extract local features within the channel; and pointwise convolution, which uses a 1×1 convolution kernel to combine all channels and integrate information from different channels. In the final stage of the network, global average pooling is used instead of the fully connected layer to further reduce computational complexity while enhancing the model's generalization.
[0048] It is understandable that the design of the peanut mold feature extraction model, while maintaining the advantages of deep networks, introduces optimizations such as residual learning, depthwise separable convolution, and global average pooling, improving the accuracy and computational efficiency of peanut image feature extraction. The introduction of residual blocks effectively avoids the vanishing gradient problem, enabling stable network training at greater depths. Depthwise separable convolution reduces the amount of computation, allowing the system to run faster while maintaining high accuracy, thereby improving the real-time performance of the detection system. Global average pooling avoids the redundant computation of traditional fully connected layers, further reducing model complexity and improving generalization capabilities.
[0049] Moldy areas appear as abnormal colors (such as dark brown or black) and have irregular textures. Using the aforementioned peanut mold feature extraction model, these areas are identified and the pixel ratio they occupy is calculated to accurately determine the mold spot area. If the peanut mold feature extraction model identifies a mold spot and its area is greater than zero, it indicates that the peanuts are clearly moldy and the initial label for the peanut mold condition is "severely moldy." If no obvious mold spots are detected (i.e., the mold spot area is zero), but aflatoxin contamination is still possible, a final determination is not made. Instead, the initial label for the peanut mold condition is marked as "suspected moldy" and the volatile gas data is used to further determine the peanut mold condition level.
[0050] S3: Obtain a comprehensive mold index based on the initial mold label and volatile gas data of the peanuts, and determine the mold grade of the peanuts to be tested based on the comprehensive mold index, specifically: When the initial label of peanut mold is suspected mold, it is necessary to obtain the mold comprehensive index based on the volatile gas data, and determine the mold level of the peanuts to be tested based on the mold comprehensive index; When the peanut to be tested passes through all volatile gas detection points and is within the detection range of the last volatile gas detection point, calculate the distance between each volatile gas detection point and the peanut to be tested.
[0051]
[0052] in, Indicates the The distance between the volatile gas detection point and the peanut to be detected, (ai, bi) represents the distance between the first volatile gas detection point and the peanut to be detected. The position coordinates of the volatile gas detection points, (a0, b0) represents the position coordinates of the peanut to be detected; Then determine the gas mildew weight coefficient :
[0053] According to the gas mildew weight coefficient, the comprehensive mildew index is obtained :
[0054] in, For the The distance between the volatile gas detection point and the peanuts to be detected; For the The concentration of volatile gases detected by each volatile gas detection point; is the standard deviation; is the total number of volatile gas detection points.
[0055] When determining the quality grade of peanuts to be tested, clear dividing boundaries need to be preset in advance based on actual testing requirements (including the number of grade divisions, grade division standards, etc.). This application further divides suspected mold into four grades. Therefore, a first preset mold comprehensive index, a mold comprehensive threshold, and a second preset mold comprehensive index are preset. The first preset mold comprehensive index is set to be less than the mold comprehensive threshold, and the mold comprehensive threshold is set to be less than the second preset mold comprehensive index. The obtained mold comprehensive index is compared with the first preset mold comprehensive index, the mold comprehensive threshold, and the second preset mold comprehensive index to determine the mold grade of the peanuts. Specifically, When the comprehensive mildew index is less than or equal to the first preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be mildew-free; When the comprehensive mildew index is greater than the first preset comprehensive mildew index and less than or equal to the comprehensive mildew threshold, the quality grade of the peanuts to be tested is determined to be slightly contaminated; When the comprehensive mildew index is greater than the comprehensive mildew threshold and less than or equal to the second preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be slightly mildewed; When the comprehensive mildew index is greater than the second preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be moderately mildewed.
[0056] As you can see, by setting multiple thresholds and categorizing peanut quality into four levels—no mold, light contamination, mild mold, and moderate mold—test results are more accurate and targeted. Compared to traditional binary classification (moldy vs. non-moldy) or ternary classification (no mold, light mold, severe mold), this method allows for more detailed differentiation of peanut contamination levels, facilitating the development of tailored treatment plans based on different quality levels.
[0057] Before comparing the comprehensive mold index with the first preset comprehensive mold index, the comprehensive mold threshold and the second preset comprehensive mold index, the comprehensive mold index needs to be adjusted based on the previous data accumulation; the previous data accumulation includes peanut kernel sample data, the peanut kernel sample data includes fruit diameter length, width, surface area, etc., as well as the comprehensive mold index and adjustment coefficient corresponding to different peanut kernel sample data. The above data are combined into corresponding sample data to obtain a historical matching data set.
[0058] When adjusting the comprehensive mold index, the size data of the peanuts to be tested is obtained using the collected image data of the peanuts to be tested, the size data is bound to the comprehensive mold index to establish matching data, the established matching data is compared with the historical matching data set, and the adjusted comprehensive mold index is determined based on the comparison results; Specifically, when there is data in the historical matching dataset whose similarity to the matching data is greater than the similarity threshold (the threshold is set according to actual needs), the mold comprehensive index is adjusted according to the historical adjustment coefficient of the historical matching data corresponding to the maximum similarity to obtain the adjusted mold comprehensive index; when the similarity between the historical matching dataset and the matching data is less than or equal to the similarity threshold, the adjusted mold comprehensive index is obtained based on the pre-established LSTM model. That is, the historical matching data corresponding to the maximum similarity is found, its adjustment coefficient is extracted, and the currently obtained mold comprehensive index is multiplied by the adjustment coefficient to obtain the adjusted mold comprehensive index. The LSTM model can collect volatile gas concentration sequences (H1...H n ) to conduct time series analysis and predict the concentration of volatile gases (H i ), recalculate the comprehensive mildew index based on the predicted volatile gas concentration to obtain an adjusted comprehensive mildew index, and store the current data and the obtained adjustment coefficient in the historical data; wherein the adjustment coefficient is calculated as follows:
[0059] in, is the adjusted comprehensive mildew index calculated by LSTM, It is the comprehensive mildew index before adjustment.
[0060] The LSTM model can be trained using historical peanut mold time series, and the current peanut mold comprehensive index can be predicted based on the known peanut mold index that changes over time. The mold comprehensive index within a preset time period can be predicted and used as the adjusted mold comprehensive index. The preset time period can be set according to actual detection needs.
[0061] By combining historical matching datasets with an LSTM deep learning model, we achieve intelligent adjustment of the comprehensive mold index, improving detection accuracy and adaptability. Compared to traditional fixed threshold methods or single-feature analysis, this method can be modified based on historical data and optimized through LSTM prediction when new features emerge. This ensures accurate determination of mold severity even for peanuts of varying sizes or unstable characteristics, reducing misjudgments and improving screening efficiency.
[0062] See also Figure 2 , the present invention also provides a mildew detection system for peanut screening, comprising an image acquisition device, a volatile gas acquisition device, a conveying device and a data processing unit; The conveying device is used to convey the peanuts to be inspected; preferably, the conveying device includes a conveyor belt, and the peanuts to be inspected are located on the conveyor belt; The image acquisition devices are provided in a plurality and are arranged on both sides of the conveying device, for acquiring image data of the peanuts to be inspected and transmitting the data to the data processing unit. The image acquisition devices are arranged on both sides of the conveying device. This layout can more comprehensively acquire image information of the peanuts, reduce image loss or incompleteness caused by factors such as occlusion, and thus more accurately extract the characteristics of peanut mold.
[0063] The volatile gas collection device is located on one side of the image collection device and is used to obtain volatile gas data from the peanuts to be tested and transmit it to the data processing unit. This design facilitates the simultaneous collection of volatile gas data from peanuts passing through the image collection area, ensuring the temporal and spatial correspondence between the image data and the volatile gas data, which is beneficial for subsequent comprehensive analysis. The processing unit includes a receiving module, a judging module and an evaluating module; The receiving module is used to receive image data and volatile gas data of peanuts to be detected; The judgment module is used to input image data into a pre-trained peanut mold feature extraction model to obtain peanut mold features, and determine the initial peanut mold label based on the peanut mold features; wherein the peanut mold feature extraction model is obtained by inserting a DynamicResBlock module after each convolutional layer in the ResNet model, and the DynamicResBlock module uses a gating mechanism to select whether to enable residual connections; The evaluation module is used to obtain a comprehensive mildew index based on the initial mildew label of the peanuts and the volatile gas data, and to determine the mildew grade of the peanuts to be tested.
[0064] Preferably, the volatile gas collection device is an electronic nose with a concentration and enrichment structure, and isolation plates are provided on both sides of each electronic nose. The electronic nose is used to collect the volatile gas concentration of the peanuts to be tested; preferably, since temperature promotes gas volatilization, temperature control can be set in the conveying device or image or volatile gas detection area to accelerate the release of volatile gases from aflatoxin-contaminated peanuts, ensuring that the electronic nose can detect aflatoxin contamination that is moldy or invisible to the naked eye.
[0065] The system integrates an image acquisition device, a volatile gas acquisition device, a conveying device and a data processing unit. Each device has a clear division of labor and works in coordination. The conveying device ensures that the peanuts to be tested can pass through the detection area in an orderly manner. The image acquisition device and the volatile gas acquisition device respectively obtain relevant information of peanuts from different dimensions, providing a comprehensive and accurate data basis for subsequent mold detection, thereby improving the reliability and accuracy of detection. The data processing unit highly integrates the receiving module, the judgment module and the evaluation module. Among them, the receiving module can quickly and accurately receive data from the image acquisition device and the volatile gas acquisition device, ensuring the integrity and timeliness of the data. The judgment module collects and analyzes the peanuts through the image acquisition device and the volatile gas acquisition device, ensuring the integrity and timeliness of the data. A peanut mold feature extraction model is constructed by inserting a DynamicResBlock module after each convolutional layer in the ResNet model. A gating mechanism is used to select whether to enable residual connections. This improvement enables the model to adaptively adjust the state of the residual connections based on the characteristics of the input data, thereby better extracting peanut mold features. The extracted peanut mold features are then used to determine the initial peanut mold label, providing an important reference for subsequent comprehensive assessment. The assessment module comprehensively considers the initial peanut mold label and volatile gas data to obtain a comprehensive mold index and determine the mold grade of the peanuts being tested, providing a more comprehensive and accurate reflection of the peanut mold condition. Through a rational hardware design and advanced data processing unit, this system automates peanut mold detection, reduces manual intervention, and significantly improves detection efficiency. In large-scale peanut screening processes, it can quickly and accurately complete large-scale peanut testing tasks, reducing labor and time costs and achieving significant economic benefits.
[0066] The present invention provides a terminal device comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of each of the aforementioned method embodiments are implemented. Alternatively, when the processor executes the computer program, the functions of each module / unit in each of the aforementioned apparatus embodiments are implemented.
[0067] The computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to accomplish the present invention.
[0068] The terminal device may be a computing device such as a desktop computer, a notebook computer, a PDA, a cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.
[0069] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0070] The memory may be used to store the computer programs and / or modules, and the processor implements various functions of the terminal device by running or executing the computer programs and / or modules stored in the memory and calling the data stored in the memory.
[0071] If the module / unit integrated in the terminal device is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention can implement all or part of the process steps in the above-mentioned method embodiments by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When executed by a processor, the computer program can implement the steps of each of the above-mentioned method embodiments. The computer program includes computer program code, which can be in source code form, object code form, executable file, or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal, and software distribution medium. It should be noted that the content of the computer-readable medium can be appropriately increased or decreased based on the requirements of legislation and patent practice in a jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media does not include electric carrier signals and telecommunication signals.
[0072] In summary, the present invention discloses a method and related device for detecting mold for peanut screening, which uses image visual detection technology to extract features from image data of peanuts to be detected and perform preliminary mold grade judgment. Then, for potential mold that cannot be identified by image visual detection, volatile gas analysis technology is used for further supplementary detection, and the distance weight between the volatile gas detection point and the peanut is used to calculate the comprehensive mold index to make up for the defect that simple visual detection cannot identify aflatoxin contamination. Determining the quality grade of peanuts based on the comprehensive mold index can not only accurately eliminate moldy peanuts, but also identify peanuts that may be moldy in advance, prevent the spread of pollution, reduce the need for repeated screening, and further improve the screening quality of peanut kernels. It can be seen that the present invention achieves high-precision and intelligent recognition of peanut mold by combining image detection and gas analysis technology, thereby improving the detection accuracy and efficiency of the peanut screening system.
[0073] The above description is merely a preferred embodiment of the present invention and is not intended to impose any limitation on the technical solution of the present invention. Those skilled in the art should understand that, without departing from the spirit and principles of the present invention, the technical solution can also be subjected to several simple modifications and replacements, and these modifications and replacements are also within the scope of protection covered by the claims.
Claims
1. A method for detecting mold in peanut screening, characterized in that: include: Obtain image data and volatile gas data of peanuts to be tested; The image data is input into a pre-trained peanut mold feature extraction model to obtain peanut mold features, and an initial peanut mold label is determined based on the peanut mold features. The peanut mold feature extraction model is obtained by inserting a DynamicResBlock module after each convolutional layer in a ResNet model, and the DynamicResBlock module uses a gating mechanism to select whether to enable residual connections. According to the initial moldy peanut label and volatile gas data, the moldy comprehensive index is obtained, and the moldy grade of the peanuts to be tested is determined based on the moldy comprehensive index.
2. The method for detecting mildew in peanut screening according to claim 1, wherein: It also includes a pre-training process of the peanut mold feature extraction model, in which the filter_dataset function is used to filter the training set and the validation set.
3. The method for detecting mildew in peanut screening according to claim 1, wherein: The method also includes preprocessing the image data of the peanuts to be detected, wherein the preprocessing includes random rotation, random cropping and scaling, random horizontal flipping, random vertical flipping, color jittering, random grayscale conversion, and random affine transformation.
4. The method for detecting mildew in peanut screening according to claim 1, wherein: The peanut mold characteristics include the mold spot area. The method for determining the peanut mold initial label according to the peanut mold characteristics is as follows: When the peanut mold spot area is greater than zero, the initial label of peanut mold is severe mold; When the area of peanut mold spots is equal to zero, the initial label of peanut mold is suspected mold.
5. The method for detecting mildew in peanut screening according to claim 4, wherein: The method for obtaining the comprehensive mildew index based on the peanut mildew initial label and volatile gas data is as follows: When the initial label of peanut mold is suspected mold, the gas mold weight coefficient is determined based on the volatile gas data. : According to the gas mildew weight coefficient, the comprehensive mildew index is obtained : in, For the The distance between the volatile gas detection point and the peanuts to be detected; For the The concentration of volatile gases detected by each volatile gas detection point; is the standard deviation; is the total number of volatile gas detection points.
6. The method for detecting mildew in peanut screening according to claim 1, wherein: The method for determining the mildew grade of peanuts to be tested based on the mildew comprehensive index is as follows: When the comprehensive mildew index is less than or equal to the first preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be mildew-free; When the comprehensive mildew index is greater than the first preset comprehensive mildew index and less than or equal to the comprehensive mildew threshold, the quality grade of the peanuts to be tested is determined to be slightly contaminated; When the comprehensive mildew index is greater than the comprehensive mildew threshold and less than or equal to the second preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be slightly mildewed; When the comprehensive mildew index is greater than the second preset comprehensive mildew index, the quality grade of the peanuts to be tested is determined to be moderately mildewed; The first preset comprehensive mildew index is smaller than a comprehensive mildew threshold, and the comprehensive mildew threshold is smaller than a second preset comprehensive mildew index.
7. A mildew detection system for peanut screening, characterized in that: It includes an image acquisition device, a volatile gas acquisition device, a conveying device and a data processing unit; The conveying device is used to convey peanuts to be tested; The image acquisition device is arranged on both sides of the conveying device, and is used to obtain image data of the peanuts to be inspected and transmit it to the data processing unit; The volatile gas collection device is arranged on one side of the image collection device, and is used to obtain the volatile gas data of the peanuts to be tested and transmit it to the data processing unit; The processing unit includes a receiving module, a judging module and an evaluating module; The receiving module is used to receive image data and volatile gas data of peanuts to be detected; The judgment module is used to input image data into a pre-trained peanut mold feature extraction model to obtain peanut mold features, and determine the initial peanut mold label based on the peanut mold features; wherein the peanut mold feature extraction model is obtained by inserting a DynamicResBlock module after each convolutional layer in the ResNet model, and the DynamicResBlock module uses a gating mechanism to select whether to enable residual connections; The evaluation module is used to obtain a comprehensive mildew index based on the initial mildew label of the peanuts and the volatile gas data, and to determine the mildew grade of the peanuts to be tested.
8. The mildew detection system for peanut screening according to claim 7, characterized in that: The volatile gas collection device is an electronic nose with a concentration and enrichment structure.
9. A terminal device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.