Visible and near-infrared spectroscopy-based soil detection system and method based on front-end decoupling computation

By using a front-end decoupled computation visible and near-infrared spectroscopy soil detection system, and by utilizing a JSON model serialization protocol and a standardized parameter mapping algorithm, the spectral prediction model is transferred from the back-end to the front-end. This solves the problem of rigid spectral detection processes and enables efficient and convenient soil property detection.

CN123111968APending Publication Date: 2026-11-17HUBEI FORBON TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611231090.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-14
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In the current field of nondestructive testing, spectral prediction models cannot run independently of the original software. The rigid process leads to complex hardware and software deployment, low prediction efficiency, and difficulty in achieving high-precision detection directly on the user side.

Method used

A visible and near-infrared spectroscopy soil detection system based on front-end decoupled computation is adopted. By using the JSON model serialization protocol and standardized parameter mapping algorithm, the spectral prediction model is transferred from the back end to the front end, realizing seamless model portability and dynamic reconfigurable preprocessing. Soil property prediction is performed by combining the PLSR model and the BPNN model.

Benefits of technology

It enables convenient operation of spectral detection, improves the reusability and scalability of the tool, breaks through the limitation of tight coupling between the algorithm and the operating environment of traditional spectral analysis tools, and improves detection efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123111968A_ABST
    Figure CN123111968A_ABST
Patent Text Reader

Abstract

This invention discloses a visible and near-infrared spectral soil detection system and method based on front-end decoupled computation. By constructing a cloud-based algorithm plugin interface and a JSON model serialization protocol, it achieves hot-swappable preprocessing algorithms and nutrient prediction models, eliminating the reliance on the traditional back-end of spectral prediction. The system includes: a data import and dimensional adaptive calibration module, which heuristically identifies the spectral matrix and performs adaptive calibration; a preprocessing algorithm pipeline module, which has preprocessing algorithm nodes built into the cloud and generates execution queues according to instructions, completing the process in a WebWorker multi-threaded environment; a model decoupled inference engine module, which defines and parses JSON-formatted pre-trained model description files, performs spectral data mapping, constructs the spectral matrix in real time in the cloud, and calculates prediction results; an interactive spectral data visualization and evaluation module, which displays the spectrum through incremental rendering; and a localized report generation module, which uses the SheetJS and jsPDF libraries to assemble report files, completing a closed-loop process from spectral data import to nutrient prediction report output.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the interdisciplinary field of spectral analysis, agricultural information technology and front-end computing, specifically to a visible and near-infrared (Vis-NIR) soil property detection platform architecture and method that does not require a back-end server and supports dynamic mounting of multi-source models and adaptive preprocessing. Background Technology

[0002] In the current field of nondestructive testing, spectral prediction models (such as PLSR and BPNN) are mostly implemented using hard-coding and deeply bound to MATLAB or Python environments, making them unable to run independently of the original software and resulting in a rigid workflow. For example, CN121561662B discloses a method and detection system for constructing a seed vigor prediction model based on spectral indices. This method relies on extracting spectral indices of different dimensions to construct multiple linear regression and random forest models. This method depends on the backend and requires the deployment and maintenance of dedicated model code to receive and calculate spectral data, making it difficult to popularize and directly perform predictions on the user side. Similarly, CN121582925B discloses a method and system for reconstructing hyperspectral data and predicting the internal quality of fruit by constructing a special multi-task deep learning master model that includes a shared encoder, a spectral reconstruction head, and a quality prediction head. This backend-heavy architecture brings several prominent problems: hardware and software deployment; the need to re-divide dimensions and call the model for each spectral data calculation, resulting in transmission delays; and low prediction efficiency. Therefore, how to achieve high-precision and robust visible and near-infrared spectral detection for objects while coordinating the entire spectral detection process is a problem that urgently needs to be solved.

[0003] The project of an automated intelligent soil detection system based on multi-source spectral fusion deep learning aims to break through the limitations of traditional wet chemical analysis methods for soil detection, which are time-consuming and inefficient, and to overcome the technical barriers of existing spectral soil detection. It utilizes the JSON model serialization protocol to extract the core parameters of the spectral prediction model, unifies the detection steps into a single system, and shifts the core technology of spectral detection from the back end to the front end, achieving convenient "one-click" spectral soil sample detection. Summary of the Invention

[0004] This invention aims to provide a visible and near-infrared spectroscopy soil detection system and method based on front-end decoupled computation. By designing a JSON model serialization protocol and a standardized parameter mapping algorithm, it achieves seamless porting of the soil property prediction model from the back end to the front end; and by constructing a dynamic and reconfigurable preprocessing pipeline, it solves the problem of rigid spectral analysis process.

