Coarse cereal aflatoxin detection method based on combination of hyperspectral imaging and deep learning
By combining hyperspectral imaging with deep learning, a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network model was built. This solved the problem of the difficulty in synergistic utilization of spatial and spectral information in existing technologies, and enabled the accurate detection of aflatoxin in grains and the precise location of contaminated areas, thereby improving the generalization ability and stability of the detection model.
Patent Information
- Application Number
- CN202610276682.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-03-09
- Publication Date
- 2026-04-07
AI Technical Summary
Existing technologies struggle to achieve the synergistic utilization and deep fusion of spatial and spectral information in hyperspectral imaging data. They are unable to simultaneously and completely extract effective information related to aflatoxin contamination from the spatial morphological and spectrochemical features of grain samples, resulting in insufficient accuracy of detection results. Furthermore, the lack of standardized spatiotemporal registration and feature alignment processing affects the generalization ability and robustness of the detection model.
This study employs a hyperspectral imaging approach combined with deep learning. By constructing a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, it achieves the synergistic utilization of spatial and spectral information, performs spatiotemporal registration and feature alignment, and builds an adapted dual-branch feature fusion network architecture for learning and matching aflatoxin contamination features.
It enables precise detection of aflatoxin contamination and accurate location of contaminated areas, improves the generalization ability of the detection method and the stability of the results, and ensures the consistency of input data and the validity of features.
Smart Images

