Prediction of Soil Total Nitrogen Based on NIR Spectroscopy and BiGRU Model With Attention Mechanism
JU Wei-liang1, YANG Wei1, 2, SONG Ya-mei1, LIU Nan1, LI Hao1, LI Min-zan1, 2*
1. Key Lab of Smart Agriculture System Integration, Ministry of Education, China Agricultural University, Beijing 100083, China
2. Key Lab of Agricultural Information Acquisition Technology, Ministry of Agriculture and Rural Affairs, China Agricultural University, Beijing 100083, China
Abstract:Soil total nitrogen (STN) content is a key indicator for evaluating soil fertility, and its accurate measurement is of great significance for improving crop yield and quality. Predicting soil total nitrogen content using near-infrared spectroscopy has been proven to be an effective solution. However, due to the high dimensionality and complex time series characteristics of soil spectral data, traditional models often struggle to capture critical information, affecting prediction accuracy. Hence, based on near-infrared spectra (900~1 700 nm) of 600 soil samples, the method for predicting soil total nitrogen (STN) content was investigated,and a Bidirectional Gated Recurrent Unit based on an Attention Mechanism (BiGRU-Attention) model was proposed. First, the spectral data quality was optimized using SG filtering and SNV preprocessing methods. Then, using the CARS feature selection algorithm, the wavelengths for modeling were reduced from 198 to 30, thereby removing redundant information and decreasing the complexity of the modeling process. The BiGRU-Attention model effectively manages the flow of information using update and reset gates and enables the model to disregard the unimportant spectral data and retain the key information, which impacts the prediction accuracy. By leveraging the dual temporal sequence processing advantages of bidirectional GRU, the model can simultaneously handle forward and backward inputs of spectral sequences, thereby enhancing its ability to focus on edge data and comprehensively capture the dependencies present in soil spectral data. Additionally, the model employs an attention layer to compute the importance of each segment using the QKV matrix and dynamically determines which features should be emphasized based on the sequential interdependencies. This process calculates attention weight matrices to assign weights to each input data point, generating a more relevant context matrix that improves the model's predictive accuracy. Experimental results show that the BiGRU-Attention model can better understand the correlation between bands and perform better in prediction than other models, with the spectral data achieving an R2 of 0.87 and an RMSE of 0.20 g·kg-1 on the test dataset after feature selection. This study provides technical support for rapid soil nutrient detection and offers a method and reference for establishing high-accuracy STN prediction models.
剧伟良,杨 玮,宋亚美,刘 楠,李 浩,李民赞. 基于注意力机制的BiGRU土壤光谱全氮预测模型研究[J]. 光谱学与光谱分析, 2025, 45(07): 2017-2025.
JU Wei-liang, YANG Wei, SONG Ya-mei, LIU Nan, LI Hao, LI Min-zan. Prediction of Soil Total Nitrogen Based on NIR Spectroscopy and BiGRU Model With Attention Mechanism. SPECTROSCOPY AND SPECTRAL ANALYSIS, 2025, 45(07): 2017-2025.
[1] BAI Zi-jin, PENG Jie, LUO De-fang, et al(白子金,彭 杰,罗德芳,等). Spectroscopy and Spectral Analysis(光谱学与光谱分析), 2022, 42(9): 2768.
[2] GAO Fei, CHEN Su-xian, DU Xiao-yu, et al(高 飞,陈素贤,杜晓玉,等). Tianjin Agricultural Sciences(天津农业科学), 2022, 28(9): 76.
[3] CHEN Hao-yu, XIANG Lei, GAO He, et al(陈昊宇,项 磊,高 贺,等). Remote Sensing for Natural Resources (自然资源遥感), 2023, 35(3): 170.
[4] ZHANG Xi-yu, LI Si-jia, WANG Xiang, et al(张锡煜,李思佳,王 翔,等). Transactions of the Chinese Society of Agricultural Engineering(农业工程学报), 2023, 39(15): 144.
[5] ZHANG Ke-di, GUO Hong-yun, SHAO Na, et al(张珂迪,郭洪云,邵 娜,等). Journal of Anhui Agricultural University(安徽农业大学学报), 2023, 50(6): 917.
[6] HUANG Ye-chang, ZENG Wei, DENG Li-zhang, et al. (黄业昌,曾 玮,邓力章,等). Journal of Zhejiang Agricultural Sciences (浙江农业科学), 2024, 65(3): 536.
[7] ZHOU Xu-dong, SHEN Yun-xin, PU Yong-yu, et al(周旭东,申云鑫,濮永瑜,等). Jiangsu Agricultural Sciences (江苏农业科学), 2024, 52(4): 231.
[8] TANG Ao-hua, YANG Gui-jun, YANG Yue, et al(唐澳华,杨贵军,杨 悦,等). Transactions of the Chinese Society for Agricultural Machinery(农业机械学报), 2024, 55(8): 382.
[9] Metzger K, Bragazza L. European Journal of Soil Science, 2024, 75(3): e13508.
[10] Sitorus A, Lapcharoensuk R. Sensors, 2024, 24(7): 2362.
[11] ZHOU Peng, KONG Yi-nuo, HAO Shan-shan, et al(周 鹏,孔一诺,郝珊珊,等). Transactions of the Chinese Society of Agricultural Engineering(农业工程学报), 2024, 40(16): 113.
[12] WEI Qing, LI Chang-yu, XU Meng-cao, et al(卫 青,李长昱,许孟操,等). Journal of Anhui Agricultural Sciences (安徽农业科学), 2023, 51(8): 6.
[13] Khammao P, Rattanapichai W, Pitakdantham R, et al. Soil Science and Plant Nutrition, 2024, 70(3): 197.
[14] QIN Wen-hu, DONG Kai-yue, DENG Zhi-chao(秦文虎,董凯月,邓志超). Soils(土壤), 2023, 55(6): 1347.
[15] HUANG Hai-xia, LI Yao-xiang, ZHANG Zhe-yu(黄海霞,李耀翔,张哲宇). Forest Engineering(森林工程), 2023, 39(6): 164.
[16] Tan A, Wang Y, Zhao Y, et al. Spectrochimica Acta Part A: Molecular and Biomolecular Spectroscopy, 2022, 283: 121759.
[17] Bai L, Zhang Z T, Guan H, et al. Talanta, 2024, 275: 126098.
[18] Zeng W, Qiu Y, Huang Y, et al. Journal of Innovative Optical Health Sciences, 2022, 15(4): 2250022.
[19] Bai Z, Chen S, Hong Y, et al. Geoderma, 2023, 437: 116589.
[20] Wang Y, Chen S, Hong Y, et al. Computers and Electronics in Agriculture, 2023, 212: 108067.
[21] Yuan Q, Wang J, Zheng M, et al. Construction and Building Materials, 2022, 350: 128799.
[22] Ji X, Huang H, Chen D, et al. Buildings, 2023, 13(1): 72.
[23] MAO Bai-hai, QIN Wu, XIAO Xian-bin, et al(毛百海,覃 吴,肖显斌,等). Energy Storage Science and Technology(储能科学与技术), 2023, 12(11): 3519.
[24] Pan S, Yang B, Wang S, et al. Energy, 2023, 284: 128701.
[25] Guo X, He J, Wang B, et al. Remote Sensing, 2022, 14(19): 4737.
[26] Kong F, Li J, Jiang B, et al. IEEE Transactions on Industrial Informatics, 2023, 19(1): 541.
[27] WANG Wei-chao, YANG Wei, CUI Yu-lu, et al(王炜超,杨 玮,崔玉露,等). Transactions of the Chinese Society for Agricultural Machinery(农业机械学报), 2021, 52(S1): 316.
[28] CAO Yong-yan, YANG Wei, WANG Dong, et al(曹永研,杨 玮,王 懂,等). Transactions of the Chinese Society for Agricultural Machinery (农业机械学报), 2022, 53(S1): 241.