A method, device, apparatus, and medium for detecting aflatoxins in grains

CN122306727BActive Publication Date: 2026-11-03HEFEI UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610340311.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-03-19
Publication Date
2026-11-03
Estimated Expiration
2046-03-19

AI Technical Summary

Technical Problem

Existing detection technologies for aflatoxin in peanuts are slow and inaccurate, making it difficult to meet the needs of large-scale, on-site rapid screening.

Method used

A hybrid frog-jumping algorithm was used to extract feature waves. By analyzing the features present in the hyperspectral image, an improved frog-jumping algorithm detection network model was used to detect the aflatoxin content in grains. By combining hyperspectral imaging technology and a deep learning model, the detection speed and accuracy were improved.

Benefits of technology

It enables rapid and accurate detection of aflatoxin in peanuts, improving detection speed and accuracy, and is suitable for large-scale, on-site rapid screening.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122306727B_ABST
    Figure CN122306727B_ABST
Patent Text Reader

Abstract

The application relates to the field of detection analysis, and discloses a method, device, equipment and medium for detecting aflatoxin in grains. The method comprises the following steps: acquiring a hyperspectral image of the grains; obtaining continuous characteristic wavelengths by using an improved mixed frog leap algorithm according to the hyperspectral image, so as to obtain characteristics of the hyperspectral image; and training and verifying a detection network model according to the hyperspectral image after characteristic extraction, so as to detect the aflatoxin content of the grains by using the trained detection network model. The important characteristics of the image where the aflatoxin exists can be extracted by using the mixed frog leap algorithm, so that the speed and accuracy of detecting the aflatoxin in the grains are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of detection and analysis, and in particular to a method, apparatus, equipment and medium for detecting aflatoxin in grains. Background Technology

[0002] Aflatoxins are secondary metabolites mainly produced by Aspergillus flavus and Aspergillus parasiticus, and are among the most toxic and carcinogenic fungal toxins discovered to date. Peanuts and their grain products, such as peanuts, are highly susceptible to Aspergillus contamination during planting, harvesting, storage, and processing due to their high oil and protein content, making them a high-risk category for aflatoxin contamination. Aflatoxins (especially AFB1) have extremely strong destructive and carcinogenic effects on the livers of humans and animals, and countries worldwide have extremely strict limits on their use in food. Therefore, establishing efficient and accurate aflatoxin detection technology for peanuts and grains is of great significance for ensuring food safety, protecting public health, and promoting international trade.

[0003] Currently, methods for detecting aflatoxin include traditional physicochemical methods, rapid immunological methods, and emerging non-destructive testing technologies. Traditional physicochemical methods are slow, while rapid immunological methods and emerging non-destructive testing technologies suffer from insufficient accuracy and result stability. In summary, existing detection technologies face a core contradiction in addressing the practical needs of large-scale, on-site rapid screening for aflatoxin in peanuts and grains: a difficult balance between accuracy, speed, cost, and non-destructive testing. Summary of the Invention

[0004] This invention aims to at least solve one of the technical problems existing in the prior art. To this end, this invention proposes a method for detecting aflatoxin in grains, which can improve the speed and accuracy of aflatoxin detection by extracting important features of aflatoxin in images through a hybrid frog-jumping algorithm.

[0005] The present invention also proposes an apparatus, device, and medium having the above-described method for detecting aflatoxin in cereals.

[0006] A method for detecting aflatoxin in cereals according to a first aspect of the present invention includes: Acquire hyperspectral images of grains; Based on the hyperspectral image, continuous feature wavelengths are obtained through an improved hybrid frog-jumping algorithm, thereby obtaining the features of the hyperspectral image; Based on the hyperspectral images after feature extraction, a detection network model is trained and validated, and the aflatoxin content of grains is detected by the trained detection network model.

[0007] A method for detecting aflatoxin in grains according to an embodiment of the present invention has at least the following beneficial effects: The present invention addresses the characteristic that aflatoxin-related absorption peaks in grain spectra often exhibit a locally continuous distribution. It employs an improved hybrid frog-jumping algorithm to select characteristic wavelengths from hyperspectral images, favoring adjacent or continuously connected bands in the spectral curves and avoiding isolated or irrelevant wavelengths. This filters out effective information, improving the speed and accuracy of subsequent detection network models and facilitating subsequent model detection. The present invention can improve the speed and accuracy of aflatoxin detection in grains by extracting important features of aflatoxin in images using a hybrid frog-jumping algorithm.