[0005] The present invention adopts the following technical solution: A visible-near-infrared spectroscopy soil detection system based on front-end decoupled computation is characterized by comprising the following modules: Data import and dimensional adaptive calibration module: Receives raw spectral data uploaded by users and generates a spectral matrix. It determines the dimensional type of the spectral matrix through heuristic rules and completes the standardization of the spectral matrix. Arrangeable preprocessing algorithm pipeline module: Provides a visual pool of spectral matrix preprocessing algorithms, enabling flexible activation of spectral matrix preprocessing algorithms and configuration of parameters, utilizes web workers to increase the fault tolerance of the spectral matrix pipeline computation flow, and outputs the preprocessed spectral matrix; Model decoupling inference engine module: Defines and parses the JSON serialization protocol of the standardized model that has been trained in the backend. Taking PLSR model and BPNN model as examples, import the trained PLSR model or BPNN model to form the model library in the system, input the preprocessed spectral matrix for calculation, and use tansig to inverse normalize the prediction results into soil nutrient prediction values, thereby realizing fast inference of multiple models and outputting soil attribute prediction values. Interactive Spectral Data Visualization and Evaluation Module: Based on Canvas and Chart.js, the module renders the input spectral data and corresponding labels, displays the differences between different bands of the data, automatically calculates the evaluation index of the standardized model, and realizes real-time verification and display of prediction accuracy.

[0006] The visible and near-infrared spectroscopy soil detection system based on front-end decoupling calculation of the present invention further includes: The localized report generation module is a file assembly function that does not rely on a server. It exports standardized model prediction result tables through SheetJS and uses jsPDF to generate PDF reports containing full-band spectral images and prediction result tables, meeting diverse local archiving needs.

[0007] The detection method of the visible and near-infrared spectroscopy soil detection system based on front-end decoupling calculation is characterized by the following steps: S1: Receive spectral data uploaded by the user, parse it to obtain a spectral matrix. The spectral data is a file containing spectral reflectance data of soil samples. The dimensional type of the spectral matrix is ​​identified based on heuristic rules. When it is determined to be the decimal representation of the reflectance of the original spectral data, a linear scaling transformation of a preset multiple is automatically performed to obtain the calibrated spectral matrix. S2: The processed spectral matrix is ​​fed into a pipelined preprocessing algorithm node pool, which contains various spectral preprocessing algorithm nodes; in response to the user's selection of node activation, parameter configuration, and sequential arrangement, a corresponding preprocessing execution queue is generated; the calibrated spectral matrix is ​​used as input, and each algorithm node is executed sequentially according to the arrangement order of the nodes in the preprocessing execution queue, and the preprocessed spectral matrix is ​​output. S3: In the backend development software, a soil nutrient prediction model is trained using a soil spectral dataset and soil nutrient chemical values. The standardized parameter set from the soil nutrient prediction model is extracted and packaged into a JSON description file. Subsequently, the model type label and the standardized parameter set corresponding to the model type are parsed in the description file in the cloud. The model type label and the standardized parameter set are stored in the model database in the browser's memory. The target models in the model database include Partial Least Squares (PLSR) and Backpropagation Neural Network (BPNN). S4: Based on the target model selection instruction, extract the corresponding standardized parameter set from the model database; input the preprocessed spectral matrix into the target model in memory; perform standardized mapping and forward inference operations on the preprocessed spectral matrix in the cloud using the standardized parameter set; use the tansig activation function to inversely normalize the model database to predict the soil nutrients, obtain the nutrient prediction values ​​of the soil sample corresponding to the spectral matrix, export the spectral chart of the prediction results using SheetJS, and obtain a localized soil attribute prediction report using jsPDF.

[0008] The specific method for identifying the dimensional type of the spectral matrix based on heuristic rules is as follows: extract the numerical values ​​of sample wavelength points in the spectral matrix and calculate local maxima; if the local maxima are less than a preset first threshold, determine that the current data is the reflectance of the original spectral data in the 0-1 interval and perform a global linear transformation multiplied by 100; if the local maxima are greater than or equal to the first threshold, keep the reflectance of the original spectral data unchanged and mark it as directly usable.

