Open Access Article
Minghui
Gu
ab,
Huansong
Huang
ab,
Qingbin
Jiao
*a,
Ding
Ma
a,
Yuxing
Xu
c,
Chao
Liu
ab,
Jiguo
Li
ab,
Xin
Zhang
ab,
Mingyu
Yang
a,
Liang
Xu
a,
Sijia
Jiang
a,
Hong
Li
d,
Jiahui
Qi
d,
Junbo
Zang
d and
Xin
Tan
*a
aChinese Academy of Sciences, Changchun Institute of Optics, Fine Mechanics and Physics, Changchun, 130033, China
bUniversity of the Chinese Academy of Sciences, Beijing, 100049, China
cSchool of Physics and Electronic Information, Yantai University, Yantai, Shandong 264005, China
dJilin Province Product Quality Supervision and Inspection Institute, Changchun, 130022, China
First published on 3rd December 2025
Soil heavy metal contamination poses a serious threat to agricultural product safety and public health, which urgently calls for the development of rapid and accurate in situ detection techniques. LIBS enables simultaneous multi-element analysis and requires minimal sample preparation, and has been widely applied in the field of elemental analysis. However, under practical field conditions, moisture in soil significantly interferes with the stability and intensity of LIBS signals, thereby limiting its capability for large-area, in situ, and accurate detection in real-world environments. To address this issue, this study proposes a novel approach for simultaneous multi-element quantitative analysis by integrating neural networks with physical correction strategies. Adaptive Iteratively Reweighted Penalized Least Squares (airPLS) and Random Forest were employed to optimize spectral data and screen characteristic spectral fingerprints. An ablation factor model was established to correct spectral intensity under moisture interference, and a Multi-Task Convolutional Attention Network (MT-CAN) was constructed to predict both moisture content and multiple heavy metal concentrations. The results demonstrated that the root mean square error for moisture prediction reached 0.83%, and the relative errors for simultaneous quantification of Zn, Cr, Cu, and Pb were all below 8%. Finally, a transfer learning strategy based on model parameters was adopted to further enhance the cross-regional generalization capability of the model. This study provides an effective technical foundation for achieving in situ heavy metal detection in field soil environments.
Laser-induced breakdown spectroscopy (LIBS), recognized for its rapid analysis, capability for simultaneous multi-element detection, and minimal sample preparation requirements, is widely regarded as a promising tool for on-site elemental analysis.4 It has been successfully applied in various fields including geological exploration.5–7 For instance, Han et al. converted LIBS spectral intensities into RGB images and employed clustering algorithms to map the distribution of Cu, Cr, and Pb in contaminated soil with high spatial resolution, thereby achieving heavy metal imaging and spatial distribution analysis of the polluted areas.8 Li et al. integrated graphite enhancement with a machine learning model (LWNet), which enabled the accurate quantification of Cd across mixed soil types and significantly improved the sensitivity and accuracy of LIBS for detecting trace toxic heavy metals.9 In contrast to traditional soil detection methods that rely on complex wet chemical digestion procedures, such as AAS,10 ICP-AES,11 and ICP-MS,12 LIBS substantially reduces the analytical cycle time and dependency on laboratory settings, rendering it more suitable for rapid analysis in field environments. However, moisture in natural soils (ranging from 2 to 25%)13 severely interferes with the formation and evolution of the laser-induced plasma, markedly reducing signal stability and intensity,14,15 which limits the technique's ability to achieve multi-element in situ detection in field soil environments. Consequently, heavy metal detection in soils still largely requires laboratory drying pretreatment to ensure analytical accuracy.
Notably, LIBS technology itself offers potential pathways to overcome moisture interference. Studies have indicated that LIBS spectral signals contain information closely related to the moisture state of samples, which can be utilized for the quantitative assessment of water content.16 To date, several researchers have employed LIBS to investigate moisture content in samples and the plasma excitation characteristics of wet specimens. For instance, M. Chen et al. studied the influence of moisture content in coal powder on laser-induced plasma properties, revealing a nonlinear relationship between moisture variation and plasma electron density;17 however, no effective signal correction method was proposed. Y. Liu et al. utilized laser-induced breakdown spectroscopy (LIBS) to analyze moisture content in cheese by normalizing the ratio of the oxygen signal to the CN signal,18 yet the generalization capability of this single-ratio approach in complex real-world matrices remains limited. Chen et al. developed an artificial neural network (ANN) prediction model based on low-moisture coal samples and proposed a stochastic spectral attenuation method to mitigate moisture-induced perturbations,19 but simultaneous multi-element detection was not achieved. Meanwhile, Wudil et al. achieved non-destructive analysis of soil moisture using support vector regression combined with adaptive boosting (SVR-ADB) for feature selection,20 although they did not extend the method to quantify heavy metals under moisture influence.
Building upon this, the present study is designed to develop a method for simultaneous and accurate multi-element quantitative analysis that is suitable for field soils by integrating moisture content prediction, spectral correction strategies, and neural network-based advanced data processing techniques. Initially, a two-dimensional convolutional neural network with an attention mechanism will be constructed based on extracted spectral fingerprint features to predict soil moisture content. Subsequently, incorporating an analysis of the laser ablation physical mechanism, an ablation factor will be introduced to correct the intensity of spectral signals affected by moisture. On this basis, a multi-task convolutional attention network will be established to achieve synchronous and high-precision quantitative analysis of multiple target heavy metal elements (such as Zn, Cr, Cu, and Pb) in moist soil. Finally, to enhance the model's generalizability and practicality, transfer learning of model parameters will be introduced. Using a small amount of spectral data from the target region (or soil type), the pre-trained model will be fine-tuned to rapidly adapt to detection requirements in new environments. This research is expected to provide technical support for real-time and in situ monitoring of heavy metal contamination in agricultural soils (moisture content 0–25%).
To prepare moist soil samples, five standard soil materials (4 g) were oven-dried and subdivided into 2.0 g aliquots. Each subsample was placed in a 50 mL beaker, and 2.0 g of ultrapure water was added. To alleviate moisture gradients within the soil particles, the samples were periodically stirred and sealed to maintain equilibrium. After 6 hours, the samples were transferred to a drying oven to undergo slow and more uniform moisture loss. By controlling the duration in the drying chamber, soil samples with final moisture contents of 0%, 9.09%, 13.79%, 18.03%, and 23.08% were obtained. This gradient was designed to cover the typical soil moisture range and, based on observations from actual farmland sampling (where soil moisture at 15 cm depth seldom falls below 10%) focuses on characterizing the higher moisture range. Prior to analysis, each soil sample was stirred and mixed again to further reduce heterogeneity, ensuring that the local moisture content at any random laser ablation site reasonably approximated the overall average moisture content determined gravimetrically. One set of samples was used for LIBS analysis, while parallel samples were tested according to HJ 613-2011 to determine the actual moisture content, which served as the benchmark truth value for the LIBS moisture prediction model. The concentrations of elements Zn, Cr, Cu, and Pb, along with the moisture content, are presented in Table 1.
| Sample | 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|---|
| Dry/ppm | Zn | 65.8 | 102.7 | 140.6 | 178.5 | 214.2 |
| Cr | 34.6 | 66.3 | 95.2 | 121.7 | 158.6 | |
| Cu | 15.1 | 28.1 | 32.8 | 45.1 | 54.7 | |
| Pb | 39.5 | 56.2 | 72.4 | 85.5 | 102.6 | |
| Wet/% | MC | 0.00 | 9.09 | 13.79 | 18.03 | 23.08 |
To obtain high-quality plasma signals, the optimized experimental parameters were set as follows: a single-pulse energy of 50 mJ, an integration time of 1.2 ms, a delay time of 1 µs, and a repetition rate of 10 Hz. The samples were placed on an X–Y–Z motorized translation stage for precise positioning. To ensure that the spectral data used for modeling represented stable and representative signals, 100 sampling points were randomly selected from the surface of each soil sample, with five spectra collected per point. By calculating the average cosine similarity of each spectrum to the others,22 the 400 spectral data points with the smallest differences were ultimately selected as representative signals, thereby minimizing the potential impact of local moisture heterogeneity and other transient fluctuations on model reliability. The total spectral acquisition time per sample was ≤8 minutes, ensuring that moisture content variation remained within 1% (see Fig. S3). A total of 4000 LIBS spectra were collected, of which 2000 were used for moisture content analysis and 2000 for multi-element concentration prediction.
![]() | ||
| Fig. 4 RF feature selection weights and spectral line distribution: (A) pertaining to moisture content; (B) pertaining to element concentrations. | ||
Among the 80 spectral lines correlated with moisture content, high-weight features are concentrated in characteristic hydrogen and oxygen emission regions such as Hα 656.3 nm, O I 777.2/844.6 nm, and the OH molecular band at 308–320 nm. The remaining weights are mainly concentrated in the 200–500 nm band, where the emission lines of metallic elements are dense, due to the rapid vaporization and dissociation of water molecules in moist soil when irradiated with laser pulses. A part of the incident laser energy is consumed, thereby reducing the overall plasma temperature. This suppressed plasma state directly attenuates the emission intensity of certain metallic elements. Consequently, the intensity variations of these metallic spectral lines indirectly reflect plasma state modifications induced by moisture content. Furthermore, from the LIBS data of dried soils with varying concentrations, 64 core spectral lines related to elemental quantification were densely distributed in the 200–500 nm region, which contains characteristic metal emission peaks including Zn I 213.8 nm, Cr I 427.4 nm, Cu I 324.7 nm, and Pb I 406.3 nm, showing high consistency with the characteristic excitation bands of the target elements.
Based on this, we propose a Multi-Task Convolutional Attention Network (MT-CAN, Fig. 5),which integrates two key tasks: moisture content prediction and multi-element concentration regression, with the aim of achieving rapid and accurate in situ detection of various heavy metal elements in humid soils. The core structure of MT-CAN consists of multi-level residual feature extraction, parallelized multi-scale Inception modules, dual attention feature calibration mechanisms, cross-stitch multitask interaction units, and a deep regression output module. First, the network employs a three-level residual module to construct the base feature extractor. This structure, through multi-layer convolution and non-linear hierarchical stacking of the original spectrum, preliminarily extracts spectral features related to elemental content or moisture, while effectively alleviating the gradient vanishing problem in deeper networks, thus providing robust low-level feature representations for subsequent multi-scale analysis. Subsequently, an improved parallelized Inception module is introduced for multi-scale feature reorganization. This module includes four independent paths, each employing 1 × 1, 3 × 3, and 5 × 5 convolution kernels along with max-pooling operations, further capturing subtle peak variations and global spectral trends within the spectral data from different samples. Residual units are embedded at the terminus of each path which enhances the stability of model training and convergence efficiency. To further strengthen the representation capability of critical features, a dual-attention feature calibration mechanism is employed in this work that adaptively re-weights feature responses across both channel and spatial dimensions. The channel attention submodule integrates average-pooling and max-pooling information and learns the significance weights of each channel via a shared multilayer perceptron whereas the spatial attention submodule generates spatial weight maps based on double-polarity pooled features through a standard convolutional layer thereby enhancing the focus on key wavelength regions and suppressing redundant responses. The collaborative weighting operation of both submodules effectively improves the model's selectivity toward useful spectral signals and its anti-interference capability. In response to the inherent correlations among chemical substrates in multi-element regression prediction tasks, a cross-stitch multi-task interaction mechanism32 is adopted which connects every two elemental prediction tasks via a 4 × 4 learnable weight matrix thereby enabling adaptive feature sharing across tasks and allowing the network to autonomously learn synergistic and constrained relationships among different elements.
To mitigate the risk of overfitting in the complex model, we adopted a hierarchical regularization strategy: L2 regularization (weight decay coefficient λ = 0.005) was introduced in the fully connected layers, batch normalization layers were embedded after each convolutional and fully connected layer, and a progressive dropout mechanism is employed (task layer dropout rate = 0.3; output layer dropout rate = 0.2). The loss function was formulated in a multitask weighted form (eqn (1)), considering both the regression errors of each task and the regularization constraint of the cross-stitch matrix. The optimal task weight combination [0.3, 0.2, 0.3, 0.2] was determined through grid search on the validation set, in order to balance the learning process of the different subtasks.
![]() | (1) |
Furthermore, comparative experiments were conducted with other commonly used methods, including KNN, SVM and 1DCNN. Table 2 summarizes the performance metrics of all comparative models. The MT-CAN model consistently outperformed all other conventional models across every performance metric. With a K of 0.978 and an RMSE of 0.831, it demonstrates high predictive accuracy. Moreover, the model maintained robust predictive capability even in extreme moisture content ranges (<2% or >20%), with the maximum absolute error not exceeding 2%, thereby meeting practical detection requirements.
| MT-CAN | KNN | SVM | 1D-CNN | |
|---|---|---|---|---|
| RMSE/% | 0.83 | 1.07 | 1.21 | 1.98 |
| K | 0.98 | 0.96 | 0.95 | 0.89 |
| MAE/% | 0.71 | 0.93 | 1.01 | 1.73 |
To enhance the interpretability of the MT-CAN model, full-spectrum data were input into the model, and Gradient-weighted Class Activation Mapping (Grad-CAM) was applied to generate feature importance heatmaps.33 This technique computes gradient weights of the feature maps from the final convolutional layer and visually highlights key spectral regions critical to the model's decision-making process. As shown in Fig. 7, the highest activation intensities consistently correspond to the characteristic emission regions of hydrogen (Hα 656.3 nm) and oxygen (OI 777.2/844.6 nm). This correlation occurs because water molecules (H2O) dissociate in the high-temperature plasma, and the resulting hydrogen (H) and oxygen (O) atoms become excited by the plasma, enhancing these characteristic spectral lines. Meanwhile, other significant weights are concentrated in the 200–500 nm region, which is rich in emission lines from metallic elements. This is attributed to the substantial consumption of laser energy in vaporizing and dissociating water, leading to a temperature drop in the plasma core, thereby attenuating their spectral line intensities. The visualization results confirm that MT-CAN successfully captures the interaction between moisture and soil matrix components, which is consistent with the features selected by RF. Therefore, employing RF feature pre-selection can improve the training efficiency of the network.
![]() | ||
| Fig. 7 The feature visualization based on Grad-CAM; different colors denote different contribution values. | ||
![]() | (2) |
![]() | (3) |
The reduction factor for each spectral band across samples with varying moisture contents was calculated according to eqn (3) and fitted exponentially, as shown in Fig. 8 (with fitting results for other bands provided in Fig. S4). A correlation coefficient of 0.99 was achieved, indicating a strong correlation between the ablation factor and moisture content. The empirically derived fitting function was incorporated into the calculation of the ablation factor in eqn (3), which was then used to correct the peak intensities of characteristic spectral lines for samples with different moisture levels. In Fig. 10, the uncorrected intensities are shown in black, and the corrected intensities are shown in red. It can be observed that the corrected spectral intensities increased significantly across all bands and converged toward those obtained under dry conditions. To quantify the overall correction effect, cosine similarity was employed to evaluate the spectral similarity between the uncorrected and corrected spectra and the dry spectra. (calculated only within the corrected spectral bands), as shown in Table 3. The results demonstrate that the spectra corrected using the ablation factor exhibit substantially higher consistency with those acquired under dry conditions.
| MC/% | 0.00 | 9.09 | 13.79 | 18.03 | 23.08 |
|---|---|---|---|---|---|
| uncorrected | 1.00 | 0.98 | 0.94 | 0.85 | 0.68 |
| Corrected | 1.00 | 0.99 | 0.98 | 0.99 | 0.99 |
:
2 ratio to thoroughly train the model. To simulate realistic field conditions involving moist soil, five dried soil samples with different concentration levels (Table 1) were prepared by adding ultrapure water following a standardized procedure, resulting in moist samples with moisture contents of 0%, 8.7%, 12.8%, 16.6%, and 24.1%. For each sample, 120 LIBS spectra were collected, and the same set of 64 characteristic spectral lines was extracted. These spectral data were intensity-corrected using the model described in Section 4.2, and the corrected data were then input into the pre-trained MT-CAN network for elemental concentration prediction. The prediction results for Zn, Cr, Cu, and Pb contents on the independent validation set are presented in Fig. 9 and Table 4.
| MC = 16.6% | Zn | Cr | Cu | Pb | |
|---|---|---|---|---|---|
| Corrected | REMAX | 7.89% | 6.97% | 5.13% | 6.27% |
| RMSE | 5.27 | 3.43 | 1.04 | 2.34 | |
| MAE | 4.41 | 2.75 | 0.84 | 1.97 | |
| Uncorrected | REMAX | 49.29% | 44.20% | 37.53% | 49.10% |
| RMSE | 36.16 | 24.92 | 8.09 | 18.81 | |
| MAE | 29.35 | 19.65 | 7.16 | 15.56 | |
To evaluate the contribution of each key component in the MT-CAN architecture and explore potential simplifications, we systematically designed seven ablation models: Model A (without residual connections), Model B (without Inception-style multi-branch blocks), Model C (without attention mechanisms), Model D (without CrossStitch units), Model E (retaining only residual and attention modules), Model F (retaining only attention and CrossStitch modules), and Model G (retaining only residual and CrossStitch modules). As summarized in Table S1 (see SI), the performance of the complete model was compared with that of these ablated versions. The results demonstrate that (1) removing the dual attention mechanism caused the most significant performance degradation (average RMSE increased by 62.9%), confirming its crucial role in calibrating feature responses and suppressing noise. (2) Disabling the CrossStitch units, thereby isolating the tasks, led to substantial performance decline (average RMSE increased by 40.4%), highlighting the importance of leveraging intrinsic correlations among elemental concentrations for synergistic prediction. (3) Replacing the multi-scale Inception modules with standard convolutional layers resulted in notable deterioration (average RMSE increased by 39.4%), validating the necessity of capturing spectral features at different scales. (4) Moreover, eliminating residual connections not only reduced prediction accuracy (average RMSE increased by 25.1%) but also led to training instability and slower convergence.
The results demonstrate that the integrated LIBS analytical framework, which combines a dynamic moisture content correction model with multi-task learning, achieves relative errors of less than 8% for the quantitative analysis of all four elements, fulfilling the detection requirements in moist soil environments and providing effective technical support for the in situ monitoring of heavy metal contamination in soils.
Finally, to facilitate practical application, this study developed a standalone software tool based on Python 3.8 and the PyQt5 module, which integrates and encapsulates the entire workflow described above—including spectral preprocessing, moisture content analysis, the ablation factor correction model, multi-element quantitative prediction, and result analysis. A representative example of the software's user interface is provided in the Fig. S5.
The specific implementation of the transfer learning framework includes the following steps: (1) the MT-CAN model fully trained on the source domain was used as the initialized network; (2) the front-end shared feature extraction layers (multi-level residual layer and Inception layer) were frozen, which preserved the knowledge of common spectral features learned from the source model; (3) only the task-specific layers (dual-attention layer, cross-stitch interaction layer, and regression output layer) were unfrozen and fine-tuned. The fine-tuning process utilized target domain data with a lower initial learning rate (5 × 10−4), employed the loss function with weight calibration, and applied early stopping to prevent overfitting. This approach effectively reused source domain knowledge while adapting to the target domain characteristics through targeted adjustments of task-specific parameters.
To validate the effectiveness of transfer learning, three modeling strategies were compared: Strategy A (training from scratch using only 200 target domain samples), Strategy B (direct application of the source domain pre-trained model without fine-tuning), and Strategy C (the transfer learning strategy proposed in this study). As shown in Table 5, Strategy C demonstrated superior predictive performance. This confirms that transfer learning significantly reduces the reliance on target domain data volume (requiring only approximately 15% of the source domain data size) by reusing shared spectral features and incorporating targeted adjustments with target domain samples, thereby offering an effective technical solution for LIBS-based monitoring in complex and variable agricultural soils.
| Zn | Cr | Cu | Pb | ||
|---|---|---|---|---|---|
| Strategy A | RE | 10.31% | 9.41% | 8.98% | 12.89% |
| RMSE | 8.24 | 6.25 | 2.11 | 3.65 | |
| MAE | 7.03 | 5.47 | 1.83 | 3.25 | |
| Strategy B | RE | 15.62% | 14.63% | 15.33% | 13.51% |
| RMSE | 11.96 | 11.08 | 3.72 | 3.98 | |
| MAE | 10.65 | 9.52 | 3.19 | 3.42 | |
| Strategy C | RE | 4.25% | 3.32% | 3.49% | 5.04% |
| RMSE | 3.31 | 1.79 | 1.07 | 1.33 | |
| MAE | 2.90 | 1.51 | 0.90 | 1.10 |
The spectral data were optimized and characteristic spectral fingerprints were screened using airPLS combined with random forest; a multi-task convolutional attention network (MT-CAN) was constructed to achieve simultaneous prediction of soil moisture content and multi-element concentrations. For moisture prediction, the MT-CAN model demonstrated superior performance (k = 0.98, RMSE = 0.83%, and MAE = 0.71%). Even under extreme moisture conditions, the prediction error remained within 2%, indicating significantly enhanced stability compared to other benchmark models. Furthermore, the introduction of an ablation factor model for intensity correction of moist sample spectra resulted in corrected spectra that exhibited high consistency with the reference dry spectra. All evaluation metrics (REMAX, RMSE, and MAE) for multi-element quantitative analysis were reduced to approximately one-seventh of their pre-correction levels, with relative errors consistently below 8%, demonstrating the method's strong capability to correct moisture interference.
Finally, by employing a transfer learning strategy that fine-tunes a source domain pre-trained model with a limited number of target domain samples, the generalization capability of the model across different regional soils was significantly enhanced. Compared with other strategies, the transfer learning fine-tuned model achieved the lowest mean absolute error in predicting target elements, validating the effectiveness and practicality of the proposed method for cross-regional applications.
Although the transfer learning strategy and the proposed MT-CAN model in this study have demonstrated good adaptability between two distinct soil types (the yellow-brown soil from Henan and the black soil/chernozem from Jilin), it must be acknowledged that the robustness of the proposed method when applied to other soils (such as sandy/clayey textures or markedly different mineral compositions) still requires further systematic evaluation. Future work will focus on constructing a large-scale spectral library encompassing a wider variety of soil types and exploring the incorporation of soil physicochemical properties as auxiliary input variables to develop more universal LIBS in situ detection solutions.
Supplementary information: sample preparation methods, soil moisture content trends, ablation factor correction model, software interface description, and ablation test results for the MT-CAN model. See DOI: https://doi.org/10.1039/d5ja00355e.
| This journal is © The Royal Society of Chemistry 2026 |