A method, system, and computer equipment for detecting and classifying hyperspectral anomalies in Chinese medicinal materials.
By combining three-dimensional convolutional neural networks with self-attention and neighborhood self-supervised learning, the problems of insufficient spatial texture characterization and missing neighborhood information in the detection of hyperspectral anomalies in Chinese medicinal materials are solved. Robust automatic identification and accurate segmentation of abnormal regions in Chinese medicinal materials are achieved, improving detection accuracy and system practicality.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINA JILIANG UNIV
- Filing Date
- 2026-04-14
- Publication Date
- 2026-06-02
AI Technical Summary
Existing hyperspectral anomaly detection technologies for Chinese medicinal materials have limitations such as failing to fully capture diverse spatial texture features with large scale differences, lacking the ability to learn band importance, ignoring the spectral similarity between neighboring patches in traditional patch extraction methods, being time-consuming and costly in data annotation, and having a large computational load for model inference, making real-time deployment difficult.
By employing a three-dimensional convolutional neural network combined with a spectral band self-attention mechanism and a neighborhood self-supervised aggregation attention network, robust automatic identification and accurate segmentation of abnormal regions in Chinese medicinal materials are achieved through multi-scale spatial spectrum fusion, band self-attention mechanism and neighborhood self-supervised learning, thus constructing an end-to-end automated classification process.
It enables efficient, accurate, and automated detection of abnormal areas in Chinese medicinal materials, improving detection quality and system practical value, and adapting to industrial deployment environments.
Smart Images