[0009] When the model type is partial least squares (PLSR), the standardized parameter set is used in the cloud to perform standardized mapping and forward inference operations on the preprocessed spectral matrix. Specifically, the mean vector of independent variables mu_x, the standard deviation vector of independent variables sig_x, the mean of dependent variables mu_y, the standard deviation of dependent variables sig_y, and the regression coefficient vector are extracted from the JSON description file. The target spectral matrix is ​​standardized band by band according to the formula xstd=(x-mu_x) / sig_x; the standardized spectral matrix is ​​then multiplied by the regression coefficient vector; the dot product result is then destandardized to the predicted soil property value according to the formula y=ystd×sig_y+mu_y.

[0010] When the model type is a backpropagation neural network (BPNN), the preprocessed spectral matrix is ​​subjected to normalization mapping and forward inference operations in the cloud using a normalized parameter set. Specifically, the weight matrix, bias vector, and input / output extrema of each network layer are extracted from the JSON description file; the target spectral matrix is ​​linearly mapped to the [-1,1] interval using the input extrema; matrix multiplication operations containing the tansig activation function are performed layer by layer, where the tansig activation function is defined as f(x)=2 / (1+e-2x)-1, and the input x is limited to prevent overflow; the original output of the output layer is linearly mapped back to the physical dimension space using the output extrema.

[0011] The preprocessing algorithm node pool contains various spectral preprocessing algorithm nodes. The execution process includes: dynamically constructing a Vandermonde matrix in the cloud according to the set window size and polynomial order; using the Gauss-Jordan elimination method to invert the normal equation matrix of the Vandermonde matrix by selecting all pivots to obtain the convolution coefficient vector; and using the convolution coefficient vector to perform sliding window convolution calculation on the spectral data.

[0012] The preprocessing algorithm node pool contains 9 spectral preprocessing algorithm nodes, namely: Moving Average Smoothing, Savitzky-Golay (SG) Convolutional Smoothing, First Derivative, Second Derivative, Standard Normal Transform (SNV), Multivariate Scattering Correction (MSC), Min-Max Normalization, Mean Centering, and Detrend Correction.

[0013] The beneficial effects of this invention lie in breaking through the limitations of the tight coupling between algorithms and operating environments in traditional spectral analysis tools. Existing soil spectral prediction methods typically utilize function packages or scripts in programming languages, hardcoding preprocessing and models into the code flow. Changing algorithms and debugging models requires modifying the source code and redeploying the model, which increases complexity. This invention uses standardized plugin description files, enabling "hot-swappable" algorithm modules, greatly improving the reusability and scalability of the tool. Attached Figure Description

[0014] Figure 1 This is a schematic diagram of the method flow of the present invention.

[0015] Figure 2 This is a schematic diagram of the system modularization of the present invention. Detailed Implementation

[0016] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0017] like Figure 2 As shown, the visible and near-infrared spectroscopy soil detection system based on front-end decoupled computation is characterized by comprising the following modules: Data import and dimensional adaptive calibration module: Receives raw spectral data uploaded by users and generates a spectral matrix. It determines the dimensional type of the spectral matrix through heuristic rules and completes the standardization of the spectral matrix. Arrangeable preprocessing algorithm pipeline module: Provides a visual pool of spectral matrix preprocessing algorithms, enabling flexible activation of spectral matrix preprocessing algorithms and configuration of parameters, utilizes web workers to increase the fault tolerance of the spectral matrix pipeline computation flow, and outputs the preprocessed spectral matrix; Model decoupling inference engine module: Defines and parses the JSON serialization protocol of the standardized model that has been trained in the backend. Taking PLSR model and BPNN model as examples, import the trained PLSR model or BPNN model to form the model library in the system, input the preprocessed spectral matrix for calculation, and use tansig to inverse normalize the prediction results into soil nutrient prediction values, thereby realizing fast inference of multiple models and outputting soil attribute prediction values. Interactive spectral data visualization and evaluation module: Based on Canvas and Chart.js, the module renders the input spectral data and corresponding labels, displays the differences between different bands of the data, automatically calculates the evaluation index of the standardized model, and realizes the real-time verification and display of prediction accuracy. The localized report generation module is a file assembly function that does not rely on a server. It exports standardized model prediction result tables through SheetJS and uses jsPDF to generate PDF reports containing full-band spectral images and prediction result tables, meeting diverse local archiving needs.