[0008] According to some embodiments of the present invention, obtaining continuous characteristic wavelengths based on the hyperspectral image using an improved hybrid frog-leap algorithm includes: The bands corresponding to the hyperspectral image are divided into several bands; Based on the divided bands, several wavelength subset selection schemes are randomly generated and the fitness value of each wavelength subset selection scheme is calculated. Based on the fitness value of the selected scheme for each wavelength subset, the meme group is divided and internally updated; The updated meme groups are then globally shuffled, and the meme groups are further divided and updated internally until the optimal wavelength subset selection scheme, i.e., continuous characteristic wavelengths, is obtained by iterating until the conditions are met.

[0009] According to some embodiments of the present invention, the step of dividing and internally updating meme groups based on the fitness values ​​of the selection scheme for each wavelength subset includes: Based on the fitness value of each wavelength subset selection scheme, the wavelength subset selection schemes are sorted and the sorted wavelength subset selection schemes are cyclically distributed to obtain several memes. For each meme group, the best and worst individuals within the group are determined based on the fitness value; the worst individual is updated by completing the continuous wavelengths in the worst individual based on the generated step size vector.

[0010] According to some embodiments of the present invention, the step size vector is generated in the following ways: For any position in the step vector, if the left or right neighbor of the best individual in the meme group is selected, then that position is selected; otherwise, that position is selected randomly.

[0011] According to some embodiments of the present invention, calculating the fitness value of each wavelength subset selection scheme includes: The hyperspectral images corresponding to the wavelength subset selection schemes are input into the vector regression model to obtain the initial predicted aflatoxin content. The root mean square error is obtained by comparing the initial predicted aflatoxin content with the aflatoxin content obtained by accurate detection of the hyperspectral image. Information redundancy is determined by the Pearson correlation coefficient of the emissivity among the selected bands in the wavelength subset selection scheme. The fitness value of the wavelength subset selection scheme is obtained based on the root mean square error and the information redundancy.

[0012] According to some embodiments of the present invention, the step of globally shuffling several internally updated meme sets to obtain the optimal meme set includes: Several meme groups are split and sorted according to the fitness value of each wavelength subset selection scheme. The top E wavelength subset selection schemes with the highest fitness values ​​are then selected. Here, E is a preset positive integer. The E wavelength subset selection schemes are cyclically allocated and sorted to obtain several meme groups. The internal updates and meme group divisions are continued until the fitness values ​​of the wavelength subset selection schemes do not exceed a preset threshold. The wavelength subset selection scheme with the smallest difference between the number of bands and the preset target number of bands is taken as the optimal wavelength subset selection scheme.

[0013] According to some embodiments of the present invention, it further includes: After updating the worst individual, a wavelength subset selection scheme is selected with a preset mutation probability. If the number of selected bands in the wavelength subset selection scheme is greater than the preset target number of bands, the bands that are more than the target number of bands are randomly deselected; otherwise, the bands that are less than the target number of bands are randomly selected.

[0014] An apparatus for detecting aflatoxin in grains according to a second aspect of the present invention, for performing a method for detecting aflatoxin in grains according to any one of the first aspects, comprising: Hyperspectral camera and controller; The hyperspectral camera is used to acquire hyperspectral images of the grain; and to send the hyperspectral images to the controller. The controller is used to obtain continuous feature wavelengths from the hyperspectral image using an improved hybrid frog-jumping algorithm, thereby obtaining the features of the hyperspectral image; and to train and validate a detection network model based on the feature-extracted hyperspectral image, thereby detecting the aflatoxin content of grains using the trained detection network model.

[0015] An electronic device according to a third aspect of the present invention includes: Memory, used to store programs; A processor for executing a program stored in the memory, wherein when the processor executes the program stored in the memory, the processor is configured to perform the method as described in any one of the first aspects.

[0016] According to a fourth aspect of the present invention, a storage medium stores computer-executable instructions for performing the method as described in any one of the first aspects.

[0017] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the description, claims, and drawings. Attached Figure Description

[0018] The accompanying drawings are provided to further understand the technical solutions of the present invention and constitute a part of the specification. They are used together with the embodiments of the present invention to explain the technical solutions of the present invention, and do not constitute a limitation on the technical solutions of the present invention.

[0019] Figure 1 This is a flowchart of a method for detecting aflatoxin in grains according to an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating the division of sample data in a method for detecting aflatoxin in cereals according to another embodiment of the present invention; Figure 3 This is a graph showing the material changes in a grain sample during a method for detecting aflatoxin in grains, provided in another embodiment of the present invention. Figure 4 This is a microstructure diagram of a grain sample in a method for detecting aflatoxin in grains provided in another embodiment of the present invention; Figure 5 This is a spectral image of a grain sample in a method for detecting aflatoxin in grains provided in another embodiment of the present invention; Figure 6 This is a regression prediction scatter plot on an independent test set in a method for detecting aflatoxin in cereals provided in another embodiment of the present invention. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0021] It should be understood that in the description of the embodiments of the present invention, "multiple" (or "amounts") means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. If "first," "second," etc., are used in the description, they are only for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.

