A method, apparatus, electronic equipment and medium for building an explosive detection model
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-20
- Publication Date
- 2026-08-14
AI Technical Summary
[0005]本发明的目的在于克服上述技术不足,提出一种爆炸物检测模型搭建方法,解决现有技术中爆炸物检测模型的识别准确率低和抗干扰能力弱的技术问题
[0016]与现有技术相比,本发明提供的爆炸物检测模型搭建方法,通过预处理的SERS光谱数据搭建并训练ECNN模型,利用模型的特征提取、特征选择与特征分类能力,有效捕捉不同宽度特征峰并保留核心特征;结合交叉熵-对比联合损失函数,使类内特征距离缩小至0.1以下,显著增强了同类样本的特征聚集程度,提升了爆炸物检测的准确率和抗干扰能力。
Smart Images

Figure CN122567631A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of explosive detection technology, specifically to a method, apparatus, electronic device, and medium for building an explosive detection model. Background Technology
[0002] Traditional explosives detection methods, such as gas chromatography-mass spectrometry (GC-MS) and ion mobility spectrometry (IMP), while possessing a certain level of accuracy, have significant limitations. First, the detection cycle is long, requiring several minutes to tens of minutes per test, which cannot meet the immediate response needs of emergencies. Second, the equipment lacks portability, often consisting of large laboratory equipment that is bulky and heavy, making it difficult to deploy in mobile scenarios such as border patrols and temporary security checkpoints. Third, the operation threshold is high, requiring specialized technicians to master instrument debugging and data interpretation skills, which makes it difficult for grassroots security personnel to quickly learn and apply the technology, limiting its widespread adoption.
[0003] Surface-enhanced Raman scattering (SERS) can accurately match the molecular structure of explosives and detect nanogram-level trace samples, providing core technical support for the trace analysis of explosives. SERS spectral analysis combined with machine learning algorithms can achieve automatic feature extraction.
[0004] However, current detection models still have the following problems: traditional convolutional neural networks (CNN), support vector machines (SVM), and other models cannot detect the weak features specific to explosives in the SERS spectrum (such as TNT at 1360 cm⁻¹). -1 The weak peak at 1280 cm⁻¹, PA at 1280 cm⁻¹ -1 The wide peak at the location has limited mining capabilities, is prone to misjudging noise as a valid feature, and is susceptible to clean environments, resulting in weak anti-interference capabilities. Summary of the Invention
[0005] The purpose of this invention is to overcome the above-mentioned technical deficiencies and propose a method for building an explosive detection model, thereby solving the technical problems of low recognition accuracy and weak anti-interference ability of existing explosive detection models.
[0006] To achieve the above-mentioned technical objectives, the present invention adopts the following technical solution: In a first aspect, the present invention provides a method for building an explosive detection model, comprising the following steps: Obtain SERS spectral data of the explosive; The SERS spectral data of the explosive are preprocessed to obtain a spectral sample set. The preprocessing includes at least data cleaning, normalization and data augmentation. An ECNN model is constructed, wherein the ECNN model includes a feature extraction network, a feature selection network, and a feature classification network connected in sequence; The ECNN model is optimized based on a spectral sample set and a pre-defined cross-entropy-contrast joint loss function, and trained using a pre-defined Adam optimizer; and Output a trained ECNN model that meets the preset accuracy.
[0007] In some embodiments, the preprocessing of the SERS spectral data of the explosive includes: Clean the SERS spectral data and remove outliers; The SERS spectral data were normalized, and the Raman intensity values were mapped to the 0-1 range to eliminate the interference of intensity differences between samples. The training set is augmented with data augmentation, including adding Gaussian noise with a standard deviation of 0.01-0.03, random wavenumber shift of ±2 wavenumbers, and random intensity scaling of 0.8-1.2 times to improve the model's generalization ability. The processed data is divided into training set samples and test set samples according to the proportion.
[0008] In some embodiments, the feature extraction network comprises three blocks, each block comprising at least sequentially connected convolutional layers, The feature extraction method of the feature extraction network includes activation functions and pooling layers. Input a spectral sample set with dimensions of 3×100×1045; The spectral sample set is processed by convolution, ReLU and pooling in the first block to obtain the first feature sequence; The first feature sequence is input into the second block, and after convolution and ReLU, it is added to the first feature sequence through residual connection, and then pooled to obtain the second feature sequence. The second feature sequence is input into the third block, and after convolution and ReLU, it is added to the second feature sequence through residual connection, and then pooled to obtain the feature vector; The output is a feature vector with dimensions of 1×256×16.
[0009] In some embodiments, the feature selection network includes a flattened layer and at least one fully connected layer connected in sequence, and the feature selection method of the feature selection network includes: Input the feature vector output by the feature extraction network; The feature vector is input into the flattening layer, and the intermediate feature sequence is obtained through the flattening operation. The intermediate feature sequence is input into a fully connected layer to calculate the core feature vector; The output is a core feature vector with a dimension of 1×256.
[0010] In some embodiments, the feature classification network includes a first fully connected layer, a second fully connected layer, and a softmax output layer connected in sequence, and the feature classification method of the feature classification network includes: The input feature selection network outputs the core feature vector; The core feature vector is input into the first fully connected layer, processed by the first fully connected layer to obtain 64-dimensional features, and then connected to the activation function; The activated 64-dimensional features are input into the second fully connected layer, and after processing by the second fully connected layer, a 3-dimensional output is obtained, corresponding to the three explosive categories. The output of the second fully connected layer is input into the softmax output layer and converted into prediction probabilities for each category, resulting in a 1×3 probability vector. The category corresponding to the highest probability is taken as the prediction result for the sample.
[0011] In some embodiments, the cross-entropy-contrast joint loss function is: ; in, For the total loss, For cross-entropy loss, To compare the losses, To compare the loss weighting coefficients.
[0012] In some embodiments, the cross-entropy loss is calculated using the following formula: ; in, The number of training samples. For cross-entropy, For the true labels of the samples, Predict probability vectors for the model; The comparison loss calculation steps include: Cosine similarity is used to measure the similarity of sample feature vectors. The formula is: ; in, , These are the core feature vectors of the two samples. ∈[-1,1]; For each anchor sample A, select one sample W of the same class and K samples of different classes to construct a comparison sample pair; The formula for the contrastive loss of a single anchor point sample is: ; in, The core feature vector of anchor sample A. This is the core feature vector of the positive sample W. Let t be the core feature vector of the k-th negative sample, and t be the temperature parameter. The contrast loss for a single anchor point sample; The total contrastive loss is the sum of the losses of all anchor point samples, and the formula is: ; in, To compare the total losses, The contrast loss for a single anchor point sample. This represents the number of training samples.
[0013] Secondly, the present invention also provides an explosive detection model building device, comprising: The spectral data acquisition module is used to acquire the SERS spectral data of explosives; The data processing module is used to preprocess the SERS spectral data of the explosive to obtain a spectral sample set. The preprocessing includes at least data cleaning, normalization and data augmentation. The model building module is used to build an ECNN model, wherein the ECNN model includes a feature extraction network, a feature selection network and a feature classification network connected in sequence; The model training module is used to optimize the ECNN model based on the spectral sample set and a preset cross-entropy-contrast joint loss function, and to train the ECNN model using a preset Adam optimizer; and The model output module is used to output the trained ECNN model that meets the preset accuracy.
[0014] Thirdly, the present invention also provides an electronic device, comprising: a processor and a memory; The memory stores computer programs that can be executed by the processor; When the processor executes the computer program, it implements the steps of the explosive detection model building method as described in any of the above.
[0015] Fourthly, the present invention also provides a computer-readable storage medium storing computer program instructions, which, when executed by a processor, implement the explosive detection model building method as described in any of the above.
[0016] Compared with existing technologies, the explosive detection model building method provided by this invention builds and trains an ECNN model using preprocessed SERS spectral data. By utilizing the model's feature extraction, feature selection, and feature classification capabilities, it effectively captures feature peaks of different widths and retains core features. Combined with the cross-entropy-contrast joint loss function, it reduces the intra-class feature distance to below 0.1, significantly enhancing the feature aggregation degree of similar samples and improving the accuracy and anti-interference ability of explosive detection. Attached Figure Description
[0017] Figure 1 This is a flowchart of the explosive detection model building method provided in the embodiments of the present invention; Figure 2 This is a flowchart of the preprocessing of SERS spectral data of the explosive provided in an embodiment of the present invention; Figure 3 This is a flowchart of the feature extraction method of the feature extraction network provided in the embodiments of the present invention; Figure 4 This is a flowchart of the feature selection method of the feature selection network provided in the embodiments of the present invention; Figure 5 This is a flowchart of the feature classification method of the feature classification network provided in the embodiments of the present invention; Figure 6 This is a structural block diagram of the explosive detection model building device provided in the embodiments of the present invention; Figure 7 This is a structural block diagram of the electronic device provided in the embodiments of the present invention; Figure 8 This is a schematic diagram of the structure of the SERS fiber optic sensing platform provided in an embodiment of the present invention; Figure 9 These are the SERS spectra of three types of explosives, TNT, PA, and Tetryl, provided in the embodiments of the present invention. Figure 10 This is a diagram showing the partitioning results of the explosive spectrum (a) training set and (b) test set provided in an embodiment of the present invention; Figure 11 This is a diagram showing the partitioning results of the specific test dataset provided in an embodiment of the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0019] To address the technical problems of low accuracy and weak anti-interference ability in explosive detection models, this invention provides a method for building an explosive detection model. This method enables the construction and training of an ECNN model using preprocessed SERS spectral data. Utilizing the model's feature extraction, feature selection, and feature classification capabilities, it effectively captures feature peaks of varying widths while retaining core features. By combining a cross-entropy-contrast joint loss function, the intra-class feature distance is reduced to below 0.1, significantly enhancing the feature aggregation of similar samples and improving the accuracy and anti-interference ability of explosive detection.
[0020] Please see Figure 1 , Figure 1 This is a flowchart of a method for building an explosive detection model according to an embodiment of the present invention. The method for building an explosive detection model includes the following steps: S101. Obtain the SERS spectral data of the explosive; S102. Preprocess the SERS spectral data of the explosive to obtain a spectral sample set. The preprocessing includes at least data cleaning, normalization and data augmentation. S103. Construct an ECNN model, wherein the ECNN model includes a feature extraction network, a feature selection network, and a feature classification network connected in sequence; S104. Optimize the ECNN model based on the spectral sample set and the preset cross-entropy-contrast joint loss function, and train the ECNN model using the preset Adam optimizer; S105. Output the trained ECNN model that meets the preset accuracy.
[0021] Understandably, by building and training an ECNN model using preprocessed SERS spectral data, the model's feature extraction, feature selection, and feature classification capabilities can effectively capture feature peaks of different widths and retain core features. Combined with the cross-entropy-contrast joint loss function, the intra-class feature distance is reduced to below 0.1, thereby enhancing the feature aggregation of similar samples and improving the accuracy and anti-interference ability of explosive detection.
[0022] The following provides an illustrative example of each step.
[0023] S101. Obtain the SERS spectral data of the explosive.
[0024] For example, please refer to Figure 8 By building a SERS fiber optic sensing platform, feature detection is performed to establish a feature dataset. The SERS fiber optic sensing platform includes a laser, collimator, dielectric film mirror, dichroic mirror, objective lens, 3-axis NanoMax displacement stage, rigid plastic clad fiber, filter, lens sleeve, five-axis coupler, spectrometer, and computer.
[0025] As is understandable, the laser, collimator, dielectric film mirror, dichroic mirror, objective lens, 3-axis NanoMax displacement stage, rigid plastic clad fiber, filter, lens sleeve, 5-axis coupler, spectrometer and computer are all existing equipment, and will not be described in detail here.
[0026] Furthermore, in the spectral acquisition, sample pretreatment is first performed by immersing the fiber end face in the explosive solution and then drying and fixing it; then the platform is adjusted, the laser is preheated for 10 minutes, and the background spectrum is subtracted; then the integration time is set to 1-5 seconds and the number of scans is 3, the spectral data is acquired and the average value is taken; finally, the data is stored according to the rule of explosive category-sample number-acquisition time, and the platform parameters are recorded.
[0027] Specifically, the excitation beam emitted by the laser is collimated into parallel light, passes sequentially through a dielectric mirror and a dichroic mirror, and is then focused by the objective lens onto the end face of a rigid plastic-clad fiber fixed on a 3-axis NanoMax displacement stage. Through the light-guiding effect of the fiber, the excitation light is transmitted to the end of the fiber probe, where it interacts with explosive molecules attached to the probe surface, generating a SERS signal. The backscattered SERS signal returns along the fiber, is collected by the same objective lens, passes through the dichroic mirror, and is reflected by the dielectric mirror to a filter to remove Rayleigh scattering interference. The purified SERS signal is focused by a lens sleeve and then precisely coupled into the entrance slit of the spectrometer via a five-axis coupler. The five-axis coupler allows for fine-tuning of the coupling angle and position between the fiber and the spectrometer to maximize signal acquisition efficiency. The spectrometer performs spectral dispersion and photoelectric conversion on the received SERS signal to obtain raw spectral data, which is then transmitted to a computer for storage.
[0028] In a specific operational example, the 785nm laser is turned on; the fiber end face is moved to the objective lens focusing area using a computer-controlled 3-axis NanoMax stage; the five-axis coupler is adjusted to achieve a coupling efficiency of over 90% between the fiber and the spectrometer; blank background spectra are acquired and stored for background subtraction in subsequent spectral data; the fiber end face is then immersed in a 10% concentration... - 6 mol / L TNT methanol solution, 10 -6 mol / L PA ethanol solution, 10 -6 The sample was immersed in a mol / L Tetryl acetone solution for 1 min, then removed and air-dried for 10 s to remove residual solvent. The treated optical fiber was fixed on a 3-axis NanoMax displacement stage, ensuring that the fiber end face was aligned with the objective lens center. The spectrometer parameters were set: integration time 3 s, scan number 3. Spectroscopic data were acquired for TNT, PA, and Tetryl samples respectively. Background spectra were automatically subtracted after each acquisition, and the average of the 3 scan results was taken as the final SERS spectral data for that sample. 100 samples of each type of explosive were repeatedly acquired, resulting in a total of 300 spectral samples. The spectral data was stored in RMN format according to the naming rule of "explosive type-sample number-acquisition time-laser power-integration time", and environmental parameters during the acquisition process were recorded.
[0029] It should be noted that combining SERS technology with fiber optic sensing, along with large SERS detection equipment such as LabRAM Odyssey, reduces the size by more than 60%, significantly improving portability and making it suitable for mobile detection scenarios such as border crossings and airports; the combination of 785nm laser and high-resolution spectrometer effectively avoids fluorescence interference, achieving a characteristic peak recognition accuracy of 2cm. -1 .
[0030] S102. Preprocess the SERS spectral data of the explosive to obtain a spectral sample set. The preprocessing includes at least data cleaning, normalization and data augmentation.
[0031] For example, the SERS spectral data of explosives is cleaned to remove outliers; normalization is performed to map Raman intensity values to the 0-1 range, eliminating interference from intensity differences between samples. Data augmentation techniques are used to expand the training set, including adding Gaussian noise with a standard deviation of 0.01-0.03, a random wavenumber shift of ±2 wavenumbers, and a random intensity scaling of 0.8-1.2 times, to improve the model's generalization ability.
[0032] S103. Construct an ECNN model, wherein the ECNN model includes a feature extraction network, a feature selection network, and a feature classification network connected in sequence.
[0033] For example, the feature extraction network mines key features from high-dimensional spectral data. The input is a standardized spectral sample set of dimensions 3×100×1045. It captures features from different wavenumber ranges through three multi-level one-dimensional convolutional layers with kernel sizes of 7, 5, and 3, and a number of kernels of 64, 128, and 256. Each convolutional layer is followed by... The activation function introduces nonlinearity, which is combined with a max pooling layer, a window size of 2, and a stride of 2 to reduce dimensionality. The residual connection is used to protect the spectral feature information, and finally the output is a 1×256×16 dimensional feature vector.
[0034] Furthermore, a feature selection network is used to filter core features. It consists of one flattening layer and two fully connected layers. and By calculating the weighted features, a 1×256-dimensional core feature vector is output, eliminating redundant and interfering features and reducing the computational burden of the model.
[0035] Furthermore, the feature classification network predicts the category based on core features. It contains two fully connected layers and a softmax output layer. The two fully connected layers are input 256 and output 64, and input 64 and output 3, respectively. The first fully connected layer connects to... The activation function integrates features, and the softmax layer converts the output into predicted probabilities for three types of explosives, taking the category corresponding to the maximum probability as the prediction result.
[0036] S104. Optimize the ECNN model based on the spectral sample set and the preset cross-entropy-contrast joint loss function, and train the ECNN model using the preset Adam optimizer.
[0037] For example, the ECNN model is trained using a cross-entropy-contrast joint loss function to optimize the model. The formula for the joint loss function is: .
[0038] Furthermore, cross-entropy loss It is used to measure the difference between the predicted category and the true category, and the calculation formula is: ,in The number of training samples. For cross-entropy, Encode the real label using one-hot encoding. Predict the probability vector for the model.
[0039] Furthermore, compare the losses This is used to optimize the feature space distribution, enabling the clustering of features from similar samples and the separation of features from dissimilar samples. First, feature similarity is calculated using cosine similarity. Then, a 1+K positive-to-negative contrast pair is constructed for each anchor sample. The loss formula for a single anchor sample is: ; In the formula, The core feature vector of anchor sample A. This is the core feature vector of the positive sample W. Let t be the core feature vector of the k-th negative sample, and t be the temperature parameter, with an optimal value of 0.1.
[0040] Furthermore, the Adam optimizer was used to train the model, with an initial learning rate of 0.001 (cosine annealing decay), a batch size of 16, 100 training epochs, and a weight decay coefficient of 0.0001.
[0041] Furthermore, after initializing the parameters, iterative training is performed, and the model accuracy is verified every epoch. If the accuracy does not improve after 5 consecutive epochs, the training is stopped early and the optimal parameters are saved. If the accuracy on the test set does not meet expectations, the parameters are adjusted and the training is repeated.
[0042] S105. Output the trained ECNN model that meets the preset accuracy.
[0043] For example, low, medium, and high intensity Gaussian noise are added to the test set samples, i.e., signal-to-noise ratios of 20:1, 10:1, and 5:1, respectively. The model classification accuracy before and after using the contrastive loss function is then calculated. If the requirements are met, it can be used as a detection model.
[0044] It should be noted that the ECNN model runs in the following environment: CPU model Intel Core i7-12700H, GPU model NVIDIA RTX 3060, 32GB of memory, operating system Windows 10, deep learning framework PyTorch, and programming language Python.
[0045] In one embodiment, please refer to Figure 2 The preprocessing of the SERS spectral data of the explosive includes the following steps: S201. Clean the SERS spectral data and remove abnormal data; S202. Normalize the SERS spectral data and map the Raman intensity values to the 0-1 range to eliminate interference from intensity differences between samples. S203. Data augmentation is used to expand the training set, including adding Gaussian noise with a standard deviation of 0.01-0.03, random wavenumber shift of ±2 wavenumbers, and random intensity scaling of 0.8-1.2 times to improve the model's generalization ability. S204. Divide the processed data into training set samples and test set samples according to the proportion.
[0046] In this embodiment, the processed data is divided into a training set and a test set in a 7:3 ratio.
[0047] Furthermore, data cleaning involves outlier detection and removal from the original spectral data, such as abnormal spectra caused by fiber end-face contamination, laser drift, etc., including abrupt intensity changes and excessive full-spectrum noise, to ensure the data quality input to the model. Normalization involves performing Min-Max normalization on the Raman intensity values of each sample at each wavenumber, mapping them to the [0,1] interval to eliminate intensity differences between different samples caused by factors such as concentration and laser power fluctuations. Data augmentation is used to enhance the robustness of the model in complex environments by augmenting the training set samples in three ways: first, adding Gaussian noise with a standard deviation of 0.01-0.03 to simulate instrument noise; second, wavenumber shifting with a random shift of ±2 wavenumbers to simulate spectrometer wavelength drift; and third, intensity scaling with a random scaling factor of 0.8-1.2 to simulate laser power fluctuations. Dataset partitioning involves dividing the 300 preprocessed samples into a 7:3 ratio: 210 training samples and 90 test samples to ensure a balanced class distribution.
[0048] In one embodiment, please refer to Figure 3 The feature extraction network comprises three blocks, each block including at least sequentially connected convolutional layers, The feature extraction method of the feature extraction network includes activation functions and pooling layers. S301, Input a spectral sample set with dimensions of 3×100×1045; S302. The spectral sample set is processed by convolution, ReLU and pooling in the first block to obtain the first feature sequence; S303. Input the first feature sequence into the second block, perform convolution and ReLU, add it to the first feature sequence through residual connection, and then pool to obtain the second feature sequence. S304. Input the second feature sequence into the third block, perform convolution and ReLU, add it to the second feature sequence through residual connection, and then pool to obtain the feature vector. S305, outputs a feature vector with dimensions of 1×256×16.
[0049] In this embodiment, the convolutional layer is a one-dimensional convolutional layer with kernel sizes of 7, 5, and 3, and a number of kernels of 64, 128, and 256. The pooling layer has a window size of 2 and a stride of 2. Specifically, the feature extraction network comprises three blocks. Each block consists of convolutional layers, ReLU activation functions, and pooling layers. The one-dimensional convolutional layers in the three blocks have kernel sizes of 7, 5, and 3, with a number of kernels of 64, 128, and 256, respectively, and a stride of 1. The convolution operation formula is as follows:
[0050] In the formula, Here, k represents the kernel weights, and k is the kernel size. The input spectrum is the Raman intensity at wavenumber t. is the feature value at position t after convolution.
[0051] Furthermore, each convolutional layer is followed by... The activation function, with the formula:
[0052] Furthermore, a pooling layer is then added after the activation function of each block. The first two blocks use max pooling with a pooling window size of 2 and a stride of 2. The last block uses adaptive average pooling to compress the output to 16. The max pooling operation formula is:
[0053] In the formula, These are the eigenvalues after pooling.
[0054] Furthermore, to preserve spectral feature information, a residual mechanism is introduced. Residual units are constructed within the last two blocks. Specifically, the input features of each block are convolved, and then added to the main path output of that block via a 1×1 convolution for channel alignment. The formula is as follows:
[0055] After processing by the feature extraction network, the original spectral data samples Convert to a feature vector of dimension 1×256×16 , where c is the category and i is the sample number.
[0056] In one embodiment, please refer to Figure 4 The feature selection network includes a flattened layer and at least one fully connected layer connected in sequence, and the feature selection method of the feature selection network includes: S401, Input the feature vector output by the feature extraction network; S402. Input the feature vector into the flattening layer, and obtain the intermediate feature sequence through the flattening operation; S403. Input the intermediate feature sequence into the fully connected layer to calculate the core feature vector; S404, the core feature vector with an output dimension of 1×256.
[0057] In this embodiment, the output of the feature extraction network is... The input flattening layer flattens the extracted features to 256. 16 = 4096.
[0058] Furthermore, through a feature-weighted module, i.e., a 2-layer fully connected combination... and Calculate the core feature vector The formula is The final output is a core feature vector with a dimension of 1×256.
[0059] In one embodiment, please refer to Figure 5 The feature classification network comprises a first fully connected layer, a second fully connected layer, and a softmax output layer connected in sequence. The feature classification method of the feature classification network includes: S501, Input the core feature vector output by the feature selection network; S502. Input the core feature vector into the first fully connected layer, process it through the first fully connected layer to obtain 64-dimensional features, and then connect it to the activation function; S503. Input the activated 64-dimensional features into the second fully connected layer. After processing by the second fully connected layer, a 3-dimensional output is obtained, corresponding to the three explosive categories. S504. Input the output of the second fully connected layer into the softmax output layer, convert it into the prediction probability of each category, and obtain a 1×3 probability vector; S505. Take the category corresponding to the maximum probability as the prediction result of the sample and output it.
[0060] Specifically, the classification network comprises two fully connected layers and one softmax output layer. The first fully connected layer has an input dimension of 256 and an output dimension of 64. The activation function, the second fully connected layer has an input dimension of 64 and an output dimension of 3, corresponding to the three types of explosives.
[0061] Furthermore, the softmax output layer converts the output of the second fully connected layer into predicted probabilities for each class, using the following formula: ; In the formula, C=3 represents the number of categories. This represents the output value of the second fully connected layer at category i. This represents the predicted probability that a sample belongs to category i. Furthermore, the classification network outputs a probability vector with a dimension of 1×3. ,Right now The category corresponding to the highest probability is taken as the final predicted category of the sample.
[0062] In one embodiment, the cross-entropy-contrast joint loss function is: ; in, For the total loss, For cross-entropy loss, To compare the losses, To compare the loss weighting coefficients.
[0063] Furthermore, the formula for calculating the cross-entropy loss is as follows:
[0064] in, The number of training samples. For cross-entropy, For the true labels of the samples, Predict the probability vector for the model.
[0065] Furthermore, the comparison loss calculation step includes: Cosine similarity is used to measure the similarity of sample feature vectors. The formula is: ; in, , These are the core feature vectors of the two samples. ∈[-1,1]; For each anchor sample A, select one sample W of the same class and K samples of different classes to construct a comparison sample pair; The formula for the contrastive loss of a single anchor point sample is: ; in, The core feature vector of anchor sample A. This is the core feature vector of the positive sample W. Let be the core feature vector of the k-th negative sample, and t be the temperature parameter, with an optimal value of 0.1. The contrast loss for a single anchor point sample; The total contrastive loss is the sum of the losses of all anchor point samples, and the formula is: ; in, To compare the total losses, The contrast loss for a single anchor point sample. This represents the number of training samples.
[0066] In one embodiment, the model training process includes: The Adam optimizer was used, with an initial learning rate of 0.001 and a cosine annealing strategy for decay; the batch size was 16; the number of training epochs was 100; and the weight decay coefficient was 0.0001. Initialize the model parameters, using a normal distribution to initialize the weights of the convolutional and fully connected layers, and using a constant of 0 to initialize the biases; Iterative training involves inputting training set samples into the model in batches, calculating the predicted probability p and the total loss L through forward propagation, calculating the gradient through backpropagation, and updating the parameters using the Adam optimizer. After each training epoch, the classification accuracy is calculated on the test set. If the accuracy on the test set does not improve for five consecutive epochs, an early stopping strategy is triggered to save the optimal model parameters.
[0067] In a specific embodiment, the detection of three explosives—TNT, PA, and Tetryl—is used as an example to illustrate the specific implementation process of the present invention.
[0068] In this embodiment, a concentration of 10 is prepared. -6 mol / L TNT methanol solution, 10 -6 mol / L PA ethanol solution, 10 - 6A mol / L Tetryl acetone solution was used. The cladding at both ends of the hard plastic-clad optical fiber was peeled off using a fiber optic de-fiber, the fiber end face was cut with a fiber optic cleaver, and then polished. Finally, the end face was wiped with anhydrous ethanol until it was clean and smooth. One end of the treated fiber was fixed on a 3-axis NanoMax displacement stage, and the other end was connected to a 5-axis coupler. The fixed end face of the fiber was immersed in solutions of different concentrations of TNT, PA, and Tetryl for 1 min each, and then allowed to air dry for 10 s. The integration time was 3 s, and the number of scans was 3. 100 samples were collected for each concentration of each explosive, resulting in a total of 3 × 100 = 300 spectral samples. Figure 9 The images show the SERS data spectra of three types of explosives.
[0069] Furthermore, the RMN files of 300 spectral samples were read, and Raman wavenumbers were extracted from 800-1800 cm⁻¹, totaling 1045 wavenumber points, along with their corresponding intensity values. The intensity values of each sample were normalized to eliminate intensity differences under different concentrations and acquisition conditions. The normalized spectral data were then grouped according to explosive categories, and labels were constructed: TNT: 0, PA: 1, Tetryl: 2. These labels were then converted into tag vectors using one-hot encoding.
[0070] Furthermore, an ECNN model was built based on the PyTorch framework, consisting of a feature extraction network, a feature selection network, and a classification network.
[0071] Furthermore, the model parameters were initialized. The weights of the convolutional and fully connected layers were initialized using a normal distribution, and the biases were initialized to 0. Table 1 shows the ablation experiment results of the loss function parameters. After verification by ablation experiments, a value of 0.3 was taken.
[0072] Table 1: Ablation Experiment Results with Loss Function Parameters
[0073] Furthermore, the training set data loader is input into the model, and forward propagation is used to calculate the predicted probability and total loss; gradients are calculated through backpropagation, and the model parameters are updated using the Adam optimizer; after each epoch of training, the model performance is evaluated on the test set, and the accuracy is recorded; when the test set accuracy does not improve for five consecutive epochs, training is stopped, and the optimal model is saved. Figure 4 The results of dividing the explosive spectra of the ECNN model into (a) training set and (b) test set are shown in the figure.
[0074] Furthermore, classification accuracy was tested. In the uninterrupted scenario, the original test set was input into the ECNN model, and the classification accuracy was calculated. In the interrupted scenario, Gaussian noise with signal-to-noise ratios of 20:1, 10:1, and 5:1 was added to the test set samples, and the model's accuracy at different interference intensities was calculated. The model architecture was preserved, and the accuracy was compared with that of a model trained using only cross-entropy loss without contrastive loss.
[0075] Table 2: Classification accuracy of ECNN model before and after using contrastive loss function under different noise interference intensities.
[0076] Table 2 shows the model accuracy under different noise interference intensities. The ECNN model has an accuracy of 93.33% under low interference, 86.67% under medium interference, and 80% under high interference. As the interference intensity increases, the accuracy of the ECNN model trained with contrastive loss decreases less, and it has strong anti-noise interference ability.
[0077] Understandably, to verify the specific identification capability of the target explosive, common interfering substances, such as ammonium nitrate, urea, and sucrose, were selected and prepared at a concentration of 10. -6 For a solution of mol / L, SERS spectra were acquired following the steps described above. Figure 11 (a) shows the SERS spectra of different interference samples. Combining the SERS spectra and statistical results, 1141 cm⁻¹ -1 This peak can serve as a characteristic identification feature for TNT, effectively distinguishing it from common interfering substances such as ammonium nitrate, urea, and sucrose. Statistical analysis of 30 samples for each substance category was performed. The **** in the figure indicates statistically significant differences between groups (P≤0.0001), further confirming the platform's specific identification capability.
[0078] Understandably, combining SERS technology with fiber optic sensing and large-scale SERS detection equipment reduces its size by more than 60%, significantly improving portability and making it suitable for mobile detection scenarios such as border crossings and airports. The combination of 785nm laser and high-resolution spectrometer effectively avoids fluorescence interference, achieving a feature peak recognition accuracy of 2cm-1. The ECNN model captures feature peaks of different widths through multi-level convolutions, and the attention mechanism filters core features, achieving a feature retention rate of 92% with weights >0.8. The joint loss function reduces the intra-class feature distance to <0.1, improving anti-interference capability by 40%-50% compared to traditional algorithms. The entire process from sample preprocessing to result output takes <5 seconds and requires no professional personnel. It can detect trace amounts of explosives at the 10-10 mol / L level, maintaining a high accuracy of >76% in both interference-free and high-interference scenarios, making it suitable for multiple fields such as security inspection, counter-terrorism, and environmental monitoring.
[0079] The present invention also provides an explosive detection model building device 600, including a spectral data acquisition module 601, a data processing module 602, a model building module 603, a model training module 604, and a model output module 605.
[0080] In this embodiment, the spectral data acquisition module 601 is used to acquire the SERS spectral data of the explosive.
[0081] In this embodiment, the data processing module 602 is used to preprocess the SERS spectral data of the explosive to obtain a spectral sample set. The preprocessing includes at least data cleaning, normalization and data augmentation. Furthermore, the SERS spectral data of the explosives were cleaned to remove outliers; normalization was performed to map the Raman intensity values to the 0-1 range, eliminating interference from intensity differences between samples. Data augmentation techniques were employed to expand the training set, including adding Gaussian noise with a standard deviation of 0.01-0.03, a random wavenumber shift of ±2 wavenumbers, and a random intensity scaling of 0.8-1.2 times, to improve the model's generalization ability.
[0082] In this embodiment, the model building module 603 is used to build an ECNN model, wherein the ECNN model includes a feature extraction network, a feature selection network and a feature classification network connected in sequence; Furthermore, the feature extraction network mines key features from high-dimensional spectral data. The input is a standardized spectral sample set of dimensions 3×100×1045. Through three multi-level one-dimensional convolutional layers with kernel sizes of 7, 5, and 3, and a number of kernels of 64, 128, and 256, features in different wavenumber ranges are captured. Each convolutional layer is followed by... The activation function introduces nonlinearity, which is combined with a max pooling layer, a window size of 2, and a stride of 2 to reduce dimensionality. The residual connection is used to protect the spectral feature information, and finally the output is a 1×256×16 dimensional feature vector.
[0083] Furthermore, a feature selection network is used to filter core features. It consists of one flattening layer and two fully connected layers. and By calculating the weighted features, a 1×256-dimensional core feature vector is output, eliminating redundant and interfering features and reducing the computational burden of the model.
[0084] Furthermore, the feature classification network predicts the category based on core features. It contains two fully connected layers and a softmax output layer. The two fully connected layers are input 256 and output 64, and input 64 and output 3, respectively. The first fully connected layer connects to... The activation function integrates features, and the softmax layer converts the output into predicted probabilities for three types of explosives, taking the category corresponding to the maximum probability as the prediction result.
[0085] In this embodiment, the model training module 604 is used to optimize the ECNN model based on the spectral sample set and the preset cross-entropy-contrast joint loss function, and to train the ECNN model using the preset Adam optimizer. Furthermore, the ECNN model is trained and optimized using a cross-entropy-contrast joint loss function, the formula of which is: .
[0086] In this embodiment, the model output module 605 is used to output a trained ECNN model that meets the preset accuracy.
[0087] The aforementioned explosive detection model building device 600 can be implemented as a computer program, which can be used in, for example... Figure 7 It runs on the electronic device shown.
[0088] Please see Figure 7 , Figure 7 This is a schematic block diagram of an electronic device provided in an embodiment of the present invention. The electronic device 700 is a host computer or a server.
[0089] See Figure 7 The electronic device 700 includes a processor 702, a memory, and a network interface 705 connected via a device bus 701. The memory may include a storage medium 703 and internal memory 704.
[0090] The storage medium 703 may store an operating system 7031 and a computer program 7032. When the computer program 7032 is executed, it enables the processor 702 to execute a method for building an explosive detection model.
[0091] The processor 702 provides computing and control capabilities to support the operation of the entire electronic device 700.
[0092] The internal memory 704 provides an environment for the operation of the computer program 7032 in the storage medium 703. When the computer program 7032 is executed by the processor 702, the processor 702 can execute the explosive detection model building method.
[0093] This network interface 705 is used for network communication, such as providing data transmission. Those skilled in the art will understand that... Figure 7The structure shown is merely a block diagram of a portion of the structure related to the present invention and does not constitute a limitation on the electronic device 700 to which the present invention is applied. The specific electronic device 700 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0094] The processor 702 is used to run a computer program 7032 stored in a memory to implement the explosive detection model building method disclosed in the embodiments of the present invention.
[0095] Those skilled in the art will understand that Figure 7 The embodiments of the computer device shown do not constitute a limitation on the specific configuration of the computer device. In other embodiments, the computer device may include more or fewer components than illustrated, or combine certain components, or have different component arrangements. For example, in some embodiments, the computer device may include only memory and a processor. In such embodiments, the structure and function of the memory and processor are different from those shown. Figure 5 The embodiments shown are consistent and will not be described again here.
[0096] It should be understood that, in this embodiment of the invention, the processor 702 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0097] In another embodiment of the present invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, wherein when executed by a processor, the computer program implements the explosive detection model building method disclosed in the embodiments of the present invention.
[0098] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.
[0099] In the embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Units with the same function may be grouped into one unit. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, or may be electrical, mechanical, or other forms of connection.
[0100] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.
[0101] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0102] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device (which may be a personal computer, a backend server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks.
[0103] The specific embodiments of the present invention described above do not constitute a limitation on the scope of protection of the present invention. Any other corresponding changes and modifications made in accordance with the technical concept of the present invention should be included within the scope of protection of the claims of the present invention.
Claims
1. A method for constructing an explosive detection model, characterized in that, Includes the following steps: Obtain SERS spectral data of the explosive; The SERS spectral data of the explosive are preprocessed to obtain a spectral sample set. The preprocessing includes at least data cleaning, normalization and data augmentation. An ECNN model is constructed, wherein the ECNN model includes a feature extraction network, a feature selection network, and a feature classification network connected in sequence; The ECNN model is optimized based on a spectral sample set and a pre-defined cross-entropy-contrast joint loss function, and trained using a pre-defined Adam optimizer; and Output a trained ECNN model that meets the preset accuracy.
2. The method for building an explosive detection model according to claim 1, characterized in that, The preprocessing of the SERS spectral data of the explosive includes: Clean the SERS spectral data and remove outliers; The SERS spectral data were normalized, and the Raman intensity values were mapped to the 0-1 range to eliminate the interference of intensity differences between samples. The training set is augmented with data augmentation, including adding Gaussian noise with a standard deviation of 0.01-0.03, random wavenumber shift of ±2 wavenumbers, and random intensity scaling of 0.8-1.2 times to improve the model's generalization ability. The processed data is divided into training set samples and test set samples according to the proportion.
3. The method for building an explosive detection model according to claim 1, characterized in that, The feature extraction network comprises three blocks, each block including at least sequentially connected convolutional layers, The feature extraction method of the feature extraction network includes activation functions and pooling layers. Input a spectral sample set with dimensions of 3×100×1045; The spectral sample set is processed by convolution, ReLU and pooling in the first block to obtain the first feature sequence; The first feature sequence is input into the second block, and after convolution and ReLU, it is added to the first feature sequence through residual connection, and then pooled to obtain the second feature sequence. The second feature sequence is input into the third block, and after convolution and ReLU, it is added to the second feature sequence through residual connection, and then pooled to obtain the feature vector; The output is a feature vector with dimensions of 1×256×16.
4. The method for building an explosive detection model according to claim 3, characterized in that, The feature selection network includes a flattening layer and at least one fully connected layer connected in sequence, and the feature selection method of the feature selection network includes: Input the feature vector output by the feature extraction network; The feature vector is input into the flattening layer, and the intermediate feature sequence is obtained through the flattening operation. The intermediate feature sequence is input into a fully connected layer to calculate the core feature vector; The output is a core feature vector with a dimension of 1×256.
5. The method for building an explosive detection model according to claim 4, characterized in that, The feature classification network comprises a first fully connected layer, a second fully connected layer, and a softmax output layer connected in sequence. The feature classification method of the feature classification network includes: The input feature selection network outputs the core feature vector; The core feature vector is input into the first fully connected layer, processed by the first fully connected layer to obtain 64-dimensional features, and then connected to the activation function; The activated 64-dimensional features are input into the second fully connected layer, and after processing by the second fully connected layer, a 3-dimensional output is obtained, corresponding to the three explosive categories. The output of the second fully connected layer is input into the softmax output layer and converted into prediction probabilities for each category, resulting in a 1×3 probability vector. The category corresponding to the highest probability is taken as the prediction result for the sample.
6. The method for building an explosive detection model according to claim 3, characterized in that, The cross-entropy-contrast joint loss function is: ; in, For the total loss, For cross-entropy loss, To compare the losses, To compare the loss weighting coefficients.
7. The method for building an explosive detection model according to claim 6, characterized in that, The formula for calculating the cross-entropy loss is as follows: ; in, The number of training samples. For cross-entropy, For the true labels of the samples, Predict probability vectors for the model; The comparison loss calculation steps include: Cosine similarity is used to measure the similarity of sample feature vectors. The formula is: ; in, , These are the core feature vectors of the two samples. ∈[-1,1]; For each anchor sample A, select one sample W of the same class and K samples of different classes to construct a comparison sample pair; The formula for the contrastive loss of a single anchor point sample is: ; in, The core feature vector of anchor sample A. This is the core feature vector of the positive sample W. Let t be the core feature vector of the k-th negative sample, and t be the temperature parameter. The contrast loss for a single anchor point sample; The total contrastive loss is the sum of the losses of all anchor point samples, and the formula is: ; in, To compare the total losses, For the contrast loss of a single anchor point sample, This represents the number of training samples.
8. A device for constructing an explosive detection model, characterized in that, include: The spectral data acquisition module is used to acquire the SERS spectral data of explosives; The data processing module is used to preprocess the SERS spectral data of the explosive to obtain a spectral sample set. The preprocessing includes at least data cleaning, normalization and data augmentation. The model building module is used to build an ECNN model, wherein the ECNN model includes a feature extraction network, a feature selection network and a feature classification network connected in sequence; The model training module is used to optimize the ECNN model based on the spectral sample set and the preset cross-entropy-contrast joint loss function, and to train the ECNN model using the preset Adam optimizer. as well as The model output module is used to output the trained ECNN model that meets the preset accuracy.
9. An electronic device, characterized in that, include: Processor and memory; The memory stores computer programs that can be executed by the processor; When the processor executes the computer program, it implements the steps of the explosive detection model building method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement the explosive detection model building method as described in any one of claims 1-7.