[0018] Please see Figure 1 The present invention provides a detection method for a visible and near-infrared spectroscopy soil detection system based on front-end decoupling calculation, comprising the following steps: S1: Receive spectral data uploaded by the user, parse it to obtain a spectral matrix. The spectral data is a file containing spectral reflectance data of soil samples. The dimensional type of the spectral matrix is ​​identified based on heuristic rules. When it is determined to be the decimal representation of the reflectance of the original spectral data, a linear scaling transformation of a preset multiple is automatically performed to obtain the calibrated spectral matrix. S2: The processed spectral matrix is ​​fed into a pipelined preprocessing algorithm node pool, which contains various spectral preprocessing algorithm nodes; in response to the user's selection of node activation, parameter configuration, and sequential arrangement, a corresponding preprocessing execution queue is generated; the calibrated spectral matrix is ​​used as input, and each algorithm node is executed sequentially according to the arrangement order of the nodes in the preprocessing execution queue, and the preprocessed spectral matrix is ​​output. S3: In the backend development software, a soil nutrient prediction model is trained using a soil spectral dataset and soil nutrient chemical values. The standardized parameter set from the soil nutrient prediction model is extracted and packaged into a JSON description file. Subsequently, the model type label and the standardized parameter set corresponding to the model type are parsed in the description file in the cloud. The model type label and the standardized parameter set are stored in the model database in the browser's memory. The target models in the model database include Partial Least Squares (PLSR) and Backpropagation Neural Network (BPNN). S4: Based on the target model selection instruction, extract the corresponding standardized parameter set from the model database; input the preprocessed spectral matrix into the target model in memory; perform standardized mapping and forward inference operations on the preprocessed spectral matrix in the cloud using the standardized parameter set; use the tansig activation function to inversely normalize the model database to predict the soil nutrients, obtain the nutrient prediction values ​​of the soil sample corresponding to the spectral matrix, export the spectral chart of the prediction results using SheetJS, and obtain a localized soil attribute prediction report using jsPDF.

[0019] In one embodiment of this application, in step S1, the spectral data is a file containing spectral reflectance data of soil samples. Reflectance data in the wavelength range of 400-2500 nm is read, and outlier wavelengths are removed to construct a standard spectral feature matrix X in the visible and near-infrared range. n A total of 2100 wavelength points were collected, and the sample items within the matrix were self-encoded.

[0020] S1 also includes a mechanism for filtering the purity of the data source to prevent data contamination from causing subsequent calculations to stall. Specifically, the system's data adaptive module first checks the content of the first line of the file: if any cell in the first line contains non-numeric text characters, the first line is determined to be the header row, and spectral data parsing begins from the second line; if all cells in the first line are numerical, the first line is determined to be the spectral data for the first sample. This rule automatically extracts the first column of data as the sample name and extracts the numerical sequence from the second column onwards as the spectral reflectance data for that sample.

[0021] In step S1, the heuristic rule includes two methods for parsing spectral metadata: extracting the wavelength values ​​of the first 5% of samples and calculating local maxima. If the local maximum is less than a preset threshold, the current spectral data is determined to be a decimal representation of the original reflectance in the 0-1 interval. The module automatically triggers a global linear transformation multiplied by 100 to map all spectral values ​​to the percentage reflectance interval and injects a status marker "reflectance%" into the interface. If the local maximum is greater than or equal to the threshold, the original data remains unchanged, and the status marker "reflectance%" is injected. The spectrum is mapped and bound to the soil sample ID, and ECharts is used to render a comparison chart of the prediction results in the front-end drawing library. The document generation interface is called to inject the values ​​and images into a preset soil prediction result report template file stream.

[0022] In step S2, the spectral preprocessing algorithm node pool provides a pool of nine preprocessing algorithms after the spectral data enters the system's table. Each algorithm in the pool is implemented as an independent function unit with a unified input / output interface, receiving a two-dimensional numerical matrix and returning a matrix of the same dimension. The nine algorithm nodes include: Moving Average Smoothing, Savitzky-Golay (SG) Convolutional Smoothing, First Derivative, Second Derivative, Standard Normal Transform (SNV), Multivariate Scattering Correction (MSC), Min-Max Normalization, Mean Centering, and Detrend Correction. The SG Smoothing node allows users to configure window size and polynomial order parameters; the Moving Average Smoothing node also allows configuration of the window size parameter.

[0023] The system's dynamic preprocessing orchestration module presents the nine algorithm nodes on the user interface. Each node is configured with an independent enable / disable switch and parameter input box, and each node is provided with an up / down sorting button.

[0024] Users activate target algorithm nodes by clicking a switch, set algorithm execution parameters through parameter input boxes, and adjust the order of nodes in the preprocessing execution queue using sorting buttons. The orchestration module monitors user operations in real time, assembles all activated nodes into a preprocessing execution queue according to their current order, and synchronously displays the current execution chain on the interface in a chained text format: "Algorithm A → Algorithm B → Algorithm C".