[0022] like Figure 1 As shown, this embodiment of the invention provides a method for detecting aflatoxin in cereals, comprising: Step S100: Obtain a hyperspectral image of the grain; Step S200: Based on the hyperspectral image, obtain continuous feature wavelengths through an improved hybrid frog-jumping algorithm to obtain the features of the hyperspectral image; Step S300: Based on the hyperspectral image after feature extraction, train and validate the detection network model, and use the trained detection network model to detect the aflatoxin content of grains.

[0023] This invention addresses the characteristic that aflatoxin-related absorption peaks in grain spectra often exhibit a locally continuous distribution. It employs an improved hybrid frog-jumping algorithm to select characteristic wavelengths from hyperspectral images, favoring adjacent or continuously occurring bands in the spectral curves while avoiding isolated or irrelevant wavelengths. This process filters out effective information, improving the speed and accuracy of subsequent detection network models and facilitating model detection. This invention can improve the speed and accuracy of aflatoxin detection in grains by extracting key features of aflatoxin in images using a hybrid frog-jumping algorithm.

[0024] It is easy to understand that step S200 is actually to extract features from the hyperspectral image, filter out irrelevant information, and select the image regions where aflatoxin exists.

[0025] In one embodiment, in step S200, continuous characteristic wavelengths are obtained based on the hyperspectral image using an improved hybrid frog-leap algorithm, including: The bands corresponding to the hyperspectral image are divided into several bands; Based on the divided bands, several wavelength subset selection schemes are randomly generated and the fitness value of each wavelength subset selection scheme is calculated. Based on the fitness value of the selected scheme for each wavelength subset, the meme group is divided and internally updated; The updated meme groups are then globally shuffled, and the meme groups are further divided and updated internally until the optimal wavelength subset selection scheme, i.e., continuous characteristic wavelengths, is obtained by iterating until the conditions are met.

[0026] It should be noted that the wavelength subset selection scheme is actually a binary vector, where a value of 1 in the i-th bit indicates that the band is selected; each wavelength subset selection scheme is a wavelength selection scheme.

[0027] In one embodiment, the process of dividing and internally updating meme groups based on the fitness values ​​of the selection schemes for each wavelength subset includes: Based on the fitness value of each wavelength subset selection scheme, the wavelength subset selection schemes are sorted and the sorted wavelength subset selection schemes are cyclically distributed to obtain several memes. For each meme group, the best and worst individuals within the group are determined based on the fitness value; the worst individual is updated by completing the continuous wavelengths in the worst individual based on the generated step size vector.

[0028] In one embodiment, the step size vector is generated in the following way: For any position in the step vector, if the left or right neighbor of the best individual in the meme group is selected, then that position is selected; otherwise, that position is selected randomly.

[0029] It is easy to understand that the step size vector and the individual wavelength subset selection scheme are both binary vectors with the same length. When the i-th band is in the neighborhood of the selected band, the bit is set to 1 with a high probability, forcing the band to move closer to the continuous features of the best individual when updating. For example, if bands 5, 6, and 7 in the best individual are selected consecutively (corresponding to an absorption peak), then the right neighbor (6) of band 5 is 1 and the left neighbor (6) of band 7 is 1, which will trigger Ri=1, so that these bands in the worst individual are also selected, and finally forming a continuous interval. For isolated bands (the neighborhood has no selected bands and does not belong to any continuous feature interval), they are no longer given high weight, but are randomly decided whether to update.

[0030] In one embodiment, calculating the fitness value of each wavelength subset selection scheme includes: The hyperspectral images corresponding to the wavelength subset selection schemes are input into the vector regression model to obtain the initial predicted aflatoxin content. The root mean square error is obtained by comparing the initial predicted aflatoxin content with the aflatoxin content obtained by accurate detection of the hyperspectral image. Information redundancy is determined by the Pearson correlation coefficient of the emissivity among the selected bands in the wavelength subset selection scheme. The fitness value of the wavelength subset selection scheme is obtained based on the root mean square error and information redundancy.

[0031] It should be noted that the training method of the vector regression model includes: acquiring hyperspectral images of the grain in advance and detecting the aflatoxin content of the grain with acquired hyperspectral images using traditional physicochemical testing methods; inputting the hyperspectral images into the vector regression model, the vector regression model outputs a rough prediction of the aflatoxin content, and comparing the output aflatoxin content with the aflatoxin content obtained through traditional physicochemical testing methods to adjust the parameters of the vector regression model.

[0032] It is easy to understand that the process of obtaining aflatoxin content through vector regression model is actually an existing prediction of aflatoxin content through network model, and the result is not accurate.