Figure CN121805167A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of agricultural product quality and safety testing, and in particular to a method for detecting aflatoxin in grains using hyperspectral imaging combined with deep learning. Background Technology
[0002] As an important component of my country's grain production and consumption system, the safety of coarse grains directly relates to food security management and consumer health. Aflatoxin, a highly toxic and carcinogenic fungal toxin, is one of the most significant safety risks associated with coarse grains throughout the entire supply chain, from planting and harvesting to storage, processing, and distribution. Therefore, efficient and accurate detection technologies for aflatoxin in coarse grains have always been a key research focus in the field of agricultural product quality and safety testing. Currently, aflatoxin detection technology has developed in parallel with multiple technological approaches. Traditional physicochemical detection and immunochromatographic detection technologies have established mature application systems. Hyperspectral imaging technology, with its core advantages of being non-destructive, non-contact, and capable of simultaneously acquiring spatial morphological and spectrochemical information of samples, has achieved rapid development and widespread application in the field of non-destructive testing of agricultural product contaminants. Meanwhile, the iterative upgrade of deep learning technology has provided core technical support for the in-depth mining and intelligent analysis of hyperspectral data. Convolutional neural network algorithms have shown significant technical advantages in hyperspectral feature extraction, feature fusion, and pattern classification. Combining hyperspectral imaging technology with deep learning algorithms has become the mainstream development direction in the field of intelligent detection of mycotoxins in agricultural products. Related technology research and application are continuously advancing, and rich technical accumulation and practical experience have been formed in the quality evaluation and safety testing scenarios of various agricultural products such as grains, fruits and vegetables, and oilseeds. This has promoted the continuous development of agricultural product safety testing technology towards intelligence, automation, and on-site application.
[0003] In the practical application and research of existing related technologies, there are still a series of technical shortcomings that urgently need to be addressed, making it difficult to fully adapt to the actual application needs of aflatoxin detection in grains. First, most existing detection schemes fail to achieve the synergistic utilization and deep fusion of spatial and spectral information in hyperspectral imaging data. They cannot simultaneously and completely extract effective information related to aflatoxin contamination from the spatial morphological features and spectrochemical features of grain samples, making it difficult to fully leverage the core advantages of hyperspectral imaging technology in acquiring multidimensional information and limiting the improvement of detection accuracy. Second, in the hyperspectral data preprocessing stage, existing technologies lack standardized spatiotemporal registration and feature alignment processes, which easily leads to misalignment and insufficient matching between spatial and spectral dimension information. This results in insufficient consistency of basic data and feature correlation for model training, making it difficult for the detection model to meet the requirements of practical applications in terms of generalization ability and robustness. Furthermore, existing deep learning-based detection solutions mostly employ single-structure network models for feature extraction and classification, failing to build a suitable dual-branch feature fusion network architecture tailored to the characteristics of aflatoxin contamination in grains. This makes it impossible to achieve targeted learning and accurate matching of aflatoxin contamination features. In addition, most technical solutions can only qualitatively determine whether the sample as a whole is contaminated, and cannot achieve pixel-level precise localization of contaminated areas on grain particles. This makes it difficult to meet the practical application needs for refined detection of aflatoxin in grains and accurate assessment of contamination levels. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method for detecting aflatoxin in grains by combining hyperspectral imaging with deep learning.
[0005] The objective of this invention is achieved through the following technical solution: A method for detecting aflatoxin in grains using hyperspectral imaging combined with deep learning is provided. This method includes the following steps: S1. Collect hyperspectral imaging data of grain particles, extract spatial and spectral information from the hyperspectral imaging data, and combine the spatial and spectral information to form basic hyperspectral imaging data; S2. Perform preprocessing operations on the hyperspectral imaging base data, and perform spatiotemporal registration and feature alignment operations on the preprocessed hyperspectral imaging base data; S3. Construct a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Import the processed hyperspectral imaging basic data into the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform iterative training on the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model to enable the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model to complete the learning and matching of aflatoxin contamination features. S4. Collect hyperspectral imaging data of the grains to be tested, perform standard preprocessing on the data, import the trained hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and perform aflatoxin detection and contamination area localization through pixel-level analysis.
[0006] Furthermore, step S1 includes: S1.1. Perform a flat laying operation on the grain particles, perform flattening, leveling and surface cleaning on the laying surface, adjust the distribution and posture of the grain particles, implement a single-layer arrangement of grain particles, separate the grain particles that are in contact with each other, fix the laying surface, remove damaged and irregular grain particles, and keep the grain particles in a non-overlapping and non-obstructing arrangement. S1.2. Perform light source stabilization control, fixed acquisition parameters and synchronous acquisition of spectral channels on the arranged grain particles, perform full-domain scanning, row-by-row scanning and column-by-column acquisition, perform point-by-point imaging, extract spatial and spectral information from hyperspectral imaging data, perform geometric correction, distortion correction and spatial dimension resampling on spatial information, perform baseline correction, drift correction and spectral dimension smoothing on spectral information, and remove abnormal acquisition data.
[0007] Furthermore, step S3 involves constructing a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, which includes: S3.1. Divide the processed hyperspectral imaging base data into training subsets and validation subsets without cross-over. Perform sample shuffling, sample balancing and stratification. Perform pixel-level data annotation on the training subset and validation subset respectively. The annotation content includes aflatoxin contaminated areas and non-contaminated areas. Perform the binding of annotation labels with data samples to establish a one-to-one correspondence between labels and data. S3.2. Perform random weight initialization on the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, configure the ReLU activation function and cross-entropy loss function of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, set the training batch size, initial learning rate value and learning rate decay rule, use the training subset to perform forward propagation operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, pass data features layer by layer, use the validation subset to perform loss value calculation, perform backward gradient update, gradient clipping and learning rate adjustment of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model round by round, set training early stopping rule, adjust the internal operating parameters and network weights of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and repeat the training and validation process.
[0008] Furthermore, step S2 includes: S2.1. Perform background signal subtraction, background reference value calibration and noise removal on the basic hyperspectral imaging data, perform neighborhood comparison, identify and remove invalid data information, perform neighborhood interpolation repair on bad data points, and identify and remove abnormal values. S2.2. Perform normalization and centering on the processed hyperspectral imaging base data, perform numerical interval mapping, adjust the data numerical distribution range, perform data bad line repair, bandpass filtering, effective band selection and band interval alignment, complete the dimensional mapping of data spatiotemporal registration and feature alignment, and perform point-by-point matching of spatial information and spectral information corresponding coordinates.
[0009] Furthermore, step S4 includes: S4.1. Perform impurity removal and sieving on the grains to be tested, separate the grains to be tested from surface debris and dust, perform surface cleaning, particle regularization and separation on the grains to be tested, and adjust the arrangement of the grains to be tested so that the grains to be tested meet the data collection conditions; S4.2. Perform the same preprocessing, spatiotemporal registration, and feature alignment as in the training phase on the hyperspectral imaging data of the grains to be tested. Import the processed data into the trained hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform forward propagation inference operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform pixel-by-pixel traversal, feature discrimination, feature vector generation, feature mapping, and region connectivity analysis. Perform pixel-by-pixel softmax classification operation, output pixel-level classification results, and perform connected component labeling.
[0010] Furthermore, in step S1, the hyperspectral imaging data is classified, deduplicated, and indexed. The hyperspectral imaging data is time-series marked and encoded. The hyperspectral imaging data is divided according to the grain category. Time-series identifiers are added to the hyperspectral imaging data collected at different times. The classified hyperspectral imaging data set is constructed and grouped for storage.
[0011] Furthermore, in step S2, feature enhancement, feature filtering, feature vector normalization, and data decorrelation processing are performed on the preprocessed hyperspectral imaging basic data to extract pollution-related feature information from the hyperspectral imaging basic data. Feature dimension matching is performed to make the feature dimension match the input dimension requirements of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, eliminate redundant correlation information, and reduce data dimension redundancy.
[0012] Furthermore, in step S3, the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model is configured with a multi-level network structure. The network structure sequentially includes an input layer, a spatial feature extraction branch, a spectral feature extraction branch, a dual-branch feature fusion module, a two-dimensional convolution module, a pooling module, a residual connection module, a multi-scale feature extraction module, a channel attention mechanism module, a feature pyramid network module, a fully connected module, and a classification output module. The spatial feature extraction branch and the spectral feature extraction branch are connected in parallel to the output of the input layer. The dual-branch feature fusion module is connected to the outputs of both the spatial and spectral feature extraction branches. The two-dimensional convolution module is connected to the output of the dual-branch feature fusion module. The pooling module is connected to the output of the two-dimensional convolution module. The residual connection module is connected to the input of the two-dimensional convolution module and the output of the pooling module. The multi-scale feature extraction module is connected to the pooling module. The output of the block is as follows: the channel attention mechanism module is connected to the output of the multi-scale feature extraction module; the feature pyramid network module is connected to the output of the channel attention mechanism module; the fully connected module is connected to the output of the feature pyramid network module; and the classification output module is connected to the output of the fully connected module. The weight initialization rules for the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model are set. A multi-scale sliding window is set for the multi-scale feature extraction module, and feature upsampling and downsampling are performed on the feature pyramid network module. Spatial and spectral feature information are extracted through the spatial feature extraction branch and the spectral feature extraction branch, respectively. Feature splicing and fusion are performed through the dual-branch feature fusion module. Pollution features at different scales are collected through the multi-scale feature extraction module, and multi-scale feature fusion is performed. This constructs the multi-level feature recognition logic of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model.
[0013] Furthermore, in step S4, threshold discrimination is performed on the pixel-level classification results output by the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and integration, spatial coordinate matching and regional boundary calibration are performed on the scattered data generated by pixel-level analysis. Consistency verification and duplication verification are performed on the integrated data, and the output format of the detection and positioning data information is standardized.
[0014] Furthermore, after step S4 is completed, the detection and positioning data information is standardized and verified, the converted detection and positioning data information is classified, archived and encrypted, the archived data is traced back and traced back codes are generated, the traced back codes are bound to the detection data and the training parameters of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and the output standard of the detection results and the data traceability system are established.
[0015] The beneficial effects of this invention are: (1) Through the complete process of hyperspectral imaging data acquisition and processing and deep learning model training and inference, the accurate detection of the pollution status of the target object and the accurate location of the pollution area can be achieved; (2) Performing standardized preprocessing, spatiotemporal registration and feature alignment operations on hyperspectral imaging data can effectively eliminate data interference and ensure the consistency of input data and the validity of features; (3) The convolutional neural network architecture with dual-branch feature fusion, combined with the full-process data management system, can significantly improve the generalization ability, execution stability and result traceability of the detection method. Attached Figure Description
[0016] Figure 1 A flowchart illustrating the steps of a method for detecting aflatoxin in grains using hyperspectral imaging combined with deep learning; Figure 2 The flowchart illustrates the specific steps of a method for detecting aflatoxin in grains using hyperspectral imaging combined with deep learning, as provided in this embodiment. Detailed Implementation
[0017] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] Example 1 See Figure 1 This embodiment provides a method for detecting aflatoxin in grains using hyperspectral imaging combined with deep learning. The method includes the following steps: S1. Collect hyperspectral imaging data of grain particles, extract spatial and spectral information from the hyperspectral imaging data, and combine the spatial and spectral information to form basic hyperspectral imaging data; S2. Perform preprocessing operations on the hyperspectral imaging base data, and perform spatiotemporal registration and feature alignment operations on the preprocessed hyperspectral imaging base data; S3. Construct a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Import the processed hyperspectral imaging basic data into the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform iterative training on the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model to enable the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model to complete the learning and matching of aflatoxin contamination features. S4. Collect hyperspectral imaging data of the grains to be tested, perform standard preprocessing on the data, import the trained hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and perform aflatoxin detection and contamination area localization through pixel-level analysis.
[0019] In some embodiments, step S1 includes: S1.1. Perform a flat laying operation on the grain particles, perform flattening, leveling and surface cleaning on the laying surface, adjust the distribution and posture of the grain particles, implement a single-layer arrangement of grain particles, separate the grain particles that are in contact with each other, fix the laying surface, remove damaged and irregular grain particles, and keep the grain particles in a non-overlapping and non-obstructing arrangement. S1.2. Perform light source stabilization control, fixed acquisition parameters and synchronous acquisition of spectral channels on the arranged grain particles, perform full-domain scanning, row-by-row scanning and column-by-column acquisition, perform point-by-point imaging, extract spatial and spectral information from hyperspectral imaging data, perform geometric correction, distortion correction and spatial dimension resampling on spatial information, perform baseline correction, drift correction and spectral dimension smoothing on spectral information, and remove abnormal acquisition data.
[0020] In some embodiments, the construction of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model in step S3 includes: S3.1. Divide the processed hyperspectral imaging base data into training subsets and validation subsets without cross-over. Perform sample shuffling, sample balancing and stratification. Perform pixel-level data annotation on the training subset and validation subset respectively. The annotation content includes aflatoxin contaminated areas and non-contaminated areas. Perform the binding of annotation labels with data samples to establish a one-to-one correspondence between labels and data. S3.2. Perform random weight initialization on the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, configure the ReLU activation function and cross-entropy loss function of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, set the training batch size, initial learning rate value and learning rate decay rule, use the training subset to perform forward propagation operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, pass data features layer by layer, use the validation subset to perform loss value calculation, perform backward gradient update, gradient clipping and learning rate adjustment of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model round by round, set training early stopping rule, adjust the internal operating parameters and network weights of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and repeat the training and validation process.
[0021] In some embodiments, step S2 includes: S2.1. Perform background signal subtraction, background reference value calibration and noise removal on the basic hyperspectral imaging data, perform neighborhood comparison, identify and remove invalid data information, perform neighborhood interpolation repair on bad data points, and identify and remove abnormal values. S2.2. Perform normalization and centering on the processed hyperspectral imaging base data, perform numerical interval mapping, adjust the data numerical distribution range, perform data bad line repair, bandpass filtering, effective band selection and band interval alignment, complete the dimensional mapping of data spatiotemporal registration and feature alignment, and perform point-by-point matching of spatial information and spectral information corresponding coordinates.
[0022] In some embodiments, step S4 includes: S4.1. Perform impurity removal and sieving on the grains to be tested, separate the grains to be tested from surface debris and dust, perform surface cleaning, particle regularization and separation on the grains to be tested, and adjust the arrangement of the grains to be tested so that the grains to be tested meet the data collection conditions; S4.2. Perform the same preprocessing, spatiotemporal registration, and feature alignment as in the training phase on the hyperspectral imaging data of the grains to be tested. Import the processed data into the trained hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform forward propagation inference operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform pixel-by-pixel traversal, feature discrimination, feature vector generation, feature mapping, and region connectivity analysis. Perform pixel-by-pixel softmax classification operation, output pixel-level classification results, and perform connected component labeling.
[0023] In some embodiments, in step S1, the hyperspectral imaging data is classified, deduplicated, and indexed; the hyperspectral imaging data is time-series labeled and encoded; the hyperspectral imaging data is divided according to the category of grains; time-series identifiers are added to the hyperspectral imaging data collected at different times; a classified hyperspectral imaging data set is constructed; and group storage is performed.
[0024] In some embodiments, in step S2, feature enhancement, feature filtering, feature vector normalization and data decorrelation processing are performed on the preprocessed hyperspectral imaging basic data to extract pollution-related feature information from the hyperspectral imaging basic data, and feature dimension matching is performed to make the feature dimension match the input dimension requirements of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, thereby eliminating redundant correlation information and reducing data dimension redundancy.
[0025] In some embodiments, in step S3, the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model is configured with a multi-level network structure. The network structure sequentially includes an input layer, a spatial feature extraction branch, a spectral feature extraction branch, a dual-branch feature fusion module, a two-dimensional convolution module, a pooling module, a residual connection module, a multi-scale feature extraction module, a channel attention mechanism module, a feature pyramid network module, a fully connected module, and a classification output module. The spatial feature extraction branch and the spectral feature extraction branch are connected in parallel to the output of the input layer. The dual-branch feature fusion module is connected to the output of the spatial feature extraction branch and the output of the spectral feature extraction branch. The two-dimensional convolution module is connected to the output of the dual-branch feature fusion module. The pooling module is connected to the output of the two-dimensional convolution module. The residual connection module is connected to the input of the two-dimensional convolution module and the output of the pooling module. The multi-scale feature extraction module is connected to the pooling module. The output of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model is constructed. The channel attention mechanism module is connected to the output of the multi-scale feature extraction module, the feature pyramid network module is connected to the output of the channel attention mechanism module, the fully connected module is connected to the output of the feature pyramid network module, and the classification output module is connected to the output of the fully connected module. Weight initialization rules are set for the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. A multi-scale sliding window is set for the multi-scale feature extraction module, and feature upsampling and downsampling are performed on the feature pyramid network module. Spatial and spectral feature information are extracted through the spatial feature extraction branch and the spectral feature extraction branch, respectively. Feature splicing and fusion are performed through the dual-branch feature fusion module. Pollution features at different scales are collected through the multi-scale feature extraction module, and multi-scale feature fusion is performed. This constructs the multi-level feature recognition logic of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model.
[0026] In some embodiments, in step S4, threshold discrimination is performed on the pixel-level classification results output by the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and integration, spatial coordinate matching and regional boundary calibration are performed on the scattered data generated by pixel-level analysis, consistency verification and duplication verification are performed on the integrated data, and the output format of the detection and positioning data information is standardized.
[0027] In some embodiments, after step S4 is completed, the detection and positioning data information is standardized and verified, the converted detection and positioning data information is classified, archived and encrypted, the archived data is traced back and traced back codes are generated, the traced back codes are bound to the detection data and the training parameters of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and the output specifications of the detection results and the data traceability system are established.
[0028] Example 2 This embodiment provides a specific implementation process for a method of detecting aflatoxin in grains using hyperspectral imaging combined with deep learning. Through the entire process of hyperspectral imaging data acquisition and processing, deep learning model building and iterative training, sample detection, and result management, qualitative detection of aflatoxin in grains and pixel-level localization of contaminated areas can be achieved. Figure 2 As shown, the specific implementation process is as follows: S1. Hyperspectral Imaging Data Acquisition and Basic Data Construction: S1.1. Sample arrangement and pre-collection preparation: Before laying out the grains, a standard inspection sieve matching the grain size is used to vibrate and screen the target grains to remove impurities such as straw, soil, and broken debris, preventing them from interfering with subsequent imaging quality. The surface on which the grains are laid out undergoes systematic processing. A matte black material is selected as the placement carrier to avoid spectral interference caused by specular reflection and ambient light diffuse reflection. The surface is leveled using a flatness detector to perform area-by-area inspection and correction, ensuring that the flatness deviation is within a preset range. A digital level is used to calibrate the horizontal and vertical alignment of the surface, and the tilt angle is corrected by fine-tuning the support structure to ensure that the grains do not shift due to gravity. A combination of wiping with a dust-free non-woven cloth and blowing with clean compressed air is used to clean the surface, removing dust, debris, and other foreign objects to prevent them from forming invalid interference signals.
[0029] After planar processing, the grains are evenly placed on the plane using automated or manual placement equipment, strictly adhering to single-layer placement to ensure each grain is in direct contact with the plane without multi-layer stacking. During placement, the distribution and orientation of the grains are adjusted so that the flattest surface of each grain faces the imaging lens. Simultaneously, contacting grains are separated one by one to ensure the spacing between grains is not less than the preset minimum safety distance, avoiding edge occlusion that could lead to missing surface information. After placement, the plane position and angle are locked using clamps to prevent displacement and vibration during scanning. Each grain is inspected and removed if it is damaged, cracked, or severely deformed, ultimately ensuring that all remaining grains are evenly arranged without overlap, occlusion, or contact.
[0030] S1.2. Hyperspectral data scanning and information extraction: Light source stabilization control was implemented for the arranged grain particles, using a highly uniform line light source. A preset preheating time was performed before acquisition to stabilize the light intensity. During acquisition, the light intensity was monitored and adjusted in real time using a light intensity sensor to ensure that the light intensity fluctuation was controlled within a preset range. Simultaneously, the illumination angle, distance, and spot size of the light source were fixed to ensure that all particles received completely consistent lighting conditions. Acquisition parameters were fixed in advance, including the spectral sampling interval, band range, exposure time, scan step size, and spatial resolution of the hyperspectral imaging equipment. All batches of samples were acquired using completely identical parameter settings to eliminate the impact of differences in acquisition parameters on data consistency. All spectral channels were set to a synchronous trigger acquisition mode to ensure that the acquisition time for all channels of pixels at the same spatial location was completely consistent, avoiding misalignment between spectral and spatial information.
[0031] After completing parameter settings and system debugging, perform full-area scanning, row-by-row scanning and column-by-column acquisition on the grain particles to ensure that the scanning range completely covers all particle distribution areas without any particles being missed; perform point-by-point imaging on each pixel within the scanning range to collect complete spectral data across the entire spectrum, so that each pixel corresponds to a complete spectral curve and a unique two-dimensional spatial coordinate, ultimately forming a three-dimensional hyperspectral data cube containing two-dimensional spatial information and one-dimensional spectral information.
[0032] Spatial and spectral information were extracted from the acquired hyperspectral imaging data. Geometric correction, distortion correction, and spatial dimension resampling were performed on the spatial information: a high-precision checkerboard calibration board was used to complete the device's geometric calibration, and the image geometric distortion was corrected based on the calibration parameters to ensure a fixed linear correspondence between pixel distances and actual physical distances; barrel and pincushion distortion corrections were performed simultaneously to ensure that the particle morphology in the image was consistent with the actual physical morphology; bilinear interpolation was used to perform spatial dimension resampling, adjusting images from different scan rows to a uniform number of pixel rows and columns to ensure completely uniform spatial resolution for all data. Baseline correction, drift correction, and spectral dimension smoothing were performed on the spectral information: a polynomial fitting algorithm was used to perform spectral baseline fitting and subtraction to eliminate baseline shifts caused by light sources and dark currents; standard whiteboard reference spectral data was used to correct channel response drift, ensuring consistent response of the same wavelength spectral data across different samples and at different times; and Savitzky-Golay smoothing filtering was used to perform spectral dimension smoothing, eliminating random noise while fully preserving key information such as spectral characteristic peaks and valleys. Finally, abnormal data collection is removed by identifying and eliminating invalid data such as completely black, completely white, data without spectral feature changes, and severely blurred images, ensuring that all retained data are valid and usable.
[0033] S1.3. Basic Data Construction and Data Management: The validated hyperspectral imaging data are classified and organized. Primary classification is performed by grain category, with data from different categories stored independently. Data from the same category is grouped by collection batch. Duplicate data is identified by comparing collection timestamps, spatial and spectral features, and only one valid data is retained to avoid uneven sample distribution. A retrieval index containing information such as collection time, sample batch, spectral range, and spatial resolution is built for each data group to improve data management and retrieval efficiency.
[0034] All hyperspectral imaging data were time-series labeled and encoded, with each data set assigned a time-series identifier containing year, month, day, hour, minute, and second. A unique time-series code consisting of "category code + collection date + batch number" was also assigned, enabling full lifecycle time-series traceability of the data. Based on the grain category and collection time, a categorized hyperspectral imaging dataset was constructed. Grouped storage and hierarchical access permissions were implemented for different data groups to ensure data storage security. Spatial and spectral information were combined to form basic hyperspectral imaging data, serving as the foundational data source for subsequent preprocessing and model training.
[0035] In some specific implementations, standardized numerical implementation processes are executed for the acquisition, dataset construction, and partitioning of basic hyperspectral imaging data to ensure dataset consistency and reusability. This implementation uses fixed acquisition batches, with all samples following a uniform arrangement and acquisition process. After acquisition, uniform correction, classification, and encoding are performed to construct a complete basic hyperspectral imaging dataset. After dataset construction, a non-overlapping hierarchical partitioning is performed to ensure consistent sample category distribution between the training and validation subsets. Specific dataset partitioning rules and requirements are shown in Table 1. Simultaneously, uniform pixel-level annotation is performed on all samples in both subsets, labeling them as aflatoxin-contaminated or non-contaminated areas. A unique category label is assigned to each pixel, binding the label to the sample's spatial coordinates and spectral information. After annotation, consistency verification is performed, removing invalid samples with incorrect annotations or missing labels, providing standardized input data for model training, allowing for direct reproducibility of the implementation.
[0036] Table 1. Specifications for Hyperspectral Dataset Division and Labeling Dataset types Sample proportion Core annotation requirements Data admission rules Training subset 70% Pixel-level point-by-point annotation, binding spatial coordinates and spectral information No outlier data, complete annotations, no duplicate samples Validation subset 30% Same annotation standard, no sample overlap with the training subset. The class distribution is consistent with the training subset, and there are no labeling errors. S2. Basic data preprocessing and dimension matching for hyperspectral imaging: S2.1. Data noise removal and invalid information cleanup: Background reference values were calibrated for the basic hyperspectral imaging data. Before each batch of samples was collected, background hyperspectral data of the placement plane without samples was collected with the same parameters. The background data was averaged across the entire area to form a background reference matrix that perfectly matched the dimensions of the sample data. Background signal subtraction was performed, and pixel-by-pixel and channel-by-channel difference calculations were performed between the sample data and the background reference matrix to eliminate the interference of the placement plane and ambient stray light on the sample spectral data and restore the true spectral response characteristics of the grain samples.
[0037] The system performs noise removal, identifying and processing all noise in the data after background subtraction. It also performs neighborhood comparison, selecting a preset-size set of neighboring pixels centered on a single pixel, calculating the mean and standard deviation of the response values for the same spectral channel within the neighborhood, and identifying pixels whose difference from the mean exceeds a preset multiple of the standard deviation as outliers. The system identifies and removes all invalid pixels with spectral channel response values of 0, maximum values, or no characteristic changes. Neighborhood interpolation is used to repair bad pixels, replacing their original values with the mean of effective neighboring pixels or bilinear interpolation to ensure spatial and spectral continuity. Finally, it removes and replaces outliers that exceed a reasonable distribution range, ensuring that the distribution of all data values remains within a reasonable and controllable range.
[0038] S2.2. Data regularization and band selection processing: Normalization and centering are performed on the noise-removed data. The min-max normalization algorithm is used to linearly map the values of each spectral channel to a unified interval of [0, 1], eliminating the difference in numerical magnitude between channels. The mean value of each spectral channel is calculated, and the pixel value is subtracted from the mean value of the corresponding channel to complete the centering, so that the center of the data distribution is adjusted to 0, reducing the negative impact of distribution offset on subsequent processing. According to the subsequent model input requirements, the data value interval mapping is completed to ensure that the data value distribution completely matches the model input requirements.
[0039] The process involves several steps: First, data line repair is performed. Invalid lines in entire rows and columns are identified and repaired using linear interpolation with adjacent rows and columns of valid data, restoring spatial continuity. Second, a Gaussian bandpass filter is used to retain valid signals in preset bands, filtering high and low frequency noise and increasing the proportion of valid feature signals. Third, statistical analysis compares the spectral response differences between polluted and unpolluted areas, identifying effective band intervals with significant feature differences and eliminating ineffective bands, thus reducing data dimensionality while preserving valid features. Fourth, band interval alignment is performed on all samples to ensure complete consistency in the effective band range, quantity, and sampling interval, guaranteeing a unified spectral dimension. Fifth, spatiotemporal registration and feature alignment are completed, ensuring a unique binding relationship between each spatial coordinate pixel and its corresponding complete spectral curve. Sixth, point-by-point matching of spatial and spectral coordinates is performed to ensure a one-to-one correspondence between spatial coordinates and spectral information, achieving complete alignment of the two types of information.
[0040] S2.3. Feature Processing and Dimension Matching: Feature enhancement processing is performed on the preprocessed hyperspectral imaging base data. By using first-order derivative and second-order derivative spectral transformations or multivariate scattering correction methods, the differences in pollution-related features are amplified, the influence of particle surface scattering on spectral data is eliminated, and the identification accuracy of pollution features is improved. Feature importance evaluation algorithm is used to complete feature screening, retaining feature dimensions with high contribution to pollution identification and eliminating invalid features. L2 normalization processing is performed on the feature vector corresponding to each pixel, normalizing the feature vector magnitude to 1, eliminating the difference in feature vector magnitude, and improving the accuracy of feature comparison.
[0041] The data undergoes decorrelation processing, calculating Pearson correlation coefficients between different feature dimensions and removing low-importance feature dimensions with correlation coefficients exceeding a preset threshold to eliminate redundant feature associations and reduce the risk of model overfitting. Spatial texture and spectral response features related to pollution are extracted from the data, while irrelevant information such as grain varieties and surface morphology is removed to ensure that the extracted features can effectively distinguish between polluted and non-polluted areas. Feature dimension matching is performed to standardize the dimension format, number of channels, and spatial size of the feature data, ensuring it fully matches the input layer dimension requirements of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, guaranteeing that the processed data can be directly input into the model. Redundant data compression is performed to remove redundant correlation information, reduce data dimensional redundancy, and reduce the computational load for model training and inference while retaining all effective features, thereby improving processing efficiency.
[0042] In some specific implementations, for the construction of a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, a standardized numerical structure configuration is executed, fully covering all technical aspects of model layers, module composition, connection relationships, feature extraction, and fusion, allowing for direct model construction and implementation. In this implementation, the core model structure adopts a fixed number of layers and module parameter configurations. Both parallel dual branches use 3 sets of convolutional + pooling layers to ensure accurate splicing and fusion of the dual-branch output feature dimensions. The dual-branch feature fusion module uses a channel-dimensional splicing method, the multi-scale feature extraction module sets a fixed number of sliding windows of different sizes, the channel attention mechanism module uses a two-layer fully connected layer structure, and the feature pyramid network module uses a fixed number of upsampling and downsampling times to construct a multi-scale feature pyramid. Detailed parameters and functional definitions of the core model modules are shown in Table 2. All modules are connected in a clearly defined order, the input layer dimension matches the preprocessed data dimension, and the classification output module dimension matches the number of labeled categories, allowing for direct reproduction and construction.
[0043] Table 2. Parameters and Functions of Core Modules in the Model Module Name Core structural configuration Key parameter settings Core Function Positioning Two-branch feature extraction branch 3 sets of convolutional layers + batch normalization + pooling layers Convolution kernel 3×3 / 3, stride 1 Parallel extraction of spatial and spectral features Dual-branch feature fusion module Channel dimension splicing structure The splicing dimension is the channel dimension. Fusion of spatial and spectral dual-modal features Multi-scale feature extraction module 3-way parallel convolution branches Convolution kernel 3×3 / 5×5 / 7×7 Collect characteristics of polluted areas at different scales. Channel attention mechanism module Global pooling + two fully connected layers Compression ratio is 8:1 Adaptive adjustment of feature channel weights Feature Pyramid Network Module Fusion of 3 downsampling and 3 upsampling Upsampling factor is 2 Integrating multi-resolution features enhances small target recognition. S3. Deep Learning Model Building and Iterative Training: S3.1. Dataset Partitioning and Labeling: The preprocessed and feature-processed hyperspectral imaging dataset was used as the model training dataset. A non-overlapping partitioning process was performed to create independent training and validation subsets, with no identical samples in either subset, ensuring complete independence between model training and validation. Stratified sampling was employed to partition the samples into layers based on grain type and contamination level. Samples were drawn from each layer according to a preset ratio and assigned to the two subsets, ensuring complete consistency in sample type and contamination level distribution between subsets. The training subset was randomly shuffled to eliminate the influence of sample order on model training. The number of pixels in contaminated and uncontaminated regions within the training subset was counted. If the difference in the number of samples between the two classes exceeded a preset threshold, oversampling or undersampling was used to balance the samples, preventing class imbalance that could lead to class bias in model training.
[0044] Pixel-level data annotation was performed on both the training and validation subsets. The annotation content was divided into two fixed categories: aflatoxin-contaminated areas and non-contaminated areas. Based on spatial images, combined with spectral feature information and physicochemical test results, the category attributes were determined pixel by pixel and a unique label was assigned to ensure that the labeled category was completely consistent with the actual contamination state of the sample. A unique ID was assigned to each sample, and the annotation label was bound to the sample's hyperspectral data, spatial coordinates, and spectral information to establish a one-to-one correspondence between the label and the data sample. After the annotation was completed, the annotation consistency was checked to remove invalid samples with annotation errors, missing labels, or labels that did not match the samples, ensuring that all samples in both subsets had complete and accurate annotation information.
[0045] To address the focal, low-concentration, and low-sample-ratio characteristics of aflatoxin contamination in grains, the annotation process uses the physical contour of the grain particles as the boundary, performing contaminated / non-contaminated category annotation only on pixels within the grain particle body region, completely excluding background pixels. This avoids invalid background information interfering with the training of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Simultaneously, for samples with low-concentration aflatoxin contamination in grains, refined annotation is performed on contamination boundary pixels during annotation. In the sample balancing stage, targeted oversampling is performed on pixels in low-concentration contamination areas to increase the proportion of low-concentration contamination features in the training data. This solves the problem of insufficient learning and high false negative rate in the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model caused by weak low-concentration aflatoxin contamination features and low sample ratio in grains.
[0046] S3.2. Deep Learning Model Structure Construction and Hierarchical Connections: A hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model was constructed. This model is an end-to-end fully supervised pixel-level classification network that can directly input 3D hyperspectral imaging data and output pixel-level classification results with the same spatial dimensions as the input data. The model network structure includes, in sequence, an input layer, a spatial feature extraction branch, a spectral feature extraction branch, a dual-branch feature fusion module, a 2D convolution module, a pooling module, a residual connection module, a multi-scale feature extraction module, a channel attention mechanism module, a feature pyramid network module, a fully connected module, and a classification output module. The connection relationships between each module and branch are fixed as follows: The input layer serves as the sole input to the model, receiving preprocessed 3D hyperspectral imaging data. The input data dimension format is [height, width, number of spectral bands]. The output of the input layer is simultaneously connected to the inputs of the spatial feature extraction branch and the spectral feature extraction branch, synchronously transmitting the input data to the two parallel branches.
[0047] In some specific implementations, the spatial feature extraction branch consists of three sets of sequentially connected “two-dimensional convolutional layers + batch normalization layers + ReLU activation layers + max pooling layers”. The three sets of convolutional layers all have a kernel size of 3×3, a stride of 1, and a padding of 1, with output channels of 32, 64, and 128 respectively. The max pooling layers all have a kernel size of 2×2 and a stride of 2. Through multi-layer convolution, features such as edges, textures, and regional morphology in the spatial dimension are extracted. The branch output is connected to the first input of the dual-branch feature fusion module. The spectral feature extraction branch consists of three sets of sequentially connected “one-dimensional convolutional layer + batch normalization layer + ReLU activation layer + average pooling layer”. The three convolutional layers all have a kernel size of 3, a stride of 1, and a padding of 1, with output channels of 32, 64, and 128 respectively. The average pooling layers all have a kernel size of 2 and a stride of 2. Convolution operations are performed on the spectral curve of each pixel to extract features such as reflectance changes and feature peak positions in the spectral dimension. The branch output is connected to the second input of the dual-branch feature fusion module, and the dimension of the output feature map is completely consistent with that of the spatial feature extraction branch.
[0048] In some specific implementations, the two inputs of the dual-branch feature fusion module are connected to the outputs of two feature extraction branches, respectively. The core operation is to stitch together and fuse spatial and spectral features along the channel dimension. The module's output is connected to the input of the two-dimensional convolutional module. The two-dimensional convolutional module consists of two sets of cascaded two-dimensional convolutional layers, batch normalization layers, and ReLU activation layers. The convolutional kernel size is 3×3, stride 1, and padding 1, with output channels of 256 and 128, respectively. The module's output is simultaneously connected to the input of the pooling module and the first input of the residual connection module. The pooling module uses max pooling layers with a 2×2 kernel size and stride 2. The module's output is simultaneously connected to the second input of the residual connection module and the input of the multi-scale feature extraction module. The residual connection module performs dimensionality matching on the feature maps of the two inputs and then adds them element-wise before outputting to the input of the multi-scale feature extraction module, mitigating the gradient vanishing problem caused by increasing network depth.
[0049] In some specific implementations, the multi-scale feature extraction module sets up three parallel convolutional branches with kernel sizes of 3×3, 5×5, and 7×7, respectively. The inputs to all three branches are the feature maps output from the residual connection module. The outputs are concatenated along the channel dimension to form a multi-scale feature map. The module's output is connected to the input of the channel attention mechanism module. The channel attention mechanism module adopts an SE channel attention structure, generating adaptive channel weights through global pooling and two fully connected layers. These weights are then multiplied channel-by-channel with the original feature map to adjust the weights. The module's output is connected to the input of the feature pyramid network module. The feature pyramid network module generates three feature maps of different resolutions through three convolutional downsampling steps of 2, and then performs multi-scale feature fusion through a 2x upsampling, finally outputting a feature map that fuses multi-scale information. The module's output is connected to the input of the fully connected module.
[0050] In some implementations, the fully connected module consists of two fully connected layers with output dimensions of 256 and 64 respectively. A ReLU activation layer and a Dropout layer with a dropout rate of 0.5 are placed between the two layers to reduce the risk of overfitting. The module's output is connected to the input of the classification output module. The classification output module consists of one fully connected layer and a softmax activation layer. The output dimension of the fully connected layer is the same as the number of classification categories. The softmax activation layer converts the output into a probability value for each category. The module's output is the final output of the model, producing a pixel-level classification probability map with the same spatial dimensions as the input data.
[0051] We set weight initialization rules for the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. All convolutional and fully connected layer weights are initialized using a He normal distribution, bias parameters are initialized to 0, batch normalization layer scaling parameters are initialized to 1, and offset parameters are initialized to 0. We set a multi-scale sliding window for the multi-scale feature extraction module, and perform feature upsampling and downsampling for the feature pyramid network module. Through dual-branch feature extraction, dual-branch module feature fusion, and multi-scale module collection and fusion of multi-scale features, we construct the multi-level feature recognition logic of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model.
[0052] The end-to-end architecture of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model is specifically designed to address the pain points of real-world aflatoxin detection in grains: For the issue of significant differences in seed coat texture and surface morphology among different grain varieties, which can easily interfere with contamination characteristics, the parallel spatial feature extraction branch, through multi-layer convolution operations, adaptively learns to distinguish between the inherent texture features of the grains themselves and the changes in surface texture and light reflection characteristics caused by aflatoxin contamination, eliminating the influence of morphological differences between different grain varieties on the detection results; the spectral feature extraction branch, targeting the characteristic absorption peak of aflatoxin in the near-infrared band, accurately captures subtle changes in the spectral curve caused by contamination through one-dimensional convolution operations, while suppressing the inherent spectral background differences among different grain varieties, thus achieving effective detection of aflatoxin in different grain varieties. Generalized extraction of contamination features: Addressing the issue that aflatoxin contamination in grains is often scattered, localized, and invisible to the naked eye, and easily missed by conventional detection methods, the multi-scale feature extraction module employs three sets of convolutional kernels of different sizes. These kernels respectively capture features of micron-level micro-contamination points, medium-sized contamination areas, and large contiguous contamination areas on grain particles, achieving full coverage identification of contamination areas at different scales. The channel attention mechanism module adaptively amplifies the feature channel weights related to aflatoxin contamination, suppresses irrelevant interference channel weights caused by grain variety, particle morphology, and changes in illumination, and strengthens the focus of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model on the core contamination features, further improving the model's generalization ability and detection accuracy in actual aflatoxin detection scenarios in grains.
[0053] S3.3. Deep Learning Model Initialization and Parameter Configuration: Following the initialization rules described above, all weights, biases, and batch normalization layer parameters of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model are randomly initialized to provide a stable initial state for model training. The model is then configured with a ReLU activation function and a binary cross-entropy loss function. The ReLU activation function is placed after all convolutional and fully connected layers to alleviate the gradient vanishing problem and improve the model's fitting ability. The binary cross-entropy loss function is used to calculate the loss value between the model output and the labeled values, providing a quantitative basis for parameter updates. The training batch size, initial learning rate, and learning rate decay rules are set to determine the maximum number of training epochs and manage the training cycle.
[0054] S3.4. Iterative Training and Parameter Update of Deep Learning Models: The forward propagation operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model is performed using a training subset to pass data features layer by layer. The loss value is calculated using a validation subset. The backward gradient update, gradient clipping and learning rate adjustment of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model are performed round by round. The training early stopping rule is set, and the internal operating parameters and network weights of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model are adjusted. The training and validation process is repeated.
[0055] In some specific implementations, model iterative training is repeated in fixed rounds. Each round of training includes five fixed steps: Forward propagation, where training subset samples are input batch by batch into the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, processed sequentially through network layers, and outputting pixel-level classification probability results, completing the feature propagation layer by layer; Loss calculation, where validation subset samples are input into the current training state of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, the output results are obtained and combined with the labeled values to calculate the validation loss value and training loss value for the current round; Backward gradient update, based on the training loss value, using the backpropagation algorithm to calculate all trainable parameters of the model layer by layer. The gradient values are updated using the Adam optimizer, with the optimizer momentum parameter set to 0.9 and the second moment parameter set to 0.999. In the gradient clipping and learning rate adjustment phase, a maximum norm threshold is set to clip the gradient to avoid gradient explosion. The learning rate is adjusted round by round according to preset rules to improve model convergence accuracy. In the early stopping and parameter adjustment phase, a maximum threshold is set for the number of consecutive validation loss cycles without decreasing. Training is terminated early when the threshold is triggered, and the model weights with the lowest validation loss are saved to avoid overfitting. After each training cycle, the model parameters are fine-tuned based on the validation results. The training and validation process is repeated until the maximum number of training cycles is reached, the validation loss reaches the preset threshold, or the early stopping rule is triggered, completing the iterative training of the model.
[0056] In some specific implementations, a standardized numerical hyperparameter configuration and workflow are executed for the iterative training process of a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. This fully covers the technical aspects of the entire model training process and allows for direct model training and convergence. In this implementation, model weight initialization, activation function and loss function configuration are completed before training, and fixed training hyperparameters are set to ensure stable model convergence without overfitting risk. During training, batch training is strictly implemented, including forward propagation, loss calculation, backpropagation gradient update, and parameter adjustment. Learning rate decay and early stopping control are executed according to rules, and the optimal model weights are saved. The key hyperparameter configuration and implementation rules for model training are shown in Table 3. The trained model can be directly used for the detection of aflatoxin in grains without additional adjustments or optimizations, and the implementation can be directly reproduced.
[0057] Table 3. Model Training Hyperparameter Configuration and Implementation Rules Hyperparameter name Configuration values Adjusting rules core role Training batch size 16 The training process remains unchanged throughout. Controlling the sample size of a single parameter update Initial learning rate 0.001 Multiply by the decay factor every 5 rounds of training. Set the initial step size for model parameter updates. Learning rate decay coefficient 0.95 Exponential decay, dropping to a minimum of 0.00001. Fine-tuning parameters in the later stages of training Early stop cycle threshold 10 If the loss does not decrease after 10 consecutive rounds of verification, the process will terminate. To prevent model overfitting and retain optimal weights Maximum number of training rounds 100 Training is forced to terminate upon reaching a certain number of rounds. Manage the training cycle to avoid ineffective iterations S4. Sample detection and result output: S4.1. Sample preprocessing and data acquisition: The grains to be tested underwent impurity removal and sieving. Vibrating sieving was performed using standard inspection sieves of the same specifications as those used in the training phase to remove impurities such as straw, soil clods, and debris, separating grain particles from surface dust. Clean compressed air was used to clean the surface of the grains, removing fine deposits and preventing obstruction of the particle surface that could lead to undetectable contaminated areas. Using the same placement plane as the training samples, the grains were laid flat, arranged in a single layer, and separated into individual particles. The particle distribution and orientation were adjusted to ensure no overlap, obstruction, or contact, and the plane position was fixed to meet the hyperspectral imaging acquisition conditions. Hyperspectral imaging data was acquired using the same imaging equipment, acquisition parameters, light source settings, and scanning method as the training samples, obtaining three-dimensional hyperspectral imaging data of the grains to ensure complete consistency between the data acquisition conditions and the training data.
[0058] S4.2. Data Processing and Model Inference: The hyperspectral imaging data of the grains to be tested undergoes the same preprocessing, spatiotemporal registration, and feature alignment operations as the training phase, including background signal subtraction, noise removal, bad pixel repair, normalization and centering, effective band selection, and band interval alignment. This ensures that the format, dimensions, and numerical distribution of the test data are completely consistent with the training samples. The processed data can be directly input into the trained hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. The processed test data is then imported into the model's input layer, where the forward propagation inference operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model is executed. The data is processed sequentially through the network layers, and finally, the classification output module outputs the pixel-level classification probability map corresponding to the test data.
[0059] Threshold discrimination is performed on the pixel-level classification results output by the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. A fixed pollution category probability threshold is set. Pixels with a probability value greater than or equal to the threshold are judged as pollution pixels, and those with a probability value less than the threshold are judged as non-pollution pixels, thus completing the binary classification of all pixels. Pixel-by-pixel traversal, feature discrimination, feature vector generation, and feature mapping are performed on the classification results. Region connectivity analysis is performed using the 8-neighborhood connectivity rule to divide adjacent pollution pixels into the same pollution connectivity region. Each independent connectivity region is uniquely numbered and labeled. Scattered classification results are integrated and stitched together according to spatial coordinates to form a complete detection result map, completing spatial coordinate matching and region boundary calibration to ensure that the location of the pollution area is completely matched with the spatial location of the original data.
[0060] Meanwhile, considering the morphological characteristics of grain particles, the spatial features output by the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model are first used during the inference process to identify the physical contour boundaries of the grain particles to be tested. Contamination category discrimination is performed only on pixels within the grain particle body, completely excluding invalid pixels in the background area, significantly reducing false detections caused by background interference. For the spectral feature anomalies caused by light reflection at the edges of grain particles, a secondary discrimination is performed on pixels in the particle edge area, combining the classification probability confidence and spectral feature matching degree output by the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Only when both indicators meet the contamination judgment threshold is the pixel marked as a contaminated pixel, further improving the accuracy of aflatoxin detection results in grains. Consistency verification is performed on the integrated detection results, eliminating isolated single-pixel false detection points. Multiple rounds of inference and repeated verification are performed to ensure stable and repeatable detection results. Finally, the output format of the detection and positioning data information is standardized according to preset specifications.
[0061] S4.3. Standardization of test results and data management: After the testing operation is completed, the testing and positioning data information is standardized and verified. The numerical format, labeling format and storage format of the test results are unified according to the preset output specifications. The converted data is subjected to integrity verification and logical verification to ensure that the data is complete and free of logical errors. The test data that passes the verification is classified, stored and archived according to the grain category, testing time and testing batch. A complete file containing sample information, collection parameters, processing flow and test results is created for each test. Symmetric encryption is performed on the stored data to prevent data from being tampered with or leaked.
[0062] The system performs traceability recording and traceability coding on archived data, fully recording information throughout the entire testing process, including sample source, equipment information, processing parameters, training parameters of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, model version, and testing time. A unique traceability code is generated, consisting of "testing date + category code + batch number + model version number," binding the traceability code to the testing data, the training parameters of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and the entire process traceability record. The traceability code allows for querying the corresponding testing process information. Furthermore, the system establishes output standards and a data traceability system for testing results, clarifying the requirements for outputting testing results and the rules for recording, storing, and querying traceability information. This ensures full traceability of the testing process and guarantees the verifiability and repeatability of the testing results.
[0063] This embodiment achieves comprehensive sample information acquisition by simultaneously obtaining spatial and spectral information from grain samples through standardized acquisition and processing of hyperspectral imaging data. Preprocessing, spatiotemporal registration, and feature alignment operations enable precise matching of spatial and spectral information, eliminating data interference and improving data validity. A dual-branch hyperspectral spatial-spectral feature fusion convolutional neural network deep learning model is constructed to simultaneously extract and fuse spatial and spectral features, achieving effective learning and precise matching of aflatoxin contamination features. Pixel-level analysis enables aflatoxin detection and contamination area localization. This solution achieves standardized execution of the entire detection process through standardized processing, ensuring the stability and accuracy of test results. Data classification management and a full-process traceability system ensure full traceability of the detection process, guaranteeing the integrity and verifiability of test data. An end-to-end deep learning model architecture enables fully automated processing from data input to result output, significantly improving the generalization ability and efficiency of the detection method.
[0064] The above description is merely a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the forms disclosed herein and should not be construed as excluding other embodiments. It can be used in various other combinations, modifications, and environments, and can be altered within the scope of the concept described herein through the above teachings or related technologies or knowledge. Modifications and variations made by those skilled in the art that do not depart from the spirit and scope of the present invention should be within the protection scope of the appended claims.
Claims
1. A method for detecting aflatoxin in grains using hyperspectral imaging combined with deep learning, characterized in that, Includes the following steps: S1. Collect hyperspectral imaging data of grain particles, extract spatial and spectral information from the hyperspectral imaging data, and combine the spatial and spectral information to form basic hyperspectral imaging data; S2. Perform preprocessing operations on the hyperspectral imaging base data, and perform spatiotemporal registration and feature alignment operations on the preprocessed hyperspectral imaging base data; S3. Construct a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Import the processed hyperspectral imaging basic data into the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform iterative training on the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model to enable the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model to complete the learning and matching of aflatoxin contamination features. S4. Collect hyperspectral imaging data of the grains to be tested, perform standard preprocessing on the data, import the trained hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and perform aflatoxin detection and contamination area localization through pixel-level analysis.
2. The method according to claim 1, characterized in that, Step S1 includes: S1.
1. Perform a flat laying operation on the grain particles, perform flattening, leveling and surface cleaning on the laying surface, adjust the distribution and posture of the grain particles, implement a single-layer arrangement of grain particles, separate the grain particles that are in contact with each other, fix the laying surface, remove damaged and irregular grain particles, and keep the grain particles in a non-overlapping and non-obstructing arrangement. S1.
2. Perform light source stabilization control, fixed acquisition parameters and synchronous acquisition of spectral channels on the arranged grain particles, perform full-domain scanning, row-by-row scanning and column-by-column acquisition, perform point-by-point imaging, extract spatial and spectral information from hyperspectral imaging data, perform geometric correction, distortion correction and spatial dimension resampling on spatial information, perform baseline correction, drift correction and spectral dimension smoothing on spectral information, and remove abnormal acquisition data.
3. The method according to claim 1, characterized in that, Step S3 involves building a hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, which includes: S3.
1. Divide the processed hyperspectral imaging base data into training subsets and validation subsets without cross-over. Perform sample shuffling, sample balancing and stratification. Perform pixel-level data annotation on the training subset and validation subset respectively. The annotation content includes aflatoxin contaminated areas and non-contaminated areas. Perform the binding of annotation labels with data samples to establish a one-to-one correspondence between labels and data. S3.
2. Perform random weight initialization on the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, configure the ReLU activation function and cross-entropy loss function of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, set the training batch size, initial learning rate value and learning rate decay rule, use the training subset to perform forward propagation operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, pass data features layer by layer, use the validation subset to perform loss value calculation, perform backward gradient update, gradient clipping and learning rate adjustment of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model round by round, set training early stopping rule, adjust the internal operating parameters and network weights of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and repeat the training and validation process.
4. The method according to claim 1, characterized in that, Step S2 includes: S2.
1. Perform background signal subtraction, background reference value calibration and noise removal on the basic hyperspectral imaging data, perform neighborhood comparison, identify and remove invalid data information, perform neighborhood interpolation repair on bad data points, and identify and remove abnormal values. S2.
2. Perform normalization and centering on the processed hyperspectral imaging base data, perform numerical interval mapping, adjust the data numerical distribution range, perform data bad line repair, bandpass filtering, effective band selection and band interval alignment, complete the dimensional mapping of data spatiotemporal registration and feature alignment, and perform point-by-point matching of spatial information and spectral information corresponding coordinates.
5. The method according to claim 1, characterized in that, Step S4 includes: S4.
1. Perform impurity removal and sieving on the grains to be tested, separate the grains to be tested from surface debris and dust, perform surface cleaning, particle regularization and separation on the grains to be tested, and adjust the arrangement of the grains to be tested so that the grains to be tested meet the data collection conditions; S4.
2. Perform the same preprocessing, spatiotemporal registration, and feature alignment as in the training phase on the hyperspectral imaging data of the grains to be tested. Import the processed data into the trained hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform forward propagation inference operation of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. Perform pixel-by-pixel traversal, feature discrimination, feature vector generation, feature mapping, and region connectivity analysis. Perform pixel-by-pixel softmax classification operation, output pixel-level classification results, and perform connected component labeling.
6. The method according to claim 1, characterized in that, In step S1, the hyperspectral imaging data is classified, deduplicated, and indexed. The hyperspectral imaging data is time-series labeled and encoded. The hyperspectral imaging data is divided according to the grain category. Time-series identifiers are added to the hyperspectral imaging data collected at different times. The classified hyperspectral imaging data set is constructed and grouped for storage.
7. The method according to claim 6, characterized in that, In step S2, feature enhancement, feature filtering, feature vector normalization, and data decorrelation processing are performed on the preprocessed hyperspectral imaging basic data to extract pollution-related feature information from the hyperspectral imaging basic data. Feature dimension matching is performed to make the feature dimension match the input dimension requirements of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model, and redundant correlation information is eliminated to reduce data dimension redundancy.
8. The method according to claim 7, characterized in that, In step S3, the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model is configured with a multi-level network structure. The network structure sequentially includes an input layer, a spatial feature extraction branch, a spectral feature extraction branch, a dual-branch feature fusion module, a two-dimensional convolution module, a pooling module, a residual connection module, a multi-scale feature extraction module, a channel attention mechanism module, a feature pyramid network module, a fully connected module, and a classification output module. The spatial feature extraction branch and the spectral feature extraction branch are connected in parallel to the output of the input layer. The dual-branch feature fusion module is connected to the outputs of both the spatial and spectral feature extraction branches. The two-dimensional convolution module is connected to the output of the dual-branch feature fusion module. The pooling module is connected to the output of the two-dimensional convolution module. The residual connection module is connected to the input of the two-dimensional convolution module and the output of the pooling module. The multi-scale feature extraction module is connected to the output of the pooling module. At the output end, the channel attention mechanism module is connected to the output end of the multi-scale feature extraction module, the feature pyramid network module is connected to the output end of the channel attention mechanism module, the fully connected module is connected to the output end of the feature pyramid network module, and the classification output module is connected to the output end of the fully connected module. The weight initialization rules for the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model are set. A multi-scale sliding window is set for the multi-scale feature extraction module, and feature upsampling and downsampling are performed on the feature pyramid network module. Spatial and spectral feature information are extracted through the spatial feature extraction branch and the spectral feature extraction branch, respectively. Feature splicing and fusion are performed through the dual-branch feature fusion module. Pollution features at different scales are collected through the multi-scale feature extraction module, and multi-scale feature fusion is performed. This constructs the multi-level feature recognition logic of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model.
9. The method according to claim 8, characterized in that, In step S4, threshold discrimination is performed on the pixel-level classification results output by the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model. The scattered data generated by pixel-level analysis is integrated, spatial coordinate matching and regional boundary calibration are performed. Consistency verification and duplication verification are performed on the integrated data, and the output format of the detection and positioning data information is standardized.
10. The method according to claim 1, characterized in that, After step S4 is completed, the detection and positioning data information is standardized and verified. The converted detection and positioning data information is classified, archived, and encrypted. The archived data is traced back and traced back codes are generated. The traced back codes are bound to the detection data and the training parameters of the hyperspectral spatial-spectral dual-branch feature fusion convolutional neural network deep learning model to establish the output standard of the detection results and the data traceability system.
Citation Information
Patent Citations
Hyperspectral image classification method for lightweight depth separable convolution feature fusion network
CN111695469A
Multi-source teacher distillation and entropy reduction distribution platform system for fruit disease detection
CN119338805A
Seed screening method and system based on laser radar technology
CN120984586A
Cited By
Grain detection device and detection method
CN121995016A
A leek pesticide residue detection method combining hyperspectral imaging and deep learning
CN122415628B