[0025] When the system triggers the "execute" command, it first checks if an available WebWorker thread exists. If the Worker thread is available, the raw spectral data is serialized with the preprocessing execution queue and passed to the Worker thread for execution. If the Worker thread is unavailable or fails to initialize, execution reverts to the browser's main thread. Simultaneously, the system sets a timeout timer. If the Worker thread does not return a result within 30 seconds, the Worker is forcibly terminated, and execution reverts to the main thread to ensure system robustness.

[0026] In the pipelined computation process, the system takes the raw spectral data as input and, according to the order of nodes in the preprocessing execution queue, sequentially uses the output matrix of the current step as the input matrix of the next step, forming a pipelined stream computation. The specific implementation of each algorithm node is as follows: The SG convolution smoothing node dynamically constructs a Vandermonde matrix V of size win × (poly+1) on the browser side based on the user-defined window size (win) and polynomial order (poly), where V ij =i j (i=0,1,...,win-1; j=0,1,...,poly). The nodes calculate the transpose matrix V of V. T Construct the normal equation matrix A=V T V, using Gauss-Jordan elimination to perform full pivoting and inversion on matrix A, yields A. -1 Then calculate the convolution coefficient vector C=(A -1 V T The first row of the array. The node performs a sliding window convolution operation on the spectral data band by band using the convolution coefficient vector, and the boundaries at the window edges are handled by a symmetrical extension method.

[0027] The SNV node performs sample-by-sample standardization on each sample spectral vector x: it calculates the mean μ and standard deviation σ of the reflectance at all wavelengths of the sample and outputs (x-μ) / σ.

[0028] The MSC node first calculates the average spectral vector x̄ of all sample spectra at each wavelength point, and then calculates the average spectral vector x̄ of each sample spectral vector. _i The regression coefficient α is solved using the least squares method. _i and b _i Make x _i ≈a _i ·x̄+b _i Output the corrected spectrum (x _i -b _i ) / a _i .

[0029] The detrending node fits a polynomial trend line about the wavelength index to each sample spectral vector and subtracts the trend line from the original spectrum.

[0030] As one implementation of this application, in step S3, the system pre-defines a JSON model serialization protocol. This protocol defines a standardized storage format for all parameters required for migrating the trained soil nutrient prediction model from the backend training environment to the browser. The protocol defines different field structures for different types of models; for example, for PLSR and BPNN models: For the PLSR model, the JSON description file contains the following fields: model type identifier (type: "plsr"), model name (name), predicted attribute name (property), regression coefficient vector (coefficients, length is 2100 wavelength points), intercept (intercept), independent variable mean vector (mu_x, length is 2100), independent variable standard deviation vector (sig_x, length is 2100), dependent variable mean (mu_y), dependent variable standard deviation (sig_y), output unit (unit), and output name list (outputNames).

[0031] For the BPNN model, the JSON description file contains the following fields: model type identifier (type: "bpnn"), model name (name), predicted attribute name (property), input dimension (input_dim, fixed at 2100), list of network layer weight matrices (weights, each element is a two-dimensional array), list of bias vectors (biases, each element is a one-dimensional array), input extrema (xMin and xMax, representing the global minimum and maximum values ​​of the input data during training, respectively), output extrema (yMin and yMax, representing the global minimum and maximum values ​​of the output data during training, respectively), and output unit (unit).

[0032] In step S3, after the user uploads the JSON description file via the file selector, the system's model decoupling inference engine performs the following parsing and verification process: (1) Read and parse the contents of the JSON file and extract the model type identifier field.

[0033] (2) Perform dimension verification: If the model type is PLSR, check whether the length of the regression coefficient vector is consistent with the number of wavelength points preset by the system. If they are inconsistent, refuse to load and prompt that the dimension is mismatched. If the model type is BPNN, check whether the input dimension field (input_dim) is consistent with the number of wavelength points preset by the system. If they are inconsistent, refuse to load and prompt that the dimension is mismatched.

[0034] (3) After the verification is successful, the complete model object obtained by parsing is stored in the model database in the browser memory, and an index is created with the model unique identifier as the key.

[0035] (4) Render the summary card of the model in the model library panel of the user interface, including the model name, model type label, predicted attribute name and output quantity.

[0036] When multiple loaded models trigger prediction commands, the model decoupled inference engine performs forward inference according to the following process: Data preparation phase: The engine determines whether a user-selected spectral wavelength range exists (selected using the spectral range selection tool described later). If a selected range exists, the corresponding wavelength index range is located based on the start and end wavelength values ​​of the range, and the corresponding column submatrix is ​​extracted from the preprocessed spectral matrix as model input; if no selected range exists, the complete preprocessed spectral matrix is ​​used as model input.

[0037] PLSR Model Inference: For models labeled PLSR, the engine extracts the mu_x vector, sig_x vector, coefficients vector, intercept value, mu_y, and sig_y from the JSON description file. For each spectral vector x of the sample to be predicted, the following three mathematical mapping steps are performed: Calculate x_std per wavelength point j =(x j -mu_x j ) / sig_x j This yields the standardized spectral vector; Calculate the score: score = Σ(x_std) j ×coefficients j )+intercept; The inverse standardized prediction value y_pred is calculated as score × sig_y + mu_y. The mu_x, sig_x, coefficients, mu_y, and sig_y used in the above four steps are all derived from JSON files exported from the MATLAB training environment. This ensures that the mathematical transformation path of the front-end inference is completely consistent with the data preprocessing path during MATLAB training, achieving lossless mapping of the standardized parameters.