[0033] In one embodiment, a global shuffle is performed on several internally updated meme sets to obtain the optimal meme set, including: Several meme groups are split and sorted according to the fitness value of each wavelength subset selection scheme. The top E wavelength subset selection schemes with the highest fitness values ​​are then selected. Here, E is a preset positive integer. The E wavelength subset selection schemes are cyclically allocated and sorted to obtain several meme groups. The internal updates and meme group divisions are continued until the fitness values ​​of the wavelength subset selection schemes do not exceed a preset threshold. The wavelength subset selection scheme that has a number of bands closer to the preset target number of bands is taken as the optimal wavelength subset selection scheme.

[0034] It is easy to understand that cyclical allocation means that, assuming there are 2 meme groups, the highest fitness value is assigned to the 1st meme group, the second highest to the 2nd meme group, the third highest to the 2nd meme group, the fourth highest to the 1st meme group, and so on.

[0035] In one embodiment, it further includes: After updating the worst individual, a wavelength subset selection scheme is selected with a preset mutation probability. If the number of selected bands in the wavelength subset selection scheme is greater than the preset target number of bands, the bands that are more than the target number of bands are randomly set to 0; otherwise, the bands that are less than the target number of bands are randomly set to 1.

[0036] In one embodiment, the specific process of selecting the spectral characteristic wavelength, i.e., step S200, is as follows: Hyperspectral analysis was used to acquire the reflectance spectra of grain samples in the range of 900-1700 nm, and samples were taken at fixed intervals, ultimately yielding D=224 consecutive band points. These 224 bands constitute the original, high-dimensional wavelength subset selection scheme; Problem Coding and Parameter Setting: Each wavelength subset selection scheme is encoded as a binary vector X=[x1,x2,...,x] of length D=224. 224 ], where: x i =1 indicates that the i-th band is selected, x i =0 indicates that the i-th band was not selected; set the initial key parameters, including: frog swarm size P=50; number of memes M=5; number of local iterations within each meme group J. local =20; Total number of global shuffling iterations G max =100; Target feature subset size guide value L target =30; ② Generate the initial frog swarm: Randomly generate P binary vectors as the initial frog swarm; for each initial individual (i.e., a wavelength subset selection scheme) Xk Calculate its fitness value F(X) k ): F(X) = α⋅Perf SVR (X)−β⋅Redundancy(X); where, Perf SVR (X): The prediction performance index calculated on the independent validation set by training a support vector regression (SVR) model using the band data selected by the individual; Redundancy(X): The absolute value of the average correlation coefficient between the selected bands is used to measure the information redundancy of the selected features; α, β: Balance weights, set α=0.7, β=0.3, to prioritize prediction performance and suppress redundancy. ③ Meme group partitioning and local depth search: Sort all individuals according to their fitness values ​​from high to low. A "cyclic allocation" strategy is used to sequentially assign the sorted individuals to M meme groups, ensuring a uniform distribution of individual quality within each group. 1) Improved local update strategy for spectral band selection: Determine the optimal individual within each group. and the worst individual 2) Update the worst-performing individual X within the population. w The generation rule for the jump step size vector R is as follows: in, This represents the (i-1)th position of the optimal individual. This represents the (i+1)th position (right position) of the optimal individual. The jump probability is preset; for i=1, after determining the step size vector R, the jump step size D is calculated according to the following formula and the worst individual is updated; Step size calculation: Location update: This mechanism is based on the characteristic that the spectrum of aflatoxins from cereals often exhibits localized continuous absorption peaks, thus avoiding the selection of isolated, irrelevant bands. 3) Updates and Variations: X w =Mutation(X) w +R⊙(X b -X w Mutation(Y) is a random perturbation operation on the binary vector Y, calculated as: Mutation(Y) = BitFlip(SizeAdjust(Y)); SizeAdjust(Y) adjusts the size based on the number of currently selected bands k. Y The difference from the target number Ltarget=30 is used for bias adjustment: BitFlip(Y) bit flip with probability p. m (Typically 0.01-0.05) Flip each bit; X is the least fit individual in the current population. w ′ represents the newly updated and mutated individual; The individual with the best fitness in the current population; Mutation operation: with probability p m =0.05 performs a bit flip, and at the same time introduces "target size guidance" in the mutation: if the number of selected bands is >30, it tends to delete redundant bands (randomly set to 0); if it is <30, it tends to add candidate key bands (randomly set to 1). ④ Global Information Washing and Elite Strategy: After all meme groups have completed their local searches, all individuals are merged again, reordered by fitness, and divided into new meme groups. Throughout the evolutionary process, the top E individuals with the highest fitness are always retained to directly enter the next generation, avoiding the loss of superior genes. When performing global sorting on all individuals, if the fitness values ​​of two individuals do not differ by more than a threshold δ (e.g., δ=0.01), the individual whose selected band number is closer to the target value of 30 is selected first. In this invention, an "individual" represents a complete wavelength subset selection scheme; each individual is a binary vector of length 224, with each bit corresponding to a spectral band. The "band number" of an individual is equal to the number of "1"s in the vector, and this number is variable. Each step in the algorithm process evaluates, compares, and updates different individuals (i.e., different wavelength subset schemes) to guide the population to converge toward the target size.

[0037] ⑤ Iteration Termination and Optimal Subset Output: Repeat steps ②, ③, and ④ until any of the following termination conditions are met: the preset maximum number of global iterations G is reached. max The improvement in the global optimal fitness value over K consecutive generations is less than the threshold ϵ. The number of bands selected by the optimal individual remains stable at around 30, and the performance is stable. When the algorithm terminates, it outputs the individual X with the highest fitness value throughout the generations. best As the final filtering result, decoding this binary vector yields the specific location indices of the 30 characteristic wavelengths.

[0038] To address the one-dimensional sequence characteristics of hyperspectral data, this invention specifically designs a deep learning model architecture with adaptive feature focusing and high interpretability, including: It receives a standardized and preprocessed one-dimensional spectral sequence, with the input dimension supporting either the complete full band or a subset of bands optimized by a feature selection algorithm; During the model training phase, random noise conforming to a Gaussian distribution N(0,0.02²) is dynamically injected into the input spectrum as a built-in data augmentation module to improve the model's robustness to small spectral fluctuations in actual detection. Dual-path multi-scale feature extraction module: Employs a parallel structure to capture spectral features under different receptive fields, including: Path 1 (Local Refinement Path): Employs a two-layer one-dimensional convolutional structure. The first layer uses 16 kernels of size 3, and the second layer uses 32 kernels of size 3. Each layer is followed by batch normalization and a ReLU activation function, focusing on extracting local spectral details and features related to adjacent bands. Path 2 (Global Context Path): Employs a one-layer one-dimensional dilated convolutional layer with a dilation rate of 2, using 16 kernels of size 3, followed by batch normalization and a ReLU activation function. This path aims to expand the receptive field through sparse sampling, capturing global trends and long-range dependencies in the spectrum without increasing parameters or reducing resolution. Attention-guided and feature fusion module: Responsible for adaptive optimization and integration of extracted features, specifically including: Spectral band attention submodule: For input spectral or shallow features, a lightweight fully connected network generates an attention weight vector equal to the number of bands, adaptively enhancing key response bands and suppressing irrelevant and noisy bands; Channel attention submodule: For feature maps extracted from dual paths, a squeeze-excitation network module is used to recalibrate them by learning the global importance of each feature channel; Adaptive feature fusion layer: The attention-weighted dual-path features are concatenated along the channel dimension and adaptively fused and reduced in dimensionality through a 1x1 convolutional layer, generating 32 fused feature maps; Regularization and Output Module: Random Deactivation Layer: A Dropout layer is connected after feature fusion, with a dropout rate set to 0.3 to prevent overfitting. Global Average Pooling Layer: Global average pooling is performed on each of the 32 feature maps to obtain a 32-dimensional global feature vector, replacing the parameter-dense fully connected layer; Output layer: The output layer is a linear fully connected layer that outputs continuous predicted concentration values ​​of AFB1.

[0039] This invention also provides an apparatus for detecting aflatoxin in grains, comprising: Hyperspectral camera and controller; A hyperspectral camera is used to acquire hyperspectral images of the grain; the hyperspectral images are then sent to the controller. The controller is used to obtain continuous feature wavelengths from hyperspectral images using an improved hybrid frog-jumping algorithm, thereby obtaining the features of the hyperspectral image; based on the hyperspectral image after feature extraction, the controller trains and validates a detection network model, thereby detecting the aflatoxin content of grains using the trained detection network model.

[0040] It should be noted that the apparatus provided in this embodiment is used to implement any of the above-mentioned methods for detecting aflatoxin in cereals.

[0041] It should also be noted that the complete implementation process of the device is as follows: 1. Sample preparation and contamination induction 2. Standard determination of reference values: In order to provide an accurate learning target (i.e., true value) for the subsequent non-destructive testing model, each sample needs to undergo destructive standard physicochemical testing.

[0042] 3. Hyperspectral image data acquisition and correction A hyperspectral imaging system was used to acquire non-destructive spectral information of peanut samples, including: an imaging unit equipped with a short-wave infrared (SWIR) hyperspectral camera (spectral range 900-1700nm, 224 bands, resolution 8nm), a sample transfer stage, two 300W halogen lamp light sources, and a control computer.

[0043] The acquisition steps are as follows: (1) After the system has warmed up and stabilized, cover the camera lens with a completely opaque lens cap and acquire a dark reference image (R). D (2) Remove the lens cap, place a high reflectivity (>99%) standard white calibration plate on the transfer table, and acquire a bright reference image (R). W (3) The peanut sample to be tested is laid flat on the conveyor stage, and line scanning imaging is performed to obtain the original hyperspectral image cube data (R1). (4) The original spectral reflectance intensity of each pixel is corrected using the following formula to eliminate the influence of light source inhomogeneity and sensor dark current: Where R is the corrected relative reflectance.

[0044] (5) From the corrected hyperspectral image, manually or automatically select the region of interest (ROI) of each peanut, and calculate the average spectral curve of all pixels in the region as the final feature spectral data of the sample.

[0045] 4. Spectral Data Preprocessing and Characteristic Wavelength Optimization: The acquired raw spectral data often contains noise, baseline drift, and scattering effects. To improve model robustness, the following four methods were used for preprocessing: ① Standard Normal Variable Transform (SNV) ② Multivariate Scattering Correction (MSC) ③ Savitzky-Golay Smoothing Filter (SG) ④ Median Filtering (MF). After preprocessing, the signal-to-noise ratio of the spectral curves was improved, and physical interference was effectively suppressed.

[0046] 5. Implement any of the above methods for detecting aflatoxin in grains, train and validate the detection network model; acquire hyperspectral images of the grain to be detected using a hyperspectral camera and input them into the detection network model, and output the aflatoxin content of the grain to be detected.

[0047] In one embodiment, to verify the effectiveness of the device described in this embodiment, a systematic experimental verification and result analysis were conducted on the non-destructive testing scheme for peanut aflatoxin B1 based on hyperspectral imaging and deep learning models.

[0048] First, the Kennard-Stone algorithm was used to divide all sample data into training, validation, and independent test sets in a 7:1.5:1.5 ratio. Principal component analysis was then used to visualize the partitioning results (e.g., ...). Figure 2 As shown in Figure A), the training set samples fully cover the distribution range of the validation and test sets in the feature space, and the spatial distribution pattern of the data points in each subset is consistent, with no isolated clusters. This indicates that the dataset partitioning is reasonable and representative, laying a reliable foundation for model training and generalization ability evaluation. Statistical analysis of the AFB1 content determined by high-performance liquid chromatography for each subset sample shows (e.g.) Figure 2 As shown in B), the toxin concentration range of the training set (3.11-180.01 μg / kg) completely covers the range of the validation set (3.25-179.34 μg / kg) and the test set (3.65-179.81 μg / kg), further confirming the reliability of the dataset partitioning and ensuring that the model can effectively learn and predict across the entire concentration range.

