Explainable residual CNN with Gramian Angular Field encoding for rapid quantification of soil properties using near-infrared spectroscopy
Abstract
Background Soil chemical composition is a key indicator of soil fertility, yet conventional physicochemical analysis is time-consuming and costly. Although near-infrared (NIR) spectroscopy enables rapid, non-destructive detection, traditional linear models struggle with the non-linear nature of high-dimensional spectral data, and deep-learning models often suffer from a "black-box" problem. Methods A one-dimensional residual convolutional neural network (1D-Res-CNN) was constructed, and the output feature maps of intermediate convolutional layers were visualized to reveal how the model learns spectral features. One-dimensional spectral sequences were mapped into twodimensional images via Gramian Angular Summation Field (GASF) and Continuous Wavelet Transform (CWT); after systematically comparing encoding performance across spectral sub-intervals, the optimal range was selected to feed a two-dimensional residual CNN (2D-Res-CNN) regression model. Using SNV-preprocessed Fourier-transform NIR spectra and an SPXY-partitioned dataset, the proposed framework was benchmarked against partial least squares regression (PLSR), k-nearest neighbors (KNN), and random forest (RF). Results First-layer kernels in the 1D-Res-CNN automatically captured spectral features corresponding to functional-group absorption peaks, supporting the physical interpretability of feature extraction. GASF-encoded images in the 5880~4000 cm-1 range exhibited the highest feature density and outperformed CWT encoding. The 2D-Res-CNN achieved prediction-set Rp2 of 0.87, 0.91, 0.91, 0.93, and 0.88 for soil pH, labile organic carbon, total nitrogen, organic matter, and available phosphorus, respectively, with lower RMSEP than both the 1D-CNN and PLSR. Conclusion By enhancing spectral feature expression through visual encoding and providing preliminary insight into model behavior via layer-wise feature-map visualization, this work offers an interpretable technical strategy for rapid quantitative analysis of soil chemical composition by NIR spectroscopy.