[0038] BPNN Model Inference: For models labeled BPNN, the engine extracts the weight matrix W of each network layer from the JSON description file. l Bias vector b l Input extreme value x Min and x Max Output extreme value yMin and y Max For each spectral vector x of the sample to be predicted, perform the following inference process: (1) Linearly map each component of the spectral vector to the interval [-1, 1] using the input extrema: x_mapped j =2×(x j -x Min ) / (x Max -x Min )-1 (2) Perform matrix multiplication and tansig activation layer by layer from the first hidden layer to the output layer: z l =W l ·a {l-1} +b l a l =tansig(z l ) The tansig function is defined as tansig(z) = 2 / (1 + e^{-2z}) - 1, and the input z components are truncated (to the interval [-700, +700]) before calculation to prevent exponential overflow. (3) For the original output of the output layer, use the output extrema to perform inverse normalization and map it back to the physical dimension space: y_pred=(a_out+1) / 2×(y Max -y Min )+y Min Multi-model fusion inference: When multiple models are selected simultaneously, the system automatically enters multi-model fusion mode. The system assigns an equal-weighted fusion weight w_i = 1 / K to each selected model, where K is the number of selected models. The weights of each model can be manually adjusted by dragging a slider. The fused prediction value is calculated using the weighted average formula: y_fused = Σ(w_i = 1 / K). i ×y_pred i ) / Σw i The fusion results are displayed as a separate row in the prediction results table, and the model type is marked as weighted fusion.

[0039] In step S4, after executing the above algorithm chain on the spectral file in the input system, the system automatically calculates four model evaluation metrics according to the following formula to verify the accuracy of the prediction results of the built-in JSON model: (1) Coefficient of determination R 2 =1-Σ(y i -ŷ i ) 2 / Σ(y i -ȳ)2 , where y i These are measured values. i ȳ is the predicted value, and ȳ is the average of the measured values; (2) Root mean square error RMSE = √(Σ(y i -ŷ i ) 2 / n), where n is the number of samples; (3) Mean Absolute Error (MAE) = Σ|y i -ŷ i | / n; (4) Relative analysis error RPD = SD / RMSE, where SD = √(Σ(y i -ȳ) 2 / (n-1)) is the standard deviation of the measured value.

[0040] The system displays the four indicators along with the predicted and measured values ​​of each sample in the same table, and uses color-coded annotations to mark the deviations between the predicted and measured values ​​according to the RMSE threshold.

[0041] The system's interactive spectral data visualization and evaluation module is built on the HTML5 Canvas element and the Chart.js chart library, providing the following four types of spectral interactive functions: The system supports multi-view rendering of spectral curves, including three view modes: original spectrum view, preprocessed spectrum view, and original / preprocessed comparison view. Users can switch between these three modes via a view switching tab. The visualization module employs an incremental rendering strategy: wavelength points within the current zoom level and visible range participate in the construction of the chart dataset; wavelength points outside the visible range are not added to the rendering pipeline. When the user drags and zooms the chart, the system dynamically updates the visible wavelength point index and reconstructs the rendering dataset.

[0042] The system renders sample label bars above the spectral chart, enabling multi-sample selection and linked highlighting. Each label corresponds to a soil sample. Users can click on a label to toggle the selected sample's status. The spectral curves of the selected samples are overlaid and rendered in real-time on the same spectral chart, with different samples distinguished by different colors. When a user hovers over or clicks on a data point on the spectral curve, the system retrieves the wavelength and sample index of the current data point through the Chart.js tooltip callback function and simultaneously highlights the corresponding row in the data table.