[0049] During storage, key physicochemical properties of peanut samples were monitored and measured, revealing the pattern of quality deterioration caused by Aspergillus flavus infection. This pattern provides a material basis explanation for the spectral changes. For example... Figure 3 (The changes in the physicochemical properties of peanut samples during cultivation, including (A) moisture content, (B) fat content, (C) acid value, and (D) protein content) are shown. As the number of cultivation days increases, the moisture, fat, and protein contents of peanut samples in different water activity groups all show a decreasing trend, while the acid value increases significantly. Specifically, in the high water activity (0.96aw) group, the daily average consumption of fat and protein is the highest in the later stage of cultivation, and the acid value increases the fastest, reaching 2.44 g / 100g / day, 2.13 g / 100g / day, and 1.08 mg KOH / g / day, respectively. This indicates that suitable moisture conditions significantly promote the growth and metabolism of Aspergillus flavus, accelerate the decomposition and consumption of peanut nutrients by its secreted lipases and proteases, and the accumulation of free fatty acids. This systemic quality deterioration process occurs simultaneously with toxin accumulation, providing an intrinsic correlation for the simultaneous monitoring of toxins and quality using hyperspectral technology.

[0050] Microstructural observation of peanut slices using scanning electron microscopy (e.g.) Figure 4 As shown, Figure 4The microstructure of peanut samples at different culture stages is shown in (A) blank (B) 2 days (C) 5 days (D) 9 days, which directly verifies the tissue damage caused by Aspergillus flavus infection. The uninoculated control group showed tightly packed cells with abundant contents. As the culture time progressed, hyphal infection led to gradual cell wall damage and content lysis, resulting in severe structural damage such as cell wall collapse and pore formation on the surface of fat particles in the later stages of culture. This evolution of micromorphology, along with the aforementioned consumption of nutrients and increase in acid value, corroborates each other, forming a complete phenotypic and intrinsic chain of evidence for peanut mold growth, illustrating the necessity of using non-destructive methods such as hyperspectral imaging to detect mold growth.