Figure CN122135115A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of Chinese medicinal material testing, and in particular to a method, system, and computer equipment for detecting and classifying hyperspectral anomalies in Chinese medicinal materials. Background Technology
[0002] While current mainstream technologies for hyperspectral anomaly detection in Chinese medicinal materials have achieved a certain degree of quality assessment, they still have many limitations in practical applications, mainly in the following aspects: Existing methods generally rely on gradient operators of a single spatial scale (such as Sobel and Canny) for foreground anomaly detection, which cannot fully capture the diverse spatial texture features with large scale differences in anomalies such as mold and insect infestation. This leads to missed or false detections of some small or marginal anomalies, reducing the overall detection accuracy. Commonly used empirical bands are fixed and selected, ignoring the differences in spectral band sensitivity between different samples and under different anomaly states. 3D convolutional networks lack the ability to learn band importance and are insufficient in responding to key spectral features, affecting classification performance and generalization ability. Traditional patch extraction and training methods treat each patch as an isolated sample, ignoring the spectral similarity and spatial semantic continuity between spatially neighboring patches, making it difficult to accurately capture the overall connectivity and morphological structure of anomaly regions, leading to confusion of classification boundaries and error accumulation. Currently, the system training process requires a large amount of manual annotation of anomaly and normal samples, which is time-consuming, costly, and prone to errors. This limits the expansion of the dataset and continuous model optimization. Furthermore, the initial foreground segmentation based on fixed thresholds and empirical sampling is cumbersome, lacking the end-to-end automated processing capabilities of a unified platform. Model inference requires a large amount of computation, making it difficult to deploy quickly in real-time or edge environments. Summary of the Invention
[0003] The purpose of this invention is to provide a method for hyperspectral anomaly detection and 3D convolutional neural network classification of Chinese medicinal materials. Combining a spectral band self-attention mechanism and a neighborhood self-supervised aggregation attention network, it addresses the problems of insufficient spatial texture characterization, limited utilization of spectral information, and lack of neighborhood context information in existing technologies. This achieves: robust automatic identification and accurate segmentation of multi-scale, multi-morphological anomaly regions in Chinese medicinal materials; dynamic adaptive spectral band weight allocation to improve feature representation and classification accuracy; label-free self-supervised learning using spatial spectral neighborhood relationships to enhance the ability to resolve anomaly spatial continuity and reduce the need for manual annotation; and the construction of an end-to-end automated 3D patch sampling and classification process to optimize training and inference efficiency and adapt to industrial deployment environments. In summary, this invention aims to overcome the technical bottlenecks of existing hyperspectral anomaly detection methods, realizing a new, efficient, accurate, and automated method for detecting mold and insect infestation in Chinese medicinal materials, significantly improving detection quality and system practical value.
[0004] To achieve the above objectives, this invention provides a method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials, comprising the following steps: Step 1: Read the hyperspectral data and use a multi-scale spatial spectrum fusion method to detect the foreground of the hyperspectral data to obtain the foreground mask of the abnormal region; Step 2: Automatically sample N three-dimensional patches for the foreground mask region using 3D patches; Step 3: Set up a three-dimensional convolutional neural network with a band self-attention mechanism, input the foreground mask and the three-dimensional patch array into the neural network to generate high-level semantic feature vectors; Step 4: The high-level semantic feature vectors are fed into the first branch network and the second branch network respectively. The first branch network is used to constrain the backbone network to retain spatial edge and local texture structure information. The second branch network is equipped with a self-supervised aggregation attention module based on neighborhood spatial spectrum, and finally outputs the classification result.
[0005] Preferably, the process involves reading hyperspectral data and performing foreground detection using a multi-scale spatial spectral fusion method to obtain anomaly region foreground masks, including the following steps: For the two-dimensional spatial image of each band in the hyperspectral data, the Sobel operator is applied at three different scales to calculate the horizontal and vertical gradients and obtain the multi-scale spatial gradient field. By combining the local spectral entropy at the corresponding scale as weights, the multi-scale gradients are weighted and fused to obtain a comprehensive gradient response map; The threshold of the integrated gradient response map is adaptively calculated, and the image is binarized to generate preliminary edge detection results; Morphological closing operations are performed using disk-shaped structural elements to fill edge gaps. Finally, connected component analysis is used to remove isolated small regions, ultimately generating a foreground mask for abnormal regions.
[0006] Preferably, the method involves automatically sampling three-dimensional patches to collect an array of N three-dimensional patches for the foreground mask region, including the following steps: Set the patch size, and cover all bands in the band dimension to form a three-dimensional patch. Perform sliding sampling along the Y and X axes in the spatial dimension to collect effective patches centered at point (y,x) within the mask area. Collect according to the set mask value, and finally output N three-dimensional patch arrays.
[0007] Preferably, a three-dimensional convolutional neural network with a band self-attention mechanism is used to generate high-level semantic feature vectors by inputting a foreground mask and a three-dimensional patch array into the neural network, including the following steps: N three-dimensional patch arrays are input into the band self-attention module, and global average pooling is performed along the spatial and batch dimensions to obtain shape features; The first shape feature is passed through two fully connected network layers, hidden layers, and activation functions. The output layer uses Sigmoid to obtain the weight coefficients for the entire band. The weight tensor is multiplied element-wise with the corresponding band of the input patch to complete the weighting of the band features and obtain the weighted features. The weighted features are extracted through multiple stages of convolution. During convolution extraction, the spectral dimension is compressed layer by layer while maintaining the spatial resolution, thus achieving joint spatial-spectral feature encoding. The output features are then subjected to adaptive global average pooling and flattened, serving as the high-level semantic feature vector extracted by the three-dimensional convolution backbone.
[0008] Preferably, the first branch network includes multiple 3D deconvolution layers or upsampling modules to gradually restore the spatial resolution to the original patch size and output a single-channel patch spatial gradient prediction map; The mean squared error of the predicted gradient map is compared with that of the Sobel gradient map calculated based on the original patch. A spatial structure reconstruction auxiliary loss function is constructed to constrain the backbone network to retain spatial edge and local texture structure information. The final training loss is a weighted mixture of the main classification cross-entropy loss and the gradient reconstruction loss according to a preset weight coefficient.
[0009] Preferably, the second branch network includes a self-supervised aggregation attention module based on neighborhood spatial spectrum, which ultimately outputs classification results, specifically including: Based on the N three-dimensional Patch arrays recorded in step 2, construct the adjacency relationship and define the nine-square grid neighborhood structure in space; Using the high-level semantic feature vectors extracted in step 3, we calculate the cosine similarity between neighborhood patches based on spectral feature vectors and construct a weighted adjacency matrix. A graph neural network model is constructed based on the weighted adjacency matrix. The graph neural network model adopts a graph attention network structure, which includes a multi-layer multi-head attention mechanism for weighted aggregation of neighborhood patch features. A self-supervised contrastive learning strategy is introduced to make the feature embeddings of the same category of patches in the neighborhood closer in the feature space, and the feature embeddings of different categories of patches farther apart, so as to enhance the feature discrimination ability and spatial continuity modeling ability. Finally, the neighborhood aggregation features output by the graph network are concatenated or weighted and fused with the high-level semantic feature vector output by the three-dimensional convolutional neural network described in step 3, and then input together into the final classification layer for category prediction and judgment to obtain the classification result.
[0010] A hyperspectral anomaly detection and classification system for traditional Chinese medicinal materials includes: The mask generation unit is used to read hyperspectral data and perform foreground detection on the hyperspectral data using a multi-scale spatial spectrum fusion method to obtain the foreground mask of the abnormal region. An automatic sampling unit is used to automatically sample N three-dimensional patch arrays of the foreground mask region through three-dimensional patch sampling. The convolutional unit is used to set up a three-dimensional convolutional neural network with a band self-attention mechanism. It inputs the foreground mask and the three-dimensional patch array into the neural network to generate high-level semantic feature vectors. Auxiliary loss units are used to constrain the backbone network to retain spatial edge and local texture structure information; The self-supervised unit outputs the classification result by aggregating the attention module based on the neighborhood spatial spectrum.
[0011] A computer device includes a memory and a processor; the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described.
[0012] Therefore, the present invention employs the above-mentioned method, system, and computer equipment for the detection and classification of hyperspectral anomalies in traditional Chinese medicinal materials, and the technical effects are as follows: Adaptive and precise segmentation of complex and anomalous regions in spectral data improves the robustness and integrity of foreground masks.
[0013] A 3D automatic patching algorithm based on spatial-spectral joint masking: Automatic sliding window sampling of anomalous regions in hyperspectral data avoids subjective experience sampling and improves the effectiveness of training samples and data utilization.
[0014] A 3D convolutional neural network structure integrating band self-attention mechanism: realizes dynamic weight allocation of features of different wavelength bands, enhances the model's ability to focus on and respond to key bands, and improves classification accuracy.
[0015] Multi-task learning design for spatial structure reconstruction auxiliary tasks: Gradient maps and spatial texture reconstruction are used as auxiliary supervision to enhance the network's expression of local spatial abnormal textures and improve the model's fine-grained recognition ability.
[0016] Neighborhood spatial spectrum self-supervised aggregation attention mechanism: Based on the construction of spectral similarity graphs of the Patch neighborhood, graph neural networks and contrastive learning are used to achieve label-free spatial spectrum aggregation, which enhances the spatial continuity recognition and classification stability of abnormal regions.
[0017] End-to-end automated hyperspectral anomaly detection deep learning framework: Combining all the key technologies mentioned above, it forms a closed loop from data preprocessing and automatic sampling to multi-task deep classification, and has good automation and practical deployment value. Attached Figure Description
[0018] Figure 1 System flowchart; Figure 2This is a schematic diagram of multi-scale spatial-spectral foreground detection and patch sampling; Figure 3 This is a diagram of the architecture of a band-based self-attention 3DCNN and a multi-task graph network. Detailed Implementation
[0019] The technical solution of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0020] Unless otherwise defined, the technical or scientific terms used in this invention shall have the ordinary meaning as understood by one of ordinary skill in the art to which this invention pertains.
[0021] Example 1 like Figure 1 As shown, a method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials includes the following steps: Step 1: Hyperspectral data acquisition and multi-scale spatial spectrum joint foreground detection The network directly reads hyperspectral reflectance data that has not been preprocessed by traditional ENVI software through this structure, and uses a multi-scale spatial spectrum fusion method to achieve accurate and automatic generation of foreground masks for anomalous regions (such as mold and insect infestation).
[0022] Specifically: The input data is the original spectral cube, with dimensions of band number (B=256) × height (H=496) × width (W=320), and the data format is a floating-point 32 or 64-bit reflectance array; for the two-dimensional spatial image of each band, the Sobel operator is applied at three different scales (convolution kernel sizes of 3×3, 5×5, and 7×7) to calculate the horizontal and vertical gradients, obtaining a multi-scale spatial gradient field; combined with the local spectral entropy at the corresponding scale as weights, the multi-scale gradients are weighted and fused to obtain a comprehensive gradient response map; the 80th percentile threshold of this comprehensive gradient response map is adaptively calculated, and the image is binarized to generate preliminary edge detection results; to ensure foreground continuity and spatial structure integrity, a disk-shaped structuring element with a radius of 5 pixels is used for morphological closing operations to fill edge gaps; finally, connected component analysis is used to remove isolated small regions with an area of less than 1200 pixels, ultimately generating a high-quality foreground mask for abnormal regions.
[0023] Innovations: It avoids the drawbacks of traditional single-scale, single-band empirical threshold selection and can effectively cover multi-morphological anomaly regions; it realizes the linkage between hyperspectral spatial and spectral dimensional information, improving the accuracy of anomaly texture detail recognition.
[0024] Step 2: Automatic sampling of 3D patches based on foreground mask Based on the foreground mask generated in step 1, the network uses this structure to achieve automated and uniform acquisition of 3D patches in anomalous regions of full-band hyperspectral data.
[0025] Specifically: The patch size is set to 9×9 (spatial window), and the band dimension covers all 256 bands, forming a three-dimensional patch (256×9×9). Sampling is performed along the Y (height) and X (width) axes in the spatial dimension with a step size of 4, acquiring valid patches centered at points (y,x) within the masked area. Only the center patch with a mask value of 1 is acquired to avoid the inclusion of invalid background data. Patches that cannot be completely cut at the boundaries are discarded to ensure that all patches have uniform shape and complete data. Finally, N three-dimensional patch arrays of shape (N, 256, 9, 9) are output for model training. Multi-scale spatial-spectral foreground detection and patch sampling are as follows: Figure 2 As shown.
[0026] Innovation: It realizes a data-driven automatic patching process, reduces manual intervention to optimize sampling strategies, and improves the relevance of training samples and data utilization.
[0027] Step 3: Design a three-dimensional convolutional neural network (3DCNN) with a band self-attention mechanism. This step constructs a backbone network structure for deep feature extraction of 3D hyperspectral patches. By introducing a band self-attention mechanism, dynamic weighted modeling of the spectral dimension is achieved, enhancing the ability to express key band information and improving classification accuracy.
[0028] Specifically: the network input size is set to B×1×256×9×9; the SpectralAttentionModule (SAM) input is set to (B,1,256,9,9); global average pooling is performed along the spatial (9×9) and batch dimensions to obtain the shape (B,1,256,1,1); after passing through two fully connected layers, the hidden layer has 64 channels, the activation function is ReLU, and the output layer uses Sigmoid to obtain the weight coefficients of 256 bands; the weight tensor is multiplied element-wise with the corresponding band of the input Patch to complete the band feature weighting; the band-weighted features are input into a three-dimensional convolutional coding network, and the convolutional coding structure features are shown in Table 1. This structure compresses the spectral dimension layer by layer while maintaining the spatial resolution, realizing spatial-spectral joint feature encoding. The Conv3d_3 output features are adaptively global average pooled and flattened to (B,64), which is used as the high-level semantic feature vector extracted by the three-dimensional convolutional backbone and output to step 4 for further enhancement modeling.
[0029] Table 1. Convolutional coding structure features
[0030] Step 4: Design of a spatial structure reconstruction-assisted multi-task learning module and a self-supervised aggregation attention module based on neighborhood spatial spectrum The structure enhances the sensitivity of the feature extraction network to local spatial textures by adding auxiliary reconstruction tasks, improves the fine-grained performance of anomaly detection, and enhances the modeling of spatial and spectral continuity between patches, thereby improving the connectivity recognition capability of the entire anomaly region.
[0031] Specifically: From the output features (B,64,32,9,9) of the third convolutional block (Conv3d_3), an auxiliary branch network is established. This auxiliary branch consists of several 3D deconvolutional layers or upsampling modules, gradually restoring the spatial resolution to the original patch size of 9×9, and outputting a single-channel patch spatial gradient prediction map. The predicted gradient map is compared with the Sobel gradient map calculated based on the original patch, and a spatial structure reconstruction auxiliary loss function is constructed to constrain the backbone network to retain spatial edge and local texture structure information. The final training loss is a weighted mixture of the main classification cross-entropy loss and the gradient reconstruction loss according to preset weight coefficients.
[0032] Further, adjacency relationships are constructed based on the Patch spatial sampling coordinates recorded in step 2, defining a nine-square grid neighborhood structure in space; using the high-dimensional feature vectors of the Patch extracted in step 3, the cosine similarity between neighboring Patches based on spectral feature vectors is calculated, and a weighted adjacency matrix is constructed; a graph neural network model is constructed based on the adjacency matrix, the model adopts a graph attention network (GAT) structure, containing a two-layer multi-head attention mechanism, with each attention head having a hidden dimension of 64, used for weighted aggregation of neighboring Patch features.
[0033] Furthermore, a self-supervised contrastive learning strategy is introduced to make the feature embeddings of similar-category patches within the neighborhood closer together in the feature space, while the feature embeddings of different-category patches are further apart, thereby enhancing feature discrimination ability and spatial continuity modeling ability. Finally, the neighborhood aggregation features output by the graph network are concatenated or weighted and fused with the output features of the 3DCNN backbone network described in step 3, and then input together into the final classification layer for category prediction. The overall architecture of the band self-attention 3DCNN and the multi-task graph neural network is as follows: Figure 3 As shown.
[0034] Step 5: Overall End-to-End Training and Inference Training strategy: The Adam optimizer is used with an initial learning rate of 1e-3, combined with a learning rate decay strategy. The loss function is a weighted sum of the cross-entropy loss for classification and the mean squared error loss for spatial reconstruction. Training uses a batch size of 256 and a training period of 30 epochs. Input data preprocessing: Each band within a patch is normalized to zero mean and unit variance, combined with data augmentation such as random spectral perturbations and spatial smoothing. Inference and deployment: Supports multi-platform GPU acceleration (NVIDIA CUDA) and complies with mainstream frameworks such as PyTorch or TensorFlow. Lightweight module design facilitates deployment on edge devices and real-time processing.
[0035] An embodiment of the present invention provides a terminal device. This terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps in the various method embodiments described above. Alternatively, when the processor executes the computer program, it implements the functions of each module / unit in the various device embodiments described above.
[0036] The computer program can be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention.
[0037] The terminal device may be a desktop computer, laptop, handheld computer, or cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.
[0038] The processor can be a central processing unit (CPU), a graphics processing unit (GPU), or other general-purpose processors.
[0039] The memory can be used to store the computer program and / or module. The processor implements various functions of the terminal device by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory.
[0040] If the modules / units integrated into the terminal device are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0041] Therefore, the present invention employs the above-mentioned hyperspectral anomaly detection and classification method, system and computer equipment for Chinese medicinal materials to realize a new method for detecting mold and insect infestation in Chinese medicinal materials that is efficient, accurate and automated, significantly improving the detection quality and the practical value of the system.
[0042] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials, characterized in that, Includes the following steps: Step 1: Read the hyperspectral data and use a multi-scale spatial spectrum fusion method to detect the foreground of the hyperspectral data to obtain the foreground mask of the abnormal region; Step 2: Automatically sample N three-dimensional patches for the foreground mask region using 3D patches; Step 3: Set up a three-dimensional convolutional neural network with a band self-attention mechanism, input the foreground mask and the three-dimensional patch array into the neural network to generate high-level semantic feature vectors; Step 4: The high-level semantic feature vectors are fed into the first branch network and the second branch network respectively. The first branch network is used to constrain the backbone network to retain spatial edge and local texture structure information. The second branch network is equipped with a self-supervised aggregation attention module based on neighborhood spatial spectrum, and finally outputs the classification result.
2. The method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials according to claim 1, characterized in that, Read hyperspectral data, perform foreground detection using a multi-scale spatial spectral fusion method, and obtain foreground masks for anomalous regions. This includes the following steps: For the two-dimensional spatial image of each band in the hyperspectral data, the Sobel operator is applied at three different scales to calculate the horizontal and vertical gradients and obtain the multi-scale spatial gradient field. By combining the local spectral entropy at the corresponding scale as weights, the multi-scale gradients are weighted and fused to obtain a comprehensive gradient response map; The threshold of the integrated gradient response map is adaptively calculated, and the image is binarized to generate preliminary edge detection results; Morphological closing operations are performed using disk-shaped structural elements to fill edge gaps. Finally, connected component analysis is used to remove isolated small regions, ultimately generating a foreground mask for abnormal regions.
3. The method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials according to claim 1, characterized in that, Automatic sampling using 3D patches acquires an array of N 3D patches for the foreground mask region, including the following steps: Set the patch size, and cover all bands in the band dimension to form a three-dimensional patch. Perform sliding sampling along the Y and X axes in the spatial dimension to collect effective patches centered at point (y,x) within the mask area. Collect according to the set mask value, and finally output N three-dimensional patch arrays.
4. The method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials according to claim 1, characterized in that, A 3D convolutional neural network with a band self-attention mechanism is set up. The foreground mask and a 3D patch array are input into the neural network to generate high-level semantic feature vectors, including the following steps: N three-dimensional patch arrays are input into the band self-attention module, and global average pooling is performed along the spatial and batch dimensions to obtain shape features; The first shape feature is passed through two fully connected network layers, hidden layers, and activation functions. The output layer uses Sigmoid to obtain the weight coefficients for the entire band. The weight tensor is multiplied element-wise with the corresponding band of the input patch to complete the weighting of the band features and obtain the weighted features. The weighted features are extracted through multiple stages of convolution. During convolution extraction, the spectral dimension is compressed layer by layer while maintaining the spatial resolution, thus achieving joint spatial-spectral feature encoding. The output features are then subjected to adaptive global average pooling and flattened, serving as the high-level semantic feature vector extracted by the three-dimensional convolution backbone.
5. The method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials according to claim 1, characterized in that, The first branch network includes multiple 3D deconvolution layers or upsampling modules, which gradually restore the spatial resolution to the original patch size and output a single-channel patch spatial gradient prediction map. The mean squared error of the predicted gradient map is compared with that of the Sobel gradient map calculated based on the original patch. A spatial structure reconstruction auxiliary loss function is constructed to constrain the backbone network to retain spatial edge and local texture structure information. The final training loss is a weighted mixture of the main classification cross-entropy loss and the gradient reconstruction loss according to a preset weight coefficient.
6. The method for detecting and classifying hyperspectral anomalies in traditional Chinese medicinal materials according to claim 1, characterized in that, The second branch network includes a self-supervised aggregation attention module based on neighborhood spatial spectrum, which ultimately outputs classification results, specifically including: Based on the N three-dimensional Patch arrays recorded in step 2, construct the adjacency relationship and define the nine-square grid neighborhood structure in space; Using the high-level semantic feature vectors extracted in step 3, we calculate the cosine similarity between neighborhood patches based on spectral feature vectors and construct a weighted adjacency matrix. A graph neural network model is constructed based on the weighted adjacency matrix. The graph neural network model adopts a graph attention network structure, which includes a multi-layer multi-head attention mechanism for weighted aggregation of neighborhood patch features. A self-supervised contrastive learning strategy is introduced to make the feature embeddings of the same category of patches in the neighborhood closer in the feature space, and the feature embeddings of different categories of patches farther apart, so as to enhance the feature discrimination ability and spatial continuity modeling ability. Finally, the neighborhood aggregation features output by the graph network and the high-level semantic feature vector output by the three-dimensional convolutional neural network are concatenated or weighted and fused together, and then input into the final classification layer for category prediction and judgment to obtain the classification result.
7. A hyperspectral anomaly detection and classification system for traditional Chinese medicinal materials, characterized in that, include: The mask generation unit is used to read hyperspectral data and perform foreground detection on the hyperspectral data using a multi-scale spatial spectrum fusion method to obtain the foreground mask of the abnormal region. An automatic sampling unit is used to automatically sample N three-dimensional patch arrays of the foreground mask region through three-dimensional patch sampling. The convolutional unit is used to set up a three-dimensional convolutional neural network with a band self-attention mechanism. It inputs the foreground mask and the three-dimensional patch array into the neural network to generate high-level semantic feature vectors. Auxiliary loss units are used to constrain the backbone network to retain spatial edge and local texture structure information; The self-supervised unit outputs the classification result by aggregating the attention module based on the neighborhood spatial spectrum.
8. A computer device, characterized in that, It includes a memory and a processor; the memory stores a computer program, characterized in that the processor executes the computer program to implement the steps of the method as described in any one of claims 1-6.