[0043] The system offers a bounding box selection mode: after activating this mode, the user drags the mouse on the spectral chart to define a rectangular selection area. The system records the start and end wavelength values ​​corresponding to the selection area. The selected wavelength interval is rendered as a semi-transparent rectangle overlaid on the spectral chart background via the Chart.js custom plugin's afterDraw hook. Users can define multiple non-overlapping wavelength intervals, and interval labels are displayed as a label bar above the chart. During prediction, users can choose to restrict the model input to spectral data within the selected wavelength interval, enabling directional modeling of characteristic bands.

[0044] The system includes a draggable resize handle at the bottom of the spectral chart area to ensure the uploaded soil sample spectral images display correctly across different user interfaces. Users can dynamically adjust the vertical height of the chart canvas by dragging the handle, with the height limited to between 200 pixels and 80% of the browser viewport height. During dragging, the `resize()` method of the `Chart.js` instance is called in real-time to redraw the chart.

[0045] The system's local report generation module completes all report assembly and file generation operations within the browser's memory, without sending data to any remote server. The export module provides the following four output formats: The system creates a Workbook object in the browser's memory using the SheetJS library. After exporting the preprocessed spectral matrix, the system organizes the preprocessed spectral samples into a two-dimensional array by concatenating the spectral matrix of wavelength points with the wavelength value rows. Then, it calls the XLSX.utils.aoa_to_sheet command line to convert the two-dimensional array into a worksheet object, and finally calls the XLSX.writeFile command line to trigger the browser's report file download function. After obtaining the soil nutrient prediction model from the model decoupling inference engine module, the system extracts the sample name, measured value, predicted values ​​from each model, and four evaluation indicators from the prediction results, integrates them into a structured table, and then executes the same process described above.

[0046] The system creates a PDF document object in the browser's memory using the jsPDF library. In full report export mode, the system first calls the toBase64Image method of the Chart.js instance to convert the current spectral image into a Base64 encoded PNG image, which is then embedded in the PDF as a page header. Next, the jsPDF-autotable plugin is called to render the prediction results table as a table block within the PDF page. Finally, four model evaluation metrics and a report generation timestamp are appended as text paragraphs below the table. The generated PDF is then serialized using a Blob object, triggering the browser download.

[0047] The system calls the toDataURL() method of the Chart.js canvas to get the Base64 data URL of the current spectrum view, creates a temporary anchor element, and triggers the download when clicked.

[0048] The system assembles the current spectral chart Base64 image, the prediction result table HTML fragment, and the evaluation index data into a complete self-contained HTML document string, and triggers download after serialization using the Blob and URL.createObjectURL methods.

[0049] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.

[0050] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

Claims

1. A visible-near-infrared spectroscopy soil detection system based on front-end decoupled computation, characterized in that, Includes the following modules: Data import and dimensional adaptive calibration module: Receives raw spectral data uploaded by users and generates a spectral matrix. It determines the dimensional type of the spectral matrix through heuristic rules and completes the standardization of the spectral matrix. Arrangeable preprocessing algorithm pipeline module: Provides a visual pool of spectral matrix preprocessing algorithms, enabling flexible activation of spectral matrix preprocessing algorithms and configuration of parameters, utilizes WebWorker to increase the fault tolerance of the spectral matrix pipeline computation flow, and outputs the preprocessed spectral matrix; Model decoupling inference engine module: Defines and parses the JSON serialization protocol of the standardized model that has been trained in the backend. Taking PLSR model and BPNN model as examples, import the trained PLSR model or BPNN model to form the model library in the system, input the preprocessed spectral matrix for calculation, and use tansig to inverse normalize the prediction results into soil nutrient prediction values, thereby realizing fast inference of multiple models and outputting soil attribute prediction values. Interactive Spectral Data Visualization and Evaluation Module: Based on Canvas and Chart.js, the module renders the input spectral data and corresponding labels, displays the differences between different bands of the data, automatically calculates the evaluation index of the standardized model, and realizes real-time verification and display of prediction accuracy.

2. The visible and near-infrared spectroscopy soil detection system based on front-end decoupling calculation according to claim 1, characterized in that, Also includes: Localized report generation module: Exports standardized model prediction result tables via SheetJS and generates PDF reports containing full-band spectral images and prediction result tables using jsPDF, meeting diverse local archiving needs.