[0051] In the crucial stage of model building, various preprocessing techniques were applied to the raw hyperspectral data to optimize the input features. For example... Figure 5 The images show the spectra of peanut samples after different preprocessing methods, where (A) is SNV, (B) is MSC, (C) is SG, and (D) is median filtering. The spectral data were processed using multivariate scattering correction, standard normal variable transformation, Savitzky-Golay smoothing, and median filtering, respectively. Preprocessing effectively eliminated baseline drift, scattering effects, and random noise, improving the signal-to-noise ratio and consistency of the spectra, making subsequent feature extraction and model training more reliable. In particular, the spectral data preprocessed with median filtering showed a good balance between overall smoothness and feature preservation.

[0052] To further screen key information, an improved hybrid frog-leap algorithm was used to select 30 characteristic wavelengths from the entire spectrum. Correlation analysis showed that these characteristic wavelengths were significantly positively correlated with the AFB1 content and most physicochemical properties (moisture, fat, protein) of peanut samples (Pearson correlation coefficient r>0.9), while showing a significant negative correlation with acid value. For example, the characteristic absorption peak at approximately 1046 nm was associated with the RNH2 stretching third overtone of proteins, while the absorption in the 1060–1270 nm range may be associated with unsaturated δ-lactone rings. These analytical results reveal the strong correlation between hyperspectral information and the internal chemical composition and contamination status of peanuts, providing a solid theoretical basis for a rapid detection model based on characteristic wavelengths.