3. The detection method of the visible and near-infrared spectroscopy soil detection system based on front-end decoupling calculation according to claim 1 or 2, characterized in that, Includes the following steps: S1: Receive spectral data uploaded by the user, parse it to obtain a spectral matrix. The spectral data is a file containing spectral reflectance data of soil samples. The dimensional type of the spectral matrix is ​​identified based on heuristic rules. When it is determined to be the decimal representation of the reflectance of the original spectral data, a linear scaling transformation of a preset multiple is automatically performed to obtain the calibrated spectral matrix. S2: The processed spectral matrix is ​​fed into a pipelined preprocessing algorithm node pool, which contains various spectral preprocessing algorithm nodes; in response to the user's selection of node activation, parameter configuration, and sequential arrangement, a corresponding preprocessing execution queue is generated; the calibrated spectral matrix is ​​used as input, and each algorithm node is executed sequentially according to the arrangement order of the nodes in the preprocessing execution queue, and the preprocessed spectral matrix is ​​output. S3: In the backend development software, use the soil spectral dataset and soil nutrient chemical values ​​to train the soil nutrient prediction model, and extract the standardized parameter set from the soil nutrient prediction model and package it into a JSON format description file; Subsequently, the model type labels and the standardized parameter sets corresponding to the model types in the description file are parsed in the cloud; the model type labels and standardized parameter sets are stored in the model database in the browser's memory. The target models in the model database include Partial Least Squares (PLSR) and Backpropagation Neural Network (BPNN). S4: Based on the target model selection instruction, extract the corresponding standardized parameter set from the model database; input the preprocessed spectral matrix into the target model in memory; perform standardized mapping and forward inference operations on the preprocessed spectral matrix in the cloud using the standardized parameter set; use the tansig activation function to inversely normalize the model database to predict the soil nutrients, obtain the nutrient prediction values ​​of the soil sample corresponding to the spectral matrix, export the spectral chart of the prediction results using SheetJS, and obtain a localized soil attribute prediction report using jsPDF.

4. The method according to claim 3, characterized in that, The specific method for identifying the dimensional type of the spectral matrix based on heuristic rules is as follows: extract the numerical values ​​of sample wavelength points in the spectral matrix and calculate local maxima; if the local maxima are less than a preset first threshold, determine that the current data is the reflectance of the original spectral data in the 0-1 interval and perform a global linear transformation multiplied by 100; if the local maxima are greater than or equal to the first threshold, keep the reflectance of the original spectral data unchanged and mark it as directly usable.

5. The method according to claim 3, characterized in that, When the model type is partial least squares (PLSR), the standardized parameter set is used in the cloud to perform standardized mapping and forward inference operations on the preprocessed spectral matrix. Specifically, the mean vector of independent variables mu_x, the standard deviation vector of independent variables sig_x, the mean of dependent variables mu_y, the standard deviation of dependent variables sig_y, and the regression coefficient vector are extracted from the JSON description file. The target spectral matrix is ​​standardized band by band according to the formula xstd=(x-mu_x) / sig_x; the standardized spectral matrix is ​​then multiplied by the regression coefficient vector; the dot product result is then destandardized to the predicted soil property value according to the formula y=ystd×sig_y+mu_y.

6. The method according to claim 3, characterized in that, When the model type is a backpropagation neural network (BPNN), the preprocessed spectral matrix is ​​subjected to normalization mapping and forward inference operations in the cloud using a normalized parameter set. Specifically, the weight matrix, bias vector, and input / output extrema of each network layer are extracted from the JSON description file; the target spectral matrix is ​​linearly mapped to the [-1,1] interval using the input extrema; matrix multiplication operations containing the tansig activation function are performed layer by layer, where the tansig activation function is defined as f(x)=2 / (1+e-2x)-1, and the input x is limited to prevent overflow; the original output of the output layer is linearly mapped back to the physical dimension space using the output extrema.

7. The method according to claim 3, characterized in that, The preprocessing algorithm node pool contains 9 spectral preprocessing algorithm nodes, namely: Moving Average Smoothing, Savitzky-Golay (SG) Convolutional Smoothing, First Derivative, Second Derivative, Standard Normal Transform (SNV), Multivariate Scattering Correction (MSC), Min-Max Normalization, Mean Centering, and Detrend Correction.

Citation Information

Patent Citations

  • A method and detection system for seed vigor prediction model based on spectral indices

    CN121561662B

  • A method and system for reconstructing hyperspectral data and predicting the internal quality of fruit.

    CN121582925B