[0053] A systematic evaluation of different models was conducted, and the results are shown in Table 1. Traditional partial least squares regression and random forest models showed some fluctuations in performance on different preprocessed data. In contrast, the improved one-dimensional convolutional neural network model constructed in this invention exhibited significantly superior and stable prediction performance. Especially on the feature band data after median filtering preprocessing, the CNN model achieved near-optimal goodness of fit and prediction accuracy on both the training and validation sets (determination coefficients R² reached 0.9774 and 0.9814, respectively; root mean square error of prediction (RMSE) as low as 7.25 and 6.35 μg / kg; and relative analysis error (RPD) as high as 2.77 and 2.81). The regression prediction scatter plot of this model on the independent test set (e.g.) Figure 6 As shown in the figure, all predicted points are evenly distributed on both sides of the 1:1 reference line, and the predicted values ​​are in high agreement with the measured values, exhibiting a good linear relationship. This fully demonstrates that the CNN model, with its convolutional and pooling layer structure, can automatically and efficiently extract deep abstract features from hyperspectral data, accurately depicting the complex nonlinear mapping relationship between toxin content and spectral response. SFLA feature optimization further removes redundant spectral information, enhancing the model's feature learning efficiency and generalization ability.

[0054] Table 1 Evaluation of the effectiveness of different modeling methods in modeling preprocessed characteristic spectra The above embodiments fully demonstrate that this invention combines hyperspectral imaging technology with optimized hybrid frog-jumping algorithm feature selection and an improved one-dimensional convolutional neural network model. This not only enables rapid, non-destructive, and accurate quantitative prediction of aflatoxin B1 content in peanuts, but also effectively correlates its spectral characteristics with the nutrient loss and quality deterioration that accompany the mold growth process. This method provides an innovative and powerful technical solution for the online integrated monitoring of mycotoxins and quality in agricultural products.

[0055] This invention also provides an electronic device, which includes, but is not limited to: Memory, used to store programs; The processor is used to execute a program stored in memory. When the processor executes the program stored in memory, the processor is used to perform the above-described method for detecting aflatoxin in grains.

[0056] The processor and memory can be connected via a bus or other means.

[0057] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs, such as the method described in the embodiments of the present invention. The processor implements the above method by running the non-transitory software program and instructions stored in the memory.

[0058] The memory may include a program storage area and a data storage area, wherein the program storage area may store the operating system and application programs required for at least one function; the data storage area may store data for executing the methods described above. Furthermore, the memory may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory may optionally include memory remotely located relative to the processor, which can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0059] The non-transitory software program and instructions required to implement the above terminal selection method are stored in memory and are executed by one or more processors.

[0060] This invention also provides a storage medium storing computer-executable instructions for performing the above-described methods.

[0061] In one embodiment, the storage medium stores computer-executable instructions that are executed by one or more control processors.

[0062] The embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0063] It will be understood by those skilled in the art that all or some of the steps and systems in the methods disclosed above can be implemented as software, firmware, hardware, and suitable combinations thereof. Some or all of the physical components can be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include computer storage media (or non-transitory media) and communication media (or transient media). As is known to those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data). Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, as is known to those skilled in the art, communication media typically include computer-readable instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.

[0064] This document describes embodiments of the invention, including preferred embodiments known to the inventors for carrying out the invention. Variations of these embodiments will become apparent to those skilled in the art upon reading the foregoing description. The inventors encourage those skilled in the art to adopt such variations as appropriate, and the inventors intend to practice embodiments of the invention in ways other than those specifically described herein. Therefore, the scope of the invention includes all modifications and equivalents of the subject matter set forth in the appended claims, as permitted by applicable law. Furthermore, the scope of the invention covers any combination of the foregoing elements in all possible variations thereof, unless otherwise indicated herein or otherwise clearly contradicted by the context.

Claims

1. A method for detecting aflatoxin in grains, characterized in that, include: Acquire hyperspectral images of grains; Based on the hyperspectral image, continuous feature wavelengths are obtained through an improved hybrid frog-jumping algorithm, thereby obtaining the features of the hyperspectral image; Based on the feature-extracted hyperspectral image, a detection network model is trained and validated. This trained network model is then used to detect the aflatoxin content in grains. The improved hybrid frog-jumping algorithm is used to obtain continuous feature wavelengths from the hyperspectral image, including: The bands corresponding to the hyperspectral image are divided into several bands; Based on the divided bands, several wavelength subset selection schemes are randomly generated and the fitness value of each wavelength subset selection scheme is calculated. Based on the fitness value of the selected scheme for each wavelength subset, the meme group is divided and internally updated; The internally updated meme groups are globally shuffled, and the meme groups are further divided and internally updated until the optimal wavelength subset selection scheme, i.e., continuous characteristic wavelengths, is obtained under the iterative condition. The process of dividing and internally updating the meme groups based on the fitness value of each wavelength subset selection scheme includes: Based on the fitness value of each wavelength subset selection scheme, the wavelength subset selection schemes are sorted and the sorted wavelength subset selection schemes are cyclically distributed to obtain several memes. For each meme group, the best and worst individuals within the group are determined based on the fitness value; the worst individual is updated by completing the continuous wavelengths in the worst individual based on the generated step size vector. The methods for generating the step size vector include: For any position in the step vector, if the left or right neighbor of the best individual in the meme group is selected, then that position is selected; otherwise, that position is selected randomly.

2. The method for detecting aflatoxin in cereals according to claim 1, characterized in that, The calculation of the fitness value of each wavelength subset selection scheme includes: The hyperspectral images corresponding to the wavelength subset selection schemes are input into the vector regression model to obtain the initial predicted aflatoxin content. The root mean square error is obtained by comparing the initial predicted aflatoxin content with the aflatoxin content obtained by accurate detection of the hyperspectral image. Information redundancy is determined by the Pearson correlation coefficient of the emissivity among the selected bands in the wavelength subset selection scheme. The fitness value of the wavelength subset selection scheme is obtained based on the root mean square error and the information redundancy.

3. The method for detecting aflatoxin in cereals according to claim 1, characterized in that, The step of globally shuffling several internally updated meme sets to obtain the optimal meme set includes: Several meme groups are split and sorted according to the fitness value of each wavelength subset selection scheme. The top E wavelength subset selection schemes with the highest fitness values ​​are then selected. Here, E is a preset positive integer. The E wavelength subset selection schemes are cyclically allocated and sorted to obtain several meme groups. The internal updates and meme group divisions are continued until the fitness values ​​of the wavelength subset selection schemes do not exceed a preset threshold. The wavelength subset selection scheme with the smallest difference between the number of bands and the preset target number of bands is taken as the optimal wavelength subset selection scheme.

4. The method for detecting aflatoxin in cereals according to claim 1, characterized in that, Also includes: After updating the worst individual, a wavelength subset selection scheme is selected with a preset mutation probability. If the number of selected bands in the wavelength subset selection scheme is greater than the preset target number of bands, the bands that are more than the target number of bands are randomly deselected; otherwise, the bands that are less than the target number of bands are randomly selected.

5. An apparatus for detecting aflatoxin in grains, used to achieve the functions described in any one of claims 1 to 4, characterized in that, include: Hyperspectral camera and controller; The hyperspectral camera is used to acquire hyperspectral images of the grain; Send the hyperspectral image to the controller; The controller is used to obtain continuous feature wavelengths from the hyperspectral image using an improved hybrid frog-jumping algorithm, thereby obtaining the features of the hyperspectral image; and to train and validate a detection network model based on the feature-extracted hyperspectral image, thereby detecting the aflatoxin content of grains using the trained detection network model.

6. An electronic device, characterized in that, include: Memory, used to store programs; A processor for executing a program stored in the memory, wherein when the processor executes the program stored in the memory, the processor is configured to perform the method as described in any one of claims 1 to 4.

7. A storage medium, characterized in that, The computer stores computer-executable instructions, which enable the computer to perform the method as described in any one of claims 1 to 4.