Ginseng tablet production area tracing method and device based on spectral analysis
Patent Information
- Application Number
- CN202610906197.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-23
- Publication Date
- 2026-09-29
AI Technical Summary
[0005]现有方案大多将产地识别、选种识别、生长年限识别作为彼此独立的单任务处理,各任务分别训练独立模型,数据利用率低,且在多任务存在相关性时未能利用任务间的统计关联,在标签为无序类别变量时若以Pearson相关系数构建任务相关性矩阵则因依赖整数编码顺序而引入人为偏差
[0085]第一、本发明设计了步骤S1,基于双相机标定参数的VNIR波段高光谱反射图像和SWIR波段高光谱反射图像帧同步采集与配准拼接方法,以及步骤S3,以反映人参片切面组织结构差异的多波段构造区域分割特征图并配合平均径向距离约束的区域分割方法。步骤S1通过对双相机进行内参标定、外参标定、单应性变换、空间分辨率重采样、波长轴一致化以及响应一致性校正,使最终拼接得到的原始高光谱图像在同一切面坐标系下覆盖可见光至短波红外的连续宽波段,为后续算法提供包含人参皂苷在多个特征吸收带上的完整化学判别证据并消除拼接处的光谱阶跃;步骤S3以对水分含量敏感的1450 nm波段反射率与对C-H键含量敏感的1690 nm波段反射率堆叠构成多维分割特征向量,联合刻画各解剖学区域的化学组成差异,并以人参片切面由外向内的解剖拓扑先验为依据,按平均径向距离由远至近将各聚类簇标定为外皮区、韧皮区、形成层、木质部,使分割结果与真实解剖结构形成稳定对应。由此带来的有益效果是,本发明对薄层、低对比度的形成层这一关键解剖结构的分割稳定性较单波段K-means方法明显改善,且降低了切片厚度差异、干燥度差异以及外界杂散光对采集和分割结果的扰动,从而在源头上保证后续多区域光谱矩阵具有稳定的判别力。
Smart Images

Figure CN122840964A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of spectral analysis and traceability technology of Chinese medicinal materials, specifically involving a method and equipment for tracing the origin of ginseng slices based on spectral analysis. Background Technology
[0002] Ginseng, a traditional and precious Chinese medicinal herb, is widely used in clinical medicine, health foods, and functional cosmetics. However, the value of ginseng varies significantly due to differences in geographical location, soil and climate, cultivation methods, and growth years. Ginseng from different origins, selected varieties, and with different growth years exhibits variations in saponin chemical composition, content, and effective component ratios, leading to substantial differences in value. In actual distribution, the supply chain for ginseng is long, from raw materials to processed slices and finally to finished products. This often results in the misrepresentation of ginseng by ordinary cultivated ginseng, younger ginseng by older ginseng, and ginseng from non-authentic producing areas by authentic producing areas, impacting the brand value and industry order of authentic medicinal materials. Therefore, establishing a rapid, non-destructive, and objective method for simultaneously identifying the origin, selection, and growth years of ginseng slices is of practical significance for the authentication and quality traceability of the ginseng industry.
[0003] Currently, existing technologies related to the identification of ginseng origin, selection, and growth years can be broadly categorized into four types: chromatographic analysis, single-band near-infrared spectroscopy, single hyperspectral analysis, and traditional pattern recognition based on artificial features. Chromatographic analysis, represented by high-performance liquid chromatography (HPLC), ultra-high-performance liquid chromatography coupled with mass spectrometry (UHPLC-MS / MS), identifies ginseng by measuring the content of ginsenoside marker components. However, this technology requires pulverizing, extracting, and analyzing ginseng slices, resulting in complex pretreatment processes, long single-sample measurement times, and high requirements for instruments and operators, making it unsuitable for applications in the industry chain involving large sample volumes and requiring rapid processing. Single-band near-infrared spectroscopy uses visible-near-infrared or short-wave infrared single-band cameras to acquire surface spectra and combines them with linear models such as principal component analysis and partial least squares discriminant analysis for identification. While simpler to operate than chromatographic methods, it has limitations in terms of band coverage, feature dimensions, and utilization of anatomical structural information. While single hyperspectral analysis introduces spatial information from the image dimension, it typically only classifies ginseng slices by taking the average spectrum of the entire slice, ignoring the differences in chemical composition among the four anatomical regions of the ginseng slice—outer skin, phloem, cambium, and xylem—from the outside in, thus wasting discriminative power. Traditional pattern recognition based on artificial features relies on manually designed morphological or textural features, which are highly dependent on the consistency of sample preparation and the experience of the operator, limiting its generalization ability.
[0004] From an engineering perspective, existing technologies mostly employ single-band cameras for data acquisition, which cannot fully cover the multiple characteristic absorption bands of ginsenoside glycosides distributed in the visible-near-infrared and short-wave infrared bands, resulting in insufficient chemical discrimination evidence for classifiers. Even with dual-camera solutions, the differences between the two cameras in terms of field of view, spatial resolution, wavelength sampling position, and spectral response sensitivity are not effectively coordinated, leading to spatial misalignment and spectral steps in the directly stitched spectral data. Existing schemes often use single-band reflectance as a clustering feature and sort anatomical regions according to the mean reflectance during region segmentation. This results in insufficient segmentation stability in the cambium layer, the thinnest and lowest-contrast anatomical structure, making it prone to mislabeling due to differences in slice thickness and dryness, thus affecting the discriminative power of subsequent multi-region spectral extraction. Existing solutions often use full-spectrum uniform sampling to directly perform data-driven selection in the characteristic band selection stage, which lacks chemical prior guidance on the inherent characteristic absorption bands of ginsenoside molecules in the near-infrared region. As a result, a large number of the selected characteristic bands fall into regions unrelated to chemical differences, and the classification performance obtained under more characteristic bands is actually lower than that of the solution of this invention.
[0005] Most existing solutions treat origin identification, seed selection identification, and growth age identification as independent single tasks, training separate models for each task. This results in low data utilization and fails to leverage statistical correlations between tasks when they are correlated. When labels are unordered categorical variables, constructing the task correlation matrix using Pearson correlation coefficients introduces human bias due to reliance on integer encoding order. Furthermore, the independent outputs of existing solutions mean that directly taking the argmax of each task's probability vector may result in triples that do not exist physically. For example, selecting wild ginseng with a growth age of 3 to 4 years presents a contradiction, while wild ginseng requires over 15 years of growth under natural conditions. Such contradictions are exacerbated by local inconsistencies in the probability vectors or by noise disturbances in the samples, impacting the system's reliability in the actual industry chain.
[0006] In summary, there is an urgent need for a method and supporting equipment for the simultaneous identification of ginseng slices' origin, variety selection, and age by integrating anatomical structure region segmentation, chemically prior-guided feature band selection, task-driven feature weighting, multi-task parallel convolutional neural networks, and triplet prior constraints, in order to solve the aforementioned technical problems. Summary of the Invention
[0007] To address the problems existing in the background technology, this invention provides a method for tracing the origin of ginseng slices based on spectral analysis, comprising the following steps:
[0008] S1: Frame-synchronous acquisition of ginseng slice sections was performed using a visible-near-infrared (VNIR) band hyperspectral camera and a short-wave infrared (SWIR) band hyperspectral camera to obtain VNIR and SWIR band hyperspectral reflectance images. Distortion correction, spatial registration, spatial resolution resampling, and wavelength axis unification were performed on the VNIR and SWIR band hyperspectral reflectance images to make them the same cross-sectional coordinate system. The images were then stitched together according to the band dimensions to obtain the original hyperspectral image.
[0009] S2: Perform pixel-by-pixel relative radiometric correction on the original hyperspectral image based on the pre-acquired dark field image and whiteboard image, and then perform spectral preprocessing on the radiometrically corrected reflectance image based on the reference spectrum and mean vector determined in advance during the training phase to obtain the preprocessed spectral matrix.
[0010] S3: Based on at least two bands that reflect the differences in the tissue structure of ginseng slices, construct a region segmentation feature map, and combine clustering algorithm and radial distance constraint to perform region segmentation on the preprocessed spectral matrix to obtain a multi-region spectral matrix composed of representative spectra of the four anatomical regions: the outer skin region, the phloem region, the cambium and the xylem.
[0011] S4: Within a specified window centered on the near-infrared characteristic absorption band of ginsenosides, the multi-region spectral matrix is resampled by wavelength axis interpolation. Based on a pre-determined set of characteristic bands, the corresponding columns are extracted from the resampled multi-region spectral matrix to obtain the multi-region characteristic spectral matrix.
[0012] S5: The multi-region feature spectral matrix is weighted based on a pre-determined fusion weight matrix to obtain a multi-task feature tensor;
[0013] S6: The multi-task feature tensor, the multi-channel spatial image extracted from the preprocessed spectral matrix according to the feature band set, and the texture feature vector extracted based on the gray-level co-occurrence matrix are respectively fed into the spectral branch, spatial branch, and texture branch of the pre-trained multi-task parallel convolutional neural network. The three task branches of the multi-task parallel convolutional neural network output the probability vectors of the origin task, the seed selection task, and the age task, respectively.
[0014] S7: Based on the set of triplets of origin, variety, and age pre-constructed from existing labeled samples, score each candidate triplet by traversing the three probability vectors output in step S6, and select the triplet that makes the score the maximum as the final result output.
[0015] Further, step S1 specifically includes:
[0016] S11: Place the ginseng slice to be tested inside the limiting ring of the sample stage, so that the cut surface of the ginseng slice to be tested faces the direction of spectral acquisition;
[0017] S12: Simultaneously send acquisition trigger signals to the VNIR band hyperspectral camera and the SWIR band hyperspectral camera through a synchronization trigger, so that the VNIR band hyperspectral camera and the SWIR band hyperspectral camera synchronously acquire the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image of the cross section of the ginseng slice to be tested.
[0018] S13: Using the pre-stored intrinsic and extrinsic parameter matrices of the VNIR band hyperspectral camera and the SWIR band hyperspectral camera, lens distortion correction is performed on the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image, and the two are mapped to the same sectional coordinate system through homography transformation;
[0019] S14: Downsample the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image with higher resolution after mapping to the same sectional coordinate system, so that the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image have the same spatial resolution, and obtain the spatially registered VNIR band hyperspectral reflectance image and SWIR band hyperspectral reflectance image.
[0020] S15: Based on a pre-determined unified wavelength axis, the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image, after spatial registration, are respectively interpolated along the band dimension to make their wavelength sampling positions consistent; within the overlapping region of the spectral response of the two cameras, response consistency correction is performed on the overlapping band based on the dual-camera response consistency correction coefficient pre-determined during the training phase.
[0021] S16: Stitch the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image after response consistency correction in the band dimension to obtain a size of [missing information]. The original hyperspectral image, wherein The number of rows in the image. The number of columns in the image. This represents the total number of bands after merging.
[0022] Further, step S2 specifically includes:
[0023] S21: Close the light-blocking dark field cover and acquire a dark field image. The dark field image is located at the pixel position. ,wavelength The DN value at the location is denoted as ;
[0024] S22: Flip the whiteboard into the acquisition field of view and acquire the whiteboard image. The whiteboard image is located at pixel position. ,wavelength The DN value at the location is denoted as ;
[0025] S23: Based on the dark field image and the whiteboard image, perform relative radiometric correction on the original hyperspectral image pixel by pixel and band by band according to the following formula to obtain the reflectance image:
[0026] ;
[0027] In the formula, pixel position At wavelength Reflectance at that location; These are the row coordinates of the image; These are the column coordinates of the image; Wavelength (nm); For the original hyperspectral image at pixel location ,wavelength The DN value at that location; For the dark field image at pixel position ,wavelength The DN value at that location; The whiteboard image at pixel position ,wavelength The DN value at that location;
[0028] S24: Perform Savitzky-Golay smoothing on the reflectance image along the band dimension;
[0029] S25: Perform multivariate scattering correction on the Savitzky-Golay smoothed reflectance image based on the reference spectrum predetermined and stored during the training phase; then perform mean centering processing on the multivariate scattering corrected reflectance image along the band dimension based on the mean vector predetermined and stored during the training phase to obtain the preprocessed spectral matrix.
[0030] Further, step S3 specifically includes:
[0031] S31: Extract the two-dimensional grayscale image corresponding to the 660nm band from the preprocessed spectral matrix, perform morphological opening operation on the two-dimensional grayscale image, and obtain the foreground binary mask of the ginseng slice section.
[0032] S32: Extract at least two two-dimensional grayscale images corresponding to bands that reflect differences in tissue structure from the preprocessed spectral matrix. The at least two bands include the 1450nm band, which is sensitive to water content, and the 1690nm band, which is sensitive to CH bond content. Stack the reflectance values corresponding to the at least two bands to form a multidimensional segmentation feature vector for each pixel position in the foreground binary mask, and obtain a region segmentation feature map.
[0033] S33: For the pixels within the foreground binary mask, perform K-means clustering based on the multidimensional segmentation feature vector, with a cluster size of 4, resulting in 4 clusters;
[0034] S34: Determine the geometric center of the foreground binary mask, calculate the average radial distance from all pixels in each cluster to the geometric center, and sequentially label the four clusters as the corresponding anatomical regions of the epidermis, phloem, cambium, and xylem according to the average radial distance from far to near, to obtain the first... Binary mask for each anatomical region ,in The numbers are 1, 2, 3, and 4.
[0035] S35: Calculate the representative spectrum of each of the four anatomical regions using the following formula:
[0036] ;
[0037] In the formula, For the first Each anatomical region at wavelength The representative spectral value at that location; For indexing anatomical regions. , , , These correspond to the outer bark, phloem, cambium, and xylem, respectively. Wavelength (nm); For the first The set of all pixel locations within an anatomical region, defined by the binary mask. Sure; For set The number of elements; These are the row and column coordinates of the pixel; This is the summation operator; For the membership operator; The preprocessed spectral matrix at the pixel position ,wavelength The reflectance value at that location;
[0038] S36: Stack the representative spectra of the four anatomical regions row by row to obtain 4 rows. The multi-region spectral matrix of the column, wherein The total number of bands in the preprocessed spectral matrix.
[0039] Further, step S4 specifically includes:
[0040] S41: The center wavelength of the near-infrared characteristic absorption band of ginsenosides is used as the a priori center. The center wavelength of the a priori center includes 1450nm, 1690nm, 1940nm, 2240nm and 2280nm, which correspond to the OH first harmonic, CH first harmonic, OH and water combination frequency, CH and CO combination frequency and CH deformation vibration frequency of ginsenoside molecules, respectively.
[0041] S42: Within a 20nm window on both sides of the center wavelength of each prior center, the spectral data of the multi-region spectral matrix is mapped to a predetermined unified wavelength axis by wavelength axis interpolation resampling. The sampling interval of the unified wavelength axis within the window is no greater than 2nm, and the original sampling wavelength of the multi-region spectral matrix is maintained outside the window to obtain a candidate spectral matrix.
[0042] S43: Based on a pre-determined set of characteristic bands Extract the corresponding columns from the candidate spectral matrix to obtain 4 rows. The multi-region characteristic spectral matrix of the column, the set of characteristic bands ,in The first in the set of characteristic bands The wavelengths (nm) corresponding to each characteristic band For characteristic band index, The number of characteristic bands in the set of characteristic bands;
[0043] S44: The set of characteristic bands The candidate spectral matrix of each sample in the training set is pre-determined as follows: Based on the wavelength axis interpolation resampling method described in S42, the candidate spectral matrix of each sample in the training set is constructed; the origin label, seed selection label, and year label of each sample in the training set are concatenated into a reference vector after one-hot encoding; a competitive adaptive reweighted sampling algorithm combined with a partial least squares discriminant analysis model is used, with the column vector corresponding to each candidate band in the candidate spectral matrix as the input feature and the reference vector as the output target, for iterative selection. In each iteration, a partial least squares discriminant analysis model is established by extracting training samples from a Monte Carlo subset and calculating the cross-validation classification loss; the bands corresponding to the subset that minimizes the cross-validation classification loss are selected as the feature band set. .
[0044] Further, step S5 specifically includes:
[0045] S51: Based on the fusion weight matrix, the four regional components at each feature band position in the multi-region feature spectral matrix are simultaneously weighted. Specifically, for each column of the multi-region feature spectral matrix, three sets of weighted column vectors are obtained by simultaneously weighting the feature band position in the columns corresponding to the origin task, seed selection task, and year task in the fusion weight matrix. The three sets of weighted column vectors obtained at all feature band positions are stacked along the task dimension to obtain a size of... Multitasking feature tensor;
[0046] The fusion weight matrix is predetermined from the training set through the following steps S52 to S55:
[0047] S52: For each sample in the training set, the multi-region feature spectral matrix of that sample is averaged along the region dimension to obtain... 3D feature vector, the The 3D feature vector, along with the corresponding origin label, selection label, and year label of the sample, constitutes a training sample pair; using the 3D feature vector of all samples in the training set... 3D eigenvectors at the th The components at each characteristic band position constitute the eigenvector. To train all samples in the task The labels on the vector form a label vector. ;
[0048] S53: Based on the feature vector and the label vector Construct a dynamic weighted matrix using the following formula. :
[0049] ;
[0050] In the formula, For the dynamic weighting matrix at the th Journey, Task Column elements; For characteristic band indexing; For task indexing, Pick , , These correspond to tasks related to the place of origin, seed selection, and time limit, respectively. For all samples in the training set 3D eigenvectors at the th The feature vector is composed of the components at each feature band position; For all samples in the training set in the task The label vector formed by the labels on the label; The mutual information (bits) between the two vectors within the parentheses on the training set; A temporary index for summation; For all samples in the training set 3D eigenvectors at the th The feature vector is composed of the components at each feature band position; The number of characteristic bands in the set of characteristic bands; To prevent small positive numbers with a denominator of zero; This is the summation operator;
[0051] S54: Calculate the normalized mutual information between pairs of labels for origin task, seed selection task, and age task on the training set, and construct a 3x3 task relevance matrix. The task relevance matrix The diagonal elements are 1, and the off-diagonal elements are the normalized mutual information between the label vectors of the two corresponding tasks.
[0052] S55: Construct the intermediate weight matrix using the following formula Then, for the intermediate weight matrix Normalize by column so that the sum of all elements in the column corresponding to each task is 1, thus obtaining the fusion weight matrix. :
[0053] ;
[0054] In the formula, This is the intermediate weight matrix; The dynamic weighting matrix; It is a 3x3 identity matrix; The task coupling coefficient is determined by grid search from the validation set partitioned from the training set. This is the task relevance matrix.
[0055] Further, step S6 specifically includes:
[0056] S61: The multi-task parallel convolutional neural network includes three parallel backbone branches: the spectral branch, the spatial branch, and the texture branch, as well as the three task branch heads located after the output of the three parallel backbone branches;
[0057] S62: The spectral branch consists of three sequentially connected one-dimensional convolutional layers, each followed by a modified linear unit activation function and a batch normalization layer; the size is... The multi-task feature tensor rearrangement is based on The input tensor, consisting of 12 channels formed by combining 4 anatomical regions and 3 tasks, with each feature band representing the sequence length, serves as the input to the spectral branch.
[0058] S63: The spatial branch consists of three sequentially connected two-dimensional convolutional layers, each followed by a modified linear unit activation function and a batch normalization layer; the input of the spatial branch is the multi-channel spatial image extracted from the preprocessed spectral matrix according to the feature band set;
[0059] S64: The texture branch consists of two fully connected layers connected in series; the input of the texture branch is the texture feature vector, which is composed of four statistical quantities: energy, contrast, correlation and entropy of the gray-level co-occurrence matrix extracted from the two-dimensional gray-level image corresponding to the 660nm band in the preprocessed spectral matrix at four directions (0°, 45°, 90° and 135°) and multiple pixel distances.
[0060] S65: Concatenate the outputs of the spectral branch, the spatial branch, and the texture branch along the channel dimension to obtain a fused feature;
[0061] S66: Using the fused features as input, the three task branches are derived. Each task branch consists of a fully connected layer, a Dropout layer, and a Softmax layer connected in series. The three task branches output the probability vector of the origin task, respectively. The probability vector of the seed selection task and the probability vector of the time-limited task ;
[0062] S67: The multi-task parallel convolutional neural network is pre-trained in the following manner: based on the multi-task feature tensor, the multi-channel spatial image, and the texture feature vector of each sample in the training set, and the corresponding origin label, selection label, and age label, the multi-task parallel convolutional neural network is trained end-to-end using a joint loss function expressed in the following formula until the joint loss function converges or the number of iterations reaches a preset value, thus obtaining the trained multi-task parallel convolutional neural network:
[0063] ;
[0064] In the formula, The value of the joint loss function; , , The loss weights are respectively for tasks related to production location, seed selection, and age. The cross-entropy loss is calculated using the predicted probability vector of the task within parentheses and the one-hot encoding of the corresponding real label. , , These are respectively: origin tasks, seed selection tasks, and year-limit tasks; The L2 regularization coefficient; It is the set of all trainable parameters of the multi-task parallel convolutional neural network; The square of the L2 norm of the vector within the brackets.
[0065] Further, step S7 specifically includes:
[0066] S71: Based on the existing labeled samples, pre-construct the set of triplets for origin, variety selection, and age. The set of three elements: origin, variety selection, and age. Each element in the array is a triplet of (origin category, selection category, and age category) that is known to exist in the existing labeled samples;
[0067] S72: Based on the set of candidate categories for place of origin Selection candidate category set and the set of candidate categories based on age Using the Cartesian product as the search space, we traverse each candidate triplet. Each candidate triplet is scored using the following formula:
[0068] ;
[0069] In the formula, Candidate Triples The rating; For the set of candidate categories of place of origin Candidate categories; For the set of candidate categories for seed selection Candidate categories; For the set of candidate categories for the year limit Candidate categories; The probability vector of the origin task output in step S6 is categorized as follows: The components on; The probability vector of the seed selection task output in step S6 is in the category The components on; The probability vector of the time-limited task output in step S6 is in the category The components on; To prevent small positive numbers from overflowing in logarithmic calculations; The natural logarithm operator; The triplet reward coefficient is determined by grid search from the validation set partitioned from the training set. This is an indicator function; it takes the value 1 if the condition inside the parentheses is true and 0 if it is false. This refers to the set of three elements: origin, variety, and age.
[0070] S73: Select to make The candidate triple with the highest value is taken as the final output, and the place of origin corresponding to the final output is denoted as . Seed selection category is Year category The probability vector of the origin task output in step S6 is then used in... The components on, the probability vector of the seed selection task in The components on the time limit and the probability vector of the task in the time limit are in The components on the graph are used as the output confidence levels for origin, variety selection, and age, respectively.
[0071] The present invention also provides a ginseng slice origin traceability device based on spectral analysis, including a sample stage, a dual-spectrum acquisition module, a standard illumination module, a radiation correction module, an embedded computing unit, a database module, a human-computer interaction display module, and a main control unit;
[0072] The sample stage is used to hold the ginseng slices to be tested.
[0073] The dual-spectral acquisition module includes a VNIR band hyperspectral camera, a SWIR band hyperspectral camera, a synchronization trigger, a dual-camera calibration component, and an image registration unit. Both the VNIR and SWIR band hyperspectral cameras are located above the sample stage with their objectives facing the stage. The synchronization trigger is electrically connected to the trigger terminals of both the VNIR and SWIR band hyperspectral cameras. The dual-camera calibration component is used to pre-calibrate the intrinsic and extrinsic parameter matrices of the VNIR and SWIR band hyperspectral cameras. The image registration unit registers the images acquired by the VNIR and SWIR band hyperspectral cameras to the same sectional coordinate system based on the intrinsic and extrinsic parameter matrices.
[0074] The standard illumination module includes a ring lamp and a diffuse reflection device. The ring lamp is arranged around the outside of the objective lens of the dual-spectrum acquisition module, and the diffuse reflection device is arranged in the optical path between the ring lamp and the sample stage.
[0075] The radiation correction module includes a flip-up whiteboard and a dark field cover. The flip-up whiteboard is installed between the sample stage and the dual-spectrum acquisition module via a flipping mechanism, and the dark field cover is closed onto the objective lens of the dual-spectrum acquisition module via a driving mechanism.
[0076] The embedded computing unit is connected to the image output terminal of the dual-spectrum acquisition module via a data interface. The embedded computing unit pre-stores the calibration parameters output by the dual-camera calibration component, the reference spectrum determined during the training phase, the mean vector, the feature band set, the fusion weight matrix, and the model parameters of the trained multi-task parallel convolutional neural network. The embedded computing unit is used to call the trained multi-task parallel convolutional neural network to execute the following steps in the method: image registration and stitching in step S1, radiometric correction and spectral preprocessing in step S2, region segmentation and multi-region spectral extraction in step S3, feature band extraction in step S4, feature weighting in step S5, network inference in step S6, and triplet score output in step S7.
[0077] The database module is communicatively connected to the embedded computing unit and is used to store training sample features and the set of triplets of origin, variety, and age.
[0078] The human-computer interaction display module is communicatively connected to the embedded computing unit and is used to display the identification results of origin, variety, and age output by the embedded computing unit, as well as the corresponding confidence level.
[0079] The main control unit is electrically connected to the dual-spectrum acquisition module, the standard illumination module, the radiation correction module, the embedded computing unit, and the human-computer interaction display module, respectively, and is used to coordinate the above modules to complete the execution flow of steps S1 to S7 of the method.
[0080] In a preferred embodiment, the sample stage is provided with a limiting ring for positioning the ginseng slice to be tested;
[0081] The dual-camera calibration component of the dual-spectrum acquisition module includes a checkerboard calibration plate, which is detachably mounted on the sample stage surface; the image registration unit is an image registration program module deployed on the embedded computing unit.
[0082] The reflective surface material of the flip-up whiteboard in the radiation correction module is polytetrafluoroethylene, the flipping mechanism includes a stepper motor electrically connected to the main control unit, and the drive mechanism is electrically connected to the main control unit.
[0083] The device also includes a light shield and a communication module; the light shield is located outside the sample stage, the dual-spectrum acquisition module, the standard illumination module, and the radiation correction module; the communication module is communicatively connected to the embedded computing unit, and the communication module includes one or both of a wired communication interface and a wireless communication interface, used to upload the identification results to a higher-level database or a blockchain traceability platform and receive remotely updated data of the origin, variety, and age tripartite set.
[0084] The beneficial effects achieved by this invention are as follows:
[0085] First, the present invention designs step S1, a method for synchronous acquisition, registration and stitching of VNIR band hyperspectral reflectance image and SWIR band hyperspectral reflectance image frames based on dual-camera calibration parameters, and step S3, a method for constructing a multi-band region segmentation feature map to reflect the differences in the tissue structure of ginseng slices and a region segmentation method with average radial distance constraints. Step S1 involves calibrating the dual cameras with intrinsic and extrinsic parameters, performing homography transformation, spatial resolution resampling, wavelength axis unification, and response consistency correction. This ensures that the final stitched original hyperspectral image covers a continuous wide band from visible light to short-wave infrared in the same cross-sectional coordinate system, providing complete chemical discrimination evidence for subsequent algorithms, including ginsenosides in multiple characteristic absorption bands, and eliminating spectral steps at the stitching point. Step S3 uses the reflectance of the 1450 nm band, which is sensitive to moisture content, and the reflectance of the 1690 nm band, which is sensitive to CH bond content, to form a multidimensional segmentation feature vector. This vector jointly characterizes the differences in chemical composition of each anatomical region. Based on the anatomical topological prior from the outside to the inside of the ginseng slice cross-section, each cluster is labeled as the epidermis, phloem, cambium, and xylem according to the average radial distance from far to near, ensuring a stable correspondence between the segmentation results and the actual anatomical structure. The beneficial effect of this invention is that it significantly improves the segmentation stability of the key anatomical structure of the thin, low-contrast cambium layer compared to the single-band K-means method, and reduces the disturbance of the acquisition and segmentation results by differences in slice thickness, dryness, and external stray light, thereby ensuring that the subsequent multi-region spectral matrix has stable discriminative power from the source.
[0086] This invention designs step S4, which is a feature band selection method that uses the center wavelength of the five inherent characteristic absorption bands of ginsenosides in the near-infrared region as the prior center, performs interpolation resampling on the wavelength axis within a specified window on both sides of each prior center, and combines a competitive adaptive reweighted sampling algorithm with a partial least squares discriminant analysis model to perform secondary refinement of candidate bands. By focusing the analysis on the vicinity of five characteristic absorption bands of ginsenoside molecules—the OH first harmonic, CH first harmonic, the combination frequency of OH and water, the sum frequency of CH and CO, and the sum frequency of CH deformation vibration—the density of candidate bands was matched with the density of chemical correlations. This allowed the selection process to prioritize the inclusion of bands with strong discriminative power into the characteristic band set, while maintaining the original sampling wavelength outside the window to retain bands sensitive to other chemical differences. The proportion of selected characteristic bands falling into the saponin prior window was significantly increased compared to the full-spectrum uniform sampling method. Lower cross-validation classification loss was achieved with fewer characteristic bands, improving the discriminative ability of subsequent classifiers while reducing the computational cost and parameter size of the model. Furthermore, the interpretability of the model was improved because the chemical meaning of the characteristic bands was clear.
[0087] This invention designs a task-driven weighting method in step S5, which involves constructing a dynamic weighting matrix using the mutual information between feature vectors and task label vectors, constructing a task relevance matrix using the normalized mutual information between each pair of task labels, and correcting the dynamic weighting matrix to obtain a fusion weight matrix. It also designs a multi-task parallel convolutional neural network and a corresponding joint loss function training method in step S6, which includes spectral branches, spatial branches, and texture branches. Step S5 uses normalized mutual information to adapt the statistical characteristics of unordered category labels such as origin and seed selection, avoiding the artificial correlation bias introduced by Pearson correlation coefficient due to its dependence on the integer encoding order of categories. It also adjusts the intensity of correlation between tasks through task coupling coefficient, so that each task has independent feature band attention when sharing the same feature source. Step S6 improves data utilization by sharing the backbone branch. It introduces the fineness of ginseng slice cross-section, texture level, and distribution characteristics of vessels and wood rays through the texture branch to characterize the gray-level co-occurrence matrix, which makes up for the shortcomings of deep convolution features in characterizing manual texture. It realizes the simultaneous recognition of three tasks: origin, seed selection, and age. The recognition accuracy of the three tasks is improved compared with the single-task convolutional neural network method and the Pearson task correlation method. At the same time, when there is statistical correlation among the three tasks, the shared backbone network obtains mutually compatible discriminative representations from the same sensing front end, improving the overall recognition performance and training efficiency of the system.
[0088] The present invention designs a triplet scoring constraint method in step S7, which uses a pre-constructed set R of origin, variety selection, and age based on existing labeled samples to jointly score the probability vectors of the three tasks and select the triplet that maximizes the score as the final output. Based on the sum of the log-likelihoods of the probability vectors of the three tasks, a discrete reward of the size of the triplet reward coefficient is provided for reasonable combinations belonging to the triplet set R through an indicator function. This causes the scoring function to form a potential well near reasonable combinations. Even if the likelihood term is disturbed by noise and has a local maximum, as long as the reward term is sufficient, the overall score will still tend to fall within reasonable triplets. This invention has a significant inhibitory effect on the physical contradictions between the independent outputs of the three tasks, greatly reducing the proportion of physically non-existent outputs such as selected wild ginseng with a maturity of 3 to 4 years. Under different noise levels, the accuracy of the joint recognition of the three tasks is improved compared with the direct argmax method, and the rate of decline is slowed down. This allows the ginseng slice origin traceability method and equipment to maintain high recognition reliability under complex sample states and different collection conditions in the industrial chain. It has good practicality in the traceability management and extended application of the entire industrial chain. Furthermore, the communication module supports remote updates of the triplet set R of origin, selection, and maturity, allowing the equipment of this invention to expand the range of supported combinations without retraining the multi-task parallel convolutional neural network, which has strong engineering maintainability. Attached Figure Description
[0089] Figure 1 This is a comparison chart of the Dice coefficients for anatomical region segmentation in Examples 1, 2, and 3 with that in Comparative Example 2.
[0090] Figure 2 These are comparison diagrams of the CARS feature band selection process in Examples 1, 2, and 3 with Comparative Example 3, where (a) is a comparison diagram of the 5-fold cross-validation classification loss curves in the CARS iteration process, and (b) is a comparison diagram of the final feature band set location distribution.
[0091] Figure 3 This is a heatmap comparing the recognition accuracy of Examples 1, 2, and 3 with Comparative Examples 1, 2, 3, 4, 5, and 6 on three tasks and the combined recognition of the three tasks.
[0092] Figure 4 The robustness of Examples 1, 2, and 3 compared to Comparative Examples 1, 4, 5, and 6, and The constraint effect comparison chart shows that (a) is a comparison of the joint recognition accuracy of the three tasks under different noise levels, and (b) is a comparison of the output ratio of physical contradictions of different methods.
[0093] Figure 5 This is a flowchart of the ginseng slice origin traceability method based on spectral analysis of the present invention.
[0094] Figure 6 This is a structural diagram of the ginseng slice origin traceability device based on spectral analysis of the present invention. Detailed Implementation
[0095] The technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. In addition, the forms of the various structures described in the following embodiments are merely illustrative. The present invention is not limited to the structures described in the following embodiments. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0096] The overall process of the ginseng slice origin traceability method based on spectral analysis of the present invention includes steps S1 to S7, as described above. Figure 5Step S1 involves simultaneous frame acquisition and image registration / stitching using dual cameras. A VNIR band hyperspectral camera is used to acquire visible-near-infrared reflectance images covering wavelengths from 400 to 1000 nm, while a SWIR band hyperspectral camera is used to acquire short-wave infrared reflectance images covering wavelengths from 1000 to 2500 nm. The stitched images simultaneously reflect the visible color, internal moisture distribution, and near-infrared characteristic absorption of ginsenoside molecules at CH and OH bonds on the ginseng slice. Sub-step S11 places the ginseng slice to be tested within the limiting ring of the sample stage, ensuring the slice faces the spectral acquisition direction to guarantee spatial stability. Sub-step S12 simultaneously sends acquisition trigger signals to both cameras via a synchronization trigger, enabling simultaneous frame acquisition of VNIR and SWIR band hyperspectral reflectance images of the ginseng slice slice, ensuring that the two images correspond to the same instantaneous illumination and sample state. Sub-step S13 uses the pre-stored dual-camera intrinsic and extrinsic parameter matrices to perform lens distortion correction on the two images. The intrinsic parameter matrix describes the camera's focal length, principal point offset, and radial and tangential distortion coefficients of the lens, while the extrinsic parameter matrix describes the relative rotation and translation between the two cameras. The images after distortion correction are mapped to the same cross-sectional coordinate system through homography transformation, so that the same pixel position in the two images corresponds to the same physical position on the ginseng slice cross-section.
[0097] Sub-step S14 downsamples the image with higher resolution among the two images mapped to the same cross-sectional coordinate system along the spatial dimension, so that the two images have the same spatial resolution, resulting in two spatially registered images. Sub-step S15 performs wavelength axis interpolation on the two spatially registered images along the band dimension based on a pre-determined unified wavelength axis. The wavelength axis interpolation preferably uses cubic spline interpolation or linear interpolation to ensure that the wavelength sampling positions of the two images are consistent. In the band interval where the spectral responses of the two cameras overlap, response consistency correction is performed on the overlapping bands based on the dual-camera response consistency correction coefficient calibrated during the training phase to eliminate the spectral step caused by the difference in sensitivity of the two camera sensors. Sub-step S16 stitches the two images after response consistency correction end-to-end along the band dimension to obtain an image of size [size missing]. The original hyperspectral image. Step S1 performs rigorous geometric registration, spatial resolution unification, wavelength axis unification, and response consistency correction on the images from the two cameras, enabling subsequent steps to be processed based on continuous broadband information in a single coordinate system, thus laying the data foundation for the entire inference process.
[0098] Step S2 performs relative radiometric correction and spectral preprocessing. Sub-step S21 closes the optical path and covers the dark field with a light-shielding cover, acquiring a dark field image. This dark field image reflects the dark current response and readout noise background of the camera's sensor under no incident light conditions. Sub-step S22 flips a white board into the acquisition field of view. The reflective surface of the white board is made of polytetrafluoroethylene (PTFE), which has near-Lambertian diffuse reflectance characteristics in the 400-2500 nm range and a reflectance higher than 0.95, serving as a high-reflectance reference. A white board image is acquired. Sub-step S23 performs relative radiometric correction pixel-by-pixel and band-by-band on the original hyperspectral image using the following formula to obtain a reflectance image. ;
[0099] In the formula, pixel position At wavelength Reflectance at that location; These are the row coordinates of the image; These are the column coordinates of the image; Wavelength (nm); For the original hyperspectral image at pixel location ,wavelength The DN value at that location; For the dark field image at pixel position ,wavelength The DN value at that location; The whiteboard image at pixel position ,wavelength The DN value at that location. This formula is the standard relative radiometric correction formula for hyperspectral reflectance imaging. Compared with mean correction that only depends on wavelength, the pixel-by-pixel form can simultaneously compensate for the spatial inhomogeneity of the light source within the field of view and the response differences between pixels of the photosensitive device.
[0100] Sub-step S24 performs Savitzky-Golay smoothing on the reflectance image along the band dimension. The Savitzky-Golay smoothing performs local polynomial least squares fitting on the reflectance sequence within an odd-length sliding window centered on the current wavelength, replacing the original reflectance with the value of the fitted polynomial at the center wavelength. This suppresses high-frequency noise while better preserving the spectral peak position and peak shape. Preferably, the window length is 9 or 11 and the polynomial order is 2 or 3. Sub-step S25 performs multivariate scattering correction on the Savitzky-Golay smoothed reflectance image based on the reference spectrum pre-determined and stored in the embedded computing unit during the training phase. The multivariate scattering correction first performs least-squares linear regression on each test spectrum and the reference spectrum to obtain the multiplicative factor and additive shift. Then, it uses the obtained multiplicative factor and additive shift to perform an inverse transform on the test spectrum to suppress the multiplicative scattering effect caused by differences in sample thickness, surface roughness, and slice optical path. Next, based on the mean vector pre-determined and stored during the training phase, it performs mean centering on the multivariate scattering corrected reflectance image along the band dimension to obtain the preprocessed spectral matrix. Using the pre-determined reference spectrum and mean vector ensures that the parameters of a single test sample do not need to be re-statistically counted in the sample dimension during inference, guaranteeing the consistency of preprocessing between the training and inference domains.
[0101] Step S3 completes the region segmentation based on the anatomical structure of the ginseng slice cross-section. Sub-step S31 extracts a two-dimensional grayscale image corresponding to the 660nm band from the preprocessed spectral matrix. This band is located in the strong absorption region of chlorophyll and carbon-containing biological tissues. The reflectance difference between the ginseng slice cross-section and the black background is the greatest in this band. Morphological opening operation is performed on this grayscale image, first eroding and then dilating. Isolated edge artifacts and small burrs are removed using circular structuring elements to obtain the foreground binary mask of the ginseng slice cross-section. Sub-step S32 extracts two-dimensional grayscale images corresponding to the 1450nm and 1690nm bands from the preprocessed spectral matrix. The former corresponds to the OH-harmonic stretching vibration absorption of water molecules, and the latter corresponds to the CH-harmonic stretching vibration absorption of organic molecules. The reflectance values of the two bands are stacked to form a multidimensional segmentation feature vector for each pixel position in the foreground binary mask, thereby obtaining the region segmentation feature map.
[0102] Sub-step S33 performs K-means clustering on the pixels within the foreground binary mask based on the multidimensional segmentation feature vector, with a cluster size of 4. K-means clustering is a well-known unsupervised clustering algorithm in the field, iteratively assigning pixels to the nearest cluster center and updating the cluster center position until the cluster center is stable. Sub-step S34 determines the geometric center of the foreground binary mask, i.e., the arithmetic mean coordinates of all pixel positions within the foreground binary mask. Then, it calculates the average radial distance from all pixels within each cluster to the geometric center. The average radial distance is the arithmetic mean of the Euclidean distances between all pixels within the cluster and the geometric center. The four clusters are sequentially labeled as the four anatomical regions corresponding to the epidermis, phloem, cambium, and xylem, according to the average radial distance from farthest to nearest, to obtain the first... Binary mask for each anatomical region ,in , , , The radial distance-based calibration method aligns with the anatomical structure of ginseng slices, which consists of the outer skin, phloem, cambium, and xylem from the outside in. This overcomes the sensitivity to differences in dryness that arises from relying solely on average reflectance for sorting. Sub-step S35 calculates the representative spectrum of each anatomical region using the following formula. ;
[0103] In the formula, For the first Each anatomical region at wavelength The representative spectral value at that location; Indexing anatomical regions; Wavelength (nm); For the first The set of all pixel locations within an anatomical region, defined by the binary mask. Sure; For set The number of elements; These are the row and column coordinates of the pixel; This is the summation operator; For the membership operator; The preprocessed spectral matrix at the pixel position ,wavelength The reflectance value at that location. Sub-step S36 stacks the representative spectra of the four anatomical regions row by row to obtain four rows. The multi-region spectral matrix of the column, wherein The total number of bands in the preprocessed spectral matrix is the multi-region spectral matrix. Compared with the single spectrum that is averaged across the entire cross section, the multi-region spectral matrix retains the chemical composition differences of different anatomical structures of ginseng slices, providing a more discriminative feature source for subsequent multi-task recognition.
[0104] Step S4 extracts characteristic bands guided by prior chemical knowledge of ginsenosides. Sub-step S41 uses the center wavelengths of five inherent characteristic absorption bands of ginsenoside molecules in the near-infrared region as prior centers, specifically 1450 nm, 1690 nm, 1940 nm, 2240 nm, and 2280 nm, corresponding to the OH first harmonic, CH first harmonic, OH-water combination frequency, CH-CO combination frequency, and CH deformation vibrational frequency, respectively. These five characteristic absorption bands represent typical vibrational features of saponin glycosides in near-infrared spectroscopy. By focusing the analysis near these five prior centers, the subsequent characteristic bands are sensitive to the chemical differences of ginsenosides. Sub-step S42 performs wavelength axis interpolation resampling on the multi-region spectral matrix using a predetermined unified wavelength axis. Within a 20 nm window on either side of each prior center, the sampling interval of the unified wavelength axis is no greater than 2 nm. Outside the window, the original sampling wavelength of the multi-region spectral matrix is maintained, resulting in the candidate spectral matrix. Wavelength axis interpolation resampling does not physically add new sampling information, but by performing spectral interpolation between the original sampling positions, it unifies the wavelength coordinates near the key absorption band to a dense, fixed-length grid, which is beneficial for feature alignment between different samples in subsequent algorithms.
[0105] Sub-step S43 is based on the set of feature bands predetermined from the training set during the training phase. Extract the corresponding columns from the candidate spectral matrix to obtain 4 rows. The multi-region characteristic spectral matrix of the column, the set of characteristic bands is denoted as ,in The first in the set of characteristic bands The wavelengths (nm) corresponding to each characteristic band For characteristic band index, The number of characteristic bands in the set of characteristic bands. The value is preferably between 18 and 25. Sub-step S44 describes the set of characteristic bands. The pre-determined method specifically involves constructing the candidate spectral matrix of each sample in the training set based on the wavelength axis interpolation resampling method described in sub-step S42. The origin label, selection label, and year label of each sample in the training set are concatenated into a reference vector after one-hot encoding. A competitive adaptive reweighted sampling algorithm combined with a partial least squares discriminant analysis (PLD) model is used to iteratively refine the candidate bands. The competitive adaptive reweighted sampling algorithm is a well-known feature band selection algorithm in this field. Its core idea is to extract a subset of training samples in a Monte Carlo manner in each iteration to establish a PLD model. Retention weights are calculated for each candidate band based on the absolute value of the regression coefficients. The number of retained bands in each iteration is controlled by an exponential decay function, and bands are resampled using a weighted probability method, so that bands with larger regression coefficients obtain a higher retention probability in subsequent iterations. The PLD model is an extension of partial least squares regression to classification tasks. After one-hot encoding, the category labels are treated as multi-output continuous variables, and linear discriminant analysis is constructed in the latent variable space that maximizes the covariance between input features and output labels. After each iteration, the current candidate band subset is evaluated using cross-validation classification loss. After the iteration, the bands corresponding to the subset that minimizes the cross-validation classification loss are selected as the feature band set. The set of characteristic bands embodies the combination of chemical priors and data-driven approaches, covering the key absorption bands of ginsenosides while retaining effective dimensions that are sensitive to the identification of origin, variety, and age.
[0106] Step S5 implements multi-task-driven feature weighting to obtain a multi-task feature tensor. Sub-step S51 simultaneously weights the four regional components at each feature band position in the multi-region feature spectral matrix based on the fusion weight matrix. Specifically, each column of the multi-region feature spectral matrix is simultaneously weighted according to the weight value of the feature band position in the column corresponding to the origin task, seed selection task, and age task in the fusion weight matrix to obtain three sets of weighted column vectors. The three sets of weighted column vectors obtained at all feature band positions are stacked along the task dimension to obtain a tensor of size [size missing]. The multi-task feature tensor. The fusion weight matrix is predetermined during the training phase through sub-steps S52 to S55. Sub-step S52 averages the multi-region feature spectral matrix of each sample in the training set along the region dimension to obtain... 3D feature vector, the The 3D feature vector, along with the corresponding origin label, selection label, and year label of the sample, constitutes a training sample pair, which is used to represent all samples in the training set. 3D eigenvectors at the th The components at each characteristic band position constitute the eigenvector. To train all samples in the task The labels on the vector form a label vector. .
[0107] Sub-step S53 constructs a dynamic weighted matrix based on the feature vector and the label vector using the following formula:
[0108] ;
[0109] In the formula, For the dynamic weighting matrix at the th Journey, Task Column elements; For characteristic band indexing; For task indexing, Pick , , These correspond to tasks related to the place of origin, seed selection, and time limit, respectively. For all samples in the training set at the th The feature vector is composed of the components at each feature band position; For all samples in the training set in the task The label vector formed by the labels on the label; The mutual information (bits) between the two vectors within the parentheses on the training set; A temporary index for summation; For all samples in the training set at the th The feature vector is composed of the components at each feature band position; The number of characteristic bands in the set of characteristic bands; To prevent small positive numbers with a denominator of zero, it is preferable to use 1 × 10. -8 Up to 1×10 -6 ; This is the summation operator. Mutual information is a non-negative index in information theory that characterizes the statistical dependence of two random variables. It takes the value of zero when the two variables are independent, and the value increases as the dependence between them strengthens. It is applicable to both continuous and discrete variables, and can characterize both linear and nonlinear dependencies. Therefore, using mutual information as a measure of band importance is superior to the Pearson correlation coefficient, which only characterizes linear correlations. After normalization, the sum of the elements in each column of the dynamic weighting matrix is 1, reflecting the relative contribution weights of each characteristic band under this task.
[0110] Sub-step S54 calculates the normalized mutual information between pairs of labels for the origin task, seed selection task, and year task on the training set, and constructs a 3x3 task correlation matrix. The task relevance matrix The diagonal elements are 1, and the off-diagonal elements represent the normalized mutual information between the label vectors of the two corresponding tasks. Normalized mutual information is an index that normalizes the mutual information using the marginal entropy of the two variables, with values falling within a closed interval of 0 to 1. This avoids the dependence on the category encoding method introduced by using the Pearson correlation coefficient when the task labels are unordered categorical variables. Sub-step S55 constructs the intermediate weight matrix according to the following formula. ;
[0111] In the formula, This is the intermediate weight matrix; The dynamic weighting matrix; It is a 3x3 identity matrix; The task coupling coefficient is preferably determined through a grid search of the validation set and is between 0 and 1. This is the task relevance matrix. When... When taking zero, Convert to an identity matrix. and The tasks are identical and uncoupled; when When taking 1, Transform into itself, for The product of the task correlation matrix and the task correlation matrix indicates that the tasks are fully coupled through correlation. The physical meaning of is the multi-task coupling strength. Then, regarding the intermediate weight matrix... Normalize by column so that the sum of all elements in the column corresponding to each task is 1, thus obtaining the fusion weight matrix. Since both mutual information and normalized mutual information are non-negative, and exist When taking non-negative real numbers, all elements are non-negative. and It is naturally non-negative and requires no additional non-negativity processing. The fusion weight matrix... Once the parameters are predetermined during the training phase, they are fixed in the embedded computing unit along with the network model parameters. They are not recalculated during the inference phase, so that each task has independent band attention when sharing the same feature source, avoiding mutual interference between multiple tasks in the shared backbone network.
[0112] Step S6 implements synchronous recognition based on a multi-task parallel convolutional neural network. Sub-step S61 specifies that the multi-task parallel convolutional neural network includes three parallel backbone branches: the spectral branch, the spatial branch, and the texture branch, as well as three task branch heads located after the outputs of the three parallel backbone branches. Sub-step S62 specifies that the spectral branch consists of three sequentially connected one-dimensional convolutional layers. Each one-dimensional convolutional layer is followed by a modified linear unit activation function and a batch normalization layer. The modified linear unit activation function sets zero for negative inputs and remains unchanged for positive inputs, which can alleviate the gradient vanishing problem in deep networks. The batch normalization layer performs zero-mean unit variance normalization on the features of the current batch in the channel dimension and applies learnable scaling and translation, which can accelerate training convergence and reduce sensitivity to initialization. Considering that the one-dimensional convolutional layer requires a two-dimensional structure with sequence length and channel dimension as input, the size is... The multi-task feature tensor rearrangement is based on The input tensor, consisting of 12 channels formed by combining 4 anatomical regions and 3 tasks, with each feature band as the sequence length, serves as the input to the spectral branch. This allows the one-dimensional convolution to slide along the feature band dimension and jointly extract local spectral patterns across the 12 channels. The kernel lengths of the three one-dimensional convolutional layers are preferably decreasing from larger to smaller values, such as 7, 5, and 3, to balance large-scale spectral shapes and local peak features.
[0113] Sub-step S63 specifies that the spatial branch consists of three sequentially connected two-dimensional convolutional layers. Each two-dimensional convolutional layer is followed by a modified linear unit activation function and a batch normalization layer. The input of the spatial branch is the multi-channel spatial image extracted from the preprocessed spectral matrix according to the feature band set. The two-dimensional convolution extracts the spatial texture and morphology of the ginseng slice cross-section in different feature bands along the spatial dimension. The preferred kernel size is 3×3. Sub-step S64 specifies that the texture branch consists of two sequentially connected fully connected layers. The input of the texture branch is the texture feature vector. The texture feature vector consists of four statistical quantities: energy, contrast, correlation, and entropy of the gray-level co-occurrence matrix extracted from the two-dimensional gray-level image corresponding to the 660nm band in the preprocessed spectral matrix at four directions (0°, 45°, 90°, and 135°) and multiple pixel distances. The gray-level co-occurrence matrix is a second-order statistic in image processing that characterizes the spatial distribution of local gray-level textures. Its elements represent the frequency of occurrence of pixel pairs with a given gray-level value at a specified direction and distance. The four statistics of energy, contrast, correlation, and entropy measure the uniformity of texture, gray-level contrast, linear dependence of gray-level pairs, and degree of disorder, respectively. Together, they can characterize the fineness, texture level, and distribution characteristics of vessels and rays in ginseng slices, making up for the lack of depth convolution features in characterizing hand-crafted textures.
[0114] Sub-step S65 concatenates the outputs of the spectral branch, the spatial branch, and the texture branch along the channel dimension to obtain a fused feature. Sub-step S66 uses the fused feature as input to generate the three task branches. Each task branch consists of a fully connected layer, a Dropout layer, and a Softmax layer connected in series. During training, the Dropout layer randomly discards some neurons with a set probability, which can weaken the excessive co-adaptation between features and improve the generalization ability of the network. The preferred Dropout probability is 0.3. The Softmax layer converts the log-odds vector output by the network into a probability vector with components summing to 1. The three task branches output the probability vector of the origin task, respectively. The probability vector of the seed selection task and the probability vector of the time-limited task Sub-step S67 describes the pre-training method of the multi-task parallel convolutional neural network, specifically, based on the multi-task feature tensor of each sample in the training set, the multi-channel spatial image, and the texture feature vector, as well as the corresponding origin label, selection label, and age label, the network is trained end-to-end using a joint loss function expressed by the following formula:
[0115] ;
[0116] In the formula, The value of the joint loss function; , , The loss weights for origin-related tasks, seed selection tasks, and age-related tasks are respectively selected, and the optimal weights are determined. The specific value is determined by a grid search of the validation set; The cross-entropy loss is calculated using the predicted probability vector of the task within parentheses and the one-hot encoding of the corresponding real label. , , These are respectively: origin tasks, seed selection tasks, and year-limit tasks; The L2 regularization coefficient is preferably 1×10. -4 Up to 1×10 -3 ; It is the set of all trainable parameters of the multi-task parallel convolutional neural network; The L2 norm of the vectors within the brackets is squared, i.e., the sum of squares of the elements. The cross-entropy loss is equal to the negative log-likelihood of the true and predicted distributions, driving the network to output a probability distribution consistent with the true labels on each task. The L2 regularization term suppresses excessive growth of the network's trainable parameters to prevent overfitting. Training continues until the joint loss function converges or the number of iterations reaches a preset value, resulting in the trained multi-task parallel convolutional neural network. After the network model parameters are solidified, they are loaded into the embedded computing unit for inference. Sharing the backbone improves data utilization, while task branches retain the uniqueness of each task, enabling the three tasks to obtain mutually compatible discriminative representations from the same perceptual front end.
[0117] Step S7 constrains the three probability vectors output in step S6 based on the pre-constructed set of triplets for origin, variety selection, and age from the existing labeled samples, and then outputs the final result. Sub-step S71 pre-constructs the set of triplets for origin, variety selection, and age based on the existing labeled samples. The set of three elements: origin, variety selection, and age. Each element in the array is a triplet consisting of the known origin category, selection category, and age category from the existing labeled samples. The introduction of this feature aims to suppress physically impossible combinations between the independent outputs of each task. Combinations between forest understory plants that have grown for over 15 years in the wild and those with short lifespans of 3 to 4 years are physically nonexistent. The constraints can suppress such outputs. Sub-step S72 uses the set of candidate origin categories. Selection candidate category set and the set of candidate categories based on age Using the Cartesian product as the search space, we iterate through each candidate triplet and score each candidate triplet according to the following formula:
[0118] ;
[0119] In the formula, Candidate Triples The rating; For the set of candidate categories of place of origin Candidate categories; For the set of candidate categories for seed selection Candidate categories; For the set of candidate categories for the year limit Candidate categories; The probability vector of the origin task output in step S6 is categorized as follows: The components on; The probability vector of the seed selection task output in step S6 is in the category The components on; The probability vector of the time-limited task output in step S6 is in the category The components on; To prevent small positive numbers from overflowing during logarithmic calculations, it can be combined with the method described in sub-step S53. Take the same value; The natural logarithm operator; The triplet reward coefficient is determined by grid search from the validation set partitioned from the training set. This is an indicator function; it takes the value 1 if the condition inside the parentheses is true and 0 if it is false. This refers to the set of three elements: origin, variety, and age. The "belongs" operator. Under the assumption that the three tasks are independent, the joint probability... The logarithm of the product equals the sum of the probabilities of the three logarithms, forming the first three terms of the scoring formula. To avoid logarithmic divergence when the probability component is zero; when the candidate triplet belongs to When the indicator function is 1, the candidate triplet is obtained with a size of Additional rewards The larger the value, the more likely it is to correspond to The stronger the constraints.
[0120] Sub-step S73 selects to make The candidate triple with the highest value is taken as the final output, and the place of origin corresponding to the final output is denoted as . Seed selection category is Year category The probability vector of the origin task output in step S6 is then used in... The components on, the probability vector of the seed selection task in The components on the time limit and the probability vector of the task in the time limit are in The components are used as the output confidence scores for origin, variety selection, and age, respectively. This scoring mechanism integrates the independent probability outputs of the three tasks with the reasonable combination prior observed in the training set. When the independent task probabilities exhibit contradictory local maxima, the overall score still tends to select the physically reasonable combination, thereby improving the robustness of the recognition results.
[0121] Reference Figure 6 The specific structure of the ginseng slice origin traceability system implementing the described method is described below. The system includes a sample stage, a dual-spectrum acquisition module, a standard illumination module, a radiation correction module, an embedded computing unit, a database module, a human-computer interaction display module, and a main control unit. Under the unified scheduling of the main control unit, each module sequentially completes data acquisition, preprocessing, inference, and result output.
[0122] The sample stage is located at the bottom of the system and forms a support platform. Its surface remains horizontal during use. The surface is equipped with a limiting ring for positioning the ginseng slices to be tested. The limiting ring can be adapted and replaced for ginseng slices of different diameters to ensure the stability of the position of the cut surface of the ginseng slices to be tested, providing a stable physical reference for the entire collection process.
[0123] The dual-spectral acquisition module is located directly above the sample stage and includes a VNIR band hyperspectral camera, a SWIR band hyperspectral camera, a synchronization trigger, a dual-camera calibration assembly, and an image registration unit. The VNIR band and SWIR band hyperspectral cameras are mounted side-by-side or coaxially, with the objective lenses of both cameras facing the sample stage. The optical axis is adjusted vertically downwards using a bracket. The synchronization trigger is electrically connected to the trigger terminals of both the VNIR and SWIR band hyperspectral cameras. After the main control unit issues an acquisition command, the synchronization trigger simultaneously sends acquisition pulses to both cameras via hardware triggering to achieve frame-synchronized acquisition. The dual-camera calibration assembly includes a checkerboard calibration plate for dual-camera intrinsic and extrinsic parameter calibration. The checkerboard calibration plate is detachably mounted at a preset position on the sample stage. During initial system deployment or on-site calibration, the intrinsic and extrinsic parameter matrices of the two cameras are obtained by imaging the checkerboard calibration plate. The image registration unit is an image registration program module deployed on the embedded computing unit. It registers the images acquired by the two cameras to the same sectional coordinate system based on the intrinsic and extrinsic parameter matrices. This module as a whole provides the dual-band image data and registration reference required in step S1.
[0124] The standard illumination module is located on the outer periphery of the objective lens of the dual-spectrum acquisition module. It includes a ring illuminator and a diffuse reflection device. The ring illuminator is arranged around the outer side of the objective lens of the dual-spectrum acquisition module to provide a uniform light beam illuminating the central area of the sample stage. The diffuse reflection device is arranged in the optical path between the ring illuminator and the sample stage to convert the direct light from the light source into uniform diffuse light to reduce specular reflection interference. This ensures that the ginseng slice under test receives stable and consistent incident light, thereby improving the signal-to-noise ratio and repeatability of spectral acquisition.
[0125] The radiation correction module includes a flip-up white plate and a dark-field cover. The flip-up white plate is mounted between the sample stage and the dual-spectrum acquisition module via a flipping mechanism. The flipping mechanism includes a stepper motor electrically connected to the main control unit. Under the control of the main control unit, the stepper motor flips the white plate into or out of the acquisition field of view as needed. The reflective surface material of the flip-up white plate is polytetrafluoroethylene (PTFE), which has near-Lambertian diffuse reflection characteristics, serving as a high-reflectivity reference for relative radiation correction. The dark-field cover is fitted onto the objective lens of the dual-spectrum acquisition module via a drive mechanism electrically connected to the main control unit. Under the control of the main control unit, the drive mechanism closes the acquisition field of view, providing the dark field conditions required for dark current and readout noise acquisition. This module as a whole provides two types of reference data for step S2: a white plate image and a dark-field image.
[0126] The embedded computing unit is connected to the image output terminal of the dual-spectral acquisition module via a data interface. The embedded computing unit pre-stores the calibration parameters output by the dual-camera calibration component, the reference spectrum determined during the training phase, the mean vector, the feature band set, the fusion weight matrix, and the model parameters of the trained multi-task parallel convolutional neural network. During the inference phase, the embedded computing unit calls the trained multi-task parallel convolutional neural network to execute the following steps: image registration and stitching in step S1, radiometric correction and spectral preprocessing in step S2, region segmentation and multi-region spectral extraction in step S3, feature band extraction in step S4, feature weighting in step S5, network inference in step S6, and triplet score output in step S7. The embedded computing unit should preferably use an edge computing platform that supports acceleration by a graphics processing unit or neural network processing unit to ensure the real-time performance of the entire inference process.
[0127] The database module is communicatively connected to the embedded computing unit and is used to store training sample features and the set of triplets for origin, variety, and age. During system operation, it provides the set of triplets required in step S7 to the embedded computing unit. Data access. The human-computer interaction display module is communicatively connected to the embedded computing unit, receiving and displaying the identification results of origin, variety, and age, as well as the corresponding confidence level, output by the embedded computing unit. Preferably, a capacitive touch screen is used as the input / output interface, allowing operators to complete sample identification entry, identification initiation, and result export on the screen. The main control unit is electrically connected to the dual-spectrum acquisition module, the standard illumination module, the radiation correction module, the embedded computing unit, and the human-computer interaction display module, respectively. As the core of the entire system's operation scheduling, it is responsible for coordinating each module according to a preset process. The specific sequence is as follows: first, the standard illumination module is started; then, the radiation correction module is controlled to complete dark-field image acquisition and whiteboard image acquisition; then, the dual-spectrum acquisition module is controlled to complete the raw image acquisition; then, the acquisition results are sent to the embedded computing unit to execute steps S2 to S7; finally, the identification results are sent to the human-computer interaction display module for display.
[0128] The system also includes a light shield and a communication module. The light shield is positioned outside the sample stage, the dual-spectrum acquisition module, the standard illumination module, and the radiation correction module to shield the image acquisition from stray light interference, ensuring a quasi-integrating sphere acquisition environment. The communication module is communicatively connected to the embedded computing unit. The communication module includes one or both of a wired and a wireless communication interface. The wired communication interface can be an Ethernet interface or an industrial bus interface, and the wireless communication interface can be a wireless access interface compliant with 4G, 5G, or Wi-Fi standards. The communication module is used to upload the identification results to a higher-level database or a blockchain traceability platform and to receive remotely updated data from the origin, variety, and age triplet set, enabling the expansion of the range of origin, variety, and age combinations supported by the system without retraining the multi-task parallel convolutional neural network.
[0129] This invention uses dual-camera broadband sensing as input, and takes anatomical structure region segmentation, feature band extraction guided by saponin chemical priors, task-driven feature weighting, multi-task parallel convolutional neural networks, and triple set constraints as core components. By introducing chemical priors, geometric priors, statistical priors, and existing labeled data priors into the reasoning process step by step, it enables three tasks—origin, seed selection, and age—to simultaneously output self-consistent recognition results under the same sensing front end.
[0130] The following are several embodiments and comparative examples of the present invention. Each embodiment uses a hyperspectral dataset of ginseng slices synthesized according to the method of the present invention. The synthesized dataset covers 60 candidate triplets, including 5 candidate origins, 3 candidate varieties, and 4 candidate age ranges. Among these, 38 triplets actually exist in the existing labeled samples, constituting the origin, variety, and age triplet set described in the present invention. The differences between the various embodiments lie only in the values of the adjustable parameters of the present invention, and each embodiment fully covers steps S1 to S7 of the present invention.
[0131] Example 1 provides a complete implementation process covering steps S1 to S7. In step S1, sub-step S11 places the ginseng slice to be tested, with a cross-sectional thickness between 1 and 2 mm, within the sample stage limiting ring. Sub-step S12 uses a synchronous trigger to synchronously acquire VNIR and SWIR hyperspectral reflectance images using both cameras. The VNIR band covers 400 to 1000 nm, and the SWIR band covers 1000 to 2500 nm. Sub-steps S13 to S15 sequentially perform distortion correction, homography transformation, spatial resolution resampling, and wavelength axis cubic spline interpolation on the two images. Sub-step S16 stitches the images together along the band dimensions to obtain a size of... The original hyperspectral image. In step S2, sub-steps S21 to S23 sequentially acquire dark field images and whiteboard images and perform relative radiometric correction on the original hyperspectral image pixel by pixel and band by band according to the radiometric correction formula. Sub-step S24 performs smoothing with Savitzky-Golay with a window length of 11 and a polynomial order of 3. Sub-step S25 performs multivariate scattering correction based on the reference spectrum determined in the training phase and mean centering based on the mean vector to obtain the preprocessed spectral matrix. In step S3, sub-step S31 performs morphological opening operations on the 660nm band grayscale image to obtain a foreground binary mask; sub-step S32 stacks the 1450nm band reflectance and the 1690nm band reflectance to construct a multidimensional segmentation feature vector; sub-step S33 performs K-means clustering with a cluster size of 4; sub-step S34 labels four anatomical regions—periderm, phloem, cambium, and xylem—accurately from far to near based on their average radial distance; and sub-steps S35 and S36 obtain four rows of data using the regional mean spectral formula. The multi-region spectral matrix is listed above. In step S4, sub-step S41 selects five saponin prior centers at 1450nm, 1690nm, 1940nm, 2240nm, and 2280nm. Sub-step S42 sets a uniform wavelength axis sampling interval of 2nm within a 20nm window on both sides of each prior center. Sub-steps S43 to S44 refine the pre-determined set of characteristic bands through CARS and PLS-DA iterations during the training phase. The multi-region characteristic spectral matrix with 4 rows and 22 columns was extracted, i.e., the number of characteristic bands. Take 22. In step S5, small positive numbers Pick Task coupling coefficient Set the value to 0.3. Sub-steps S52 to S55 pre-determine the fusion weight matrix according to the dynamic weighting matrix formula and task relevance correction formula described in this invention. Sub-step S51 The weighted result is the size. The multi-task feature tensor. In step S6, the kernel lengths of the three one-dimensional convolutional layers in the spectral branch in sub-step S62 are 7, 5, and 3 respectively; the kernel lengths of the three two-dimensional convolutional layers in the spatial branch in sub-step S63 are 3×3; the input of the texture branch is a 20-dimensional gray-level co-occurrence matrix feature vector; the Dropout probability of the task branch head in sub-step S66 is 0.3; and the three task loss weights in the joint loss function in sub-step S67 are... , and All are taken as 1 / 3, L2 regularization coefficient Pick The Adam optimizer is used for 200 iterations until the joint loss function converges, resulting in the trained multi-task parallel convolutional neural network. In step S7, the triplet reward coefficient... Take 0.8, and in sub-steps S71 to S73, iterate through 60 candidate triples according to the scoring formula and select the triple that maximizes the score as the final output.
[0132] Example 2: The difference between this example and Example 1 is the number of characteristic bands. Taking 18, the CARS and PLS-DA selection process in the remaining sub-steps S43 to S44 delays the iteration number corresponding to the optimal cross-validation classification loss; task coupling coefficient Take 0.5; Triplet reward coefficient The parameter is set to 1.2; the Savitzky-Golay smoothing window length is set to 9; the kernel lengths of the three one-dimensional convolutional layers in sub-step S62 are set to 5, 3, and 3 respectively. The remaining steps and parameter values are exactly the same as in Example 1. This example covers all parameters of the present invention. Small Centered value Larger value combinations.
[0133] Example 3: The difference between this example and Example 1 is the number of characteristic bands. Set the coefficient to 25, which is the task coupling coefficient. Take 0.1, triplet reward coefficient Set the L2 regularization coefficient to 0.5. Pick The Dropout probability is set to 0.5. The remaining steps and parameter values are exactly the same as in Example 1. This example covers all parameters of the present invention. Large Small Smaller value combinations.
[0134] Comparative Example 1 differs from Example 1 in that only the VNIR band hyperspectral camera is used for acquisition, and the SWIR band hyperspectral camera is not used. Therefore, all the contents of sub-steps S13 to S16 involving dual-camera registration, wavelength axis alignment and stitching are omitted. The original hyperspectral image only covers the 400 to 1000 nm band. The processing flow of subsequent steps S2 to S7 is the same.
[0135] Comparative Example 2 differs from Example 1 in that sub-step S32 uses only the 1450nm single-band reflectance as the clustering feature, without stacking the 1690nm band to form a multi-dimensional segmentation feature vector; sub-step S34 directly corresponds the outer bark region, phloem region, cambium, and xylem according to the average reflectance of each cluster from low to high, without introducing an average radial distance constraint. The remaining steps are the same as in Example 1.
[0136] Comparative Example 3 differs from Example 1 in that sub-step S41 does not introduce the five near-infrared characteristic absorption band prior centers of ginsenosides; sub-step S42 performs full-spectrum uniform sampling of the multi-region spectral matrix without window densification; and sub-steps S43 to S44 directly perform CARS and PLS-DA iterative selection on all candidate bands of the uniform sampling. The number of selected characteristic bands is... Take 30. The remaining steps are the same as in Example 1.
[0137] Comparative Example 4 differs from Example 1 in that, in sub-step S54, after encoding the labels of the three tasks as integers 1, 2, and 3, the task correlation matrix is constructed using the Pearson correlation coefficient. Instead of constructing it using normalized mutual information, the remaining steps are the same as in Example 1.
[0138] Comparative Example 5 differs from Example 1 in that, instead of constructing the multi-task parallel convolutional neural network, three complete convolutional neural networks are trained independently for the origin task, seed selection task, and age limit task, respectively. The three networks do not share backbone branches, and sub-step S67 does not use the joint loss function; each network is trained using single-task cross-entropy loss. The remaining steps are the same as in Example 1.
[0139] Comparative Example 6 differs from Example 1 in that it skips all sub-steps of step S7 and directly takes the argmax of the probability vectors of the origin task, seed selection task, and age task output in step S6 as the final output of each task, without being based on the set of triplets for origin, seed selection, and age. Apply scoring constraints. The remaining steps are the same as in Example 1. This comparative example is used to verify that step S7 of the present invention is based on a set of triples. The scoring constraints have a suppressive effect on the combination of physical contradictions between the independent outputs of each task.
[0140] Experiment 1 uses Examples 1, 2, and 3, and Comparative Example 2. The Dice similarity coefficient is employed, defined as the sum of the areas of the intersection of the segmentation result obtained by the method of this invention and twice the area of the manually labeled gold standard. The value falls within a closed interval of 0 to 1, with a value closer to 1 indicating greater consistency between the segmentation result and the gold standard. The Dice similarity coefficient is a standard evaluation metric in image segmentation. This experiment independently extracted 200 samples from the synthetic dataset. For each sample, four anatomical regions were manually labeled as the gold standard. The average Dice coefficients of the four methods on the four anatomical regions were calculated. The experimental results are as follows: Figure 1 As shown.
[0141] Figure 1 The chart is presented as a grouped bar graph. The horizontal axis represents the four anatomical regions: the epidermis, phloem, cambium, and xylem. The vertical axis represents the Dice similarity coefficient. The four groups of bars correspond to Example 1, Example 2, Example 3, and Comparative Example 2, respectively. The example bars are in blue, and the comparative example bars are in red. The Dice coefficient value is labeled at the top of each bar. Figure 1 It can be seen that the Dice coefficients of the three embodiments in the four anatomical regions are all above 0.76, with Embodiment 3 showing the best overall performance, with all four anatomical regions above 0.79; Comparative Example 2 can achieve Dice coefficients of 0.85, 0.71 and 0.88 in the bark, phloem and xylem regions respectively, but the Dice coefficient in the cambium, the thinnest anatomical structure, is only 0.42, which is 0.36 different from 0.78 in Embodiment 1.
[0142] from Figure 1It can be seen that the calibration method described in step S3 of the present invention, which uses the 1450nm band reflectance and the 1690nm band reflectance to form a multidimensional segmentation feature vector and is combined with the average radial distance constraint, can provide stable segmentation on the thin, low-contrast anatomical structure of the ginseng slice cambium. This overcomes the problem that the single-band K-means method is insufficient for segmenting the cambium layer under the reflectance mean sorting method. The conclusion can be explained mechanistically as follows: the 1450nm band corresponds to the absorption of the first harmonic stretching vibration of water molecules (OH), reflecting the distribution of water content in each anatomical region; the 1690nm band corresponds to the absorption of the first harmonic stretching vibration of organic molecules (CH), reflecting the distribution of organic content in each anatomical region; the combined characteristics of the two bands more reliably characterize the differences in chemical composition of each anatomical region than single-band reflectance; at the same time, the ginseng slice cross-section anatomically presents the topological structure of the epidermis, phloem, cambium, and xylem from the outside to the inside, and there is a fixed radial distance order between the pixels of each anatomical region and the geometric center of the cross-section. Using the average radial distance as the calibration basis ensures that the clustering results form a stable correspondence with the actual anatomical structure, making up for the insufficiency of the sorting method based solely on the average reflectance value, which is sensitive to differences in sample dryness and slice thickness.
[0143] Experimental Example 2 uses Examples 1, 2, and 3, and Comparative Example 3. It employs the 5-fold cross-validation classification loss curve in the CARS iteration process and the optimal number of feature bands corresponding to the optimal number of iterations. The hit rate of the 5 saponin prior windows, and the final set of characteristic bands selected. The location distribution. The 5-fold cross-validation classification loss is calculated by using a partial least squares discriminant analysis model to perform 5-fold cross-validation on the training samples and then taking the cumulative average of the classification losses; the hit rate of the 5 saponin prior windows is defined as the final feature band set. The number of characteristic bands falling within the 20nm window on either side of the a priori center of saponins divided by the number of characteristic bands This experiment divides the synthetic dataset into a training set of 1500 simulated spectra and a validation set of 500 simulated spectra. The experimental results are as follows: Figure 2 As shown, Figure 2 include Figure 2 (a) and Figure 2 (b)
[0144] Figure 2 (a) is a comparison of the 5-fold cross-validation classification loss curves during the CARS iteration process. The horizontal axis represents the number of CARS iterations, and the vertical axis represents the 5-fold cross-validation classification loss. The four curves correspond to Example 1, Example 2, Example 3, and Comparative Example 3, respectively. The curves for the examples are represented by solid blue lines, and the curves for the comparative examples are represented by dashed red lines. The optimal number of iterations for each method is marked with a star, and the corresponding optimal feature band number is labeled near the mark. value. Figure 2 (b) represents the final set of selected characteristic bands. The position distribution scatter plot has wavelength on the horizontal axis. The four rows of scatter points correspond to Example 1, Example 2, Example 3 and Comparative Example 3 from top to bottom. The five a priori center positions of saponins at 1450nm, 1690nm, 1940nm, 2240nm and 2280nm are marked by five vertical dashed lines. Gray shading is added on both sides of each dashed line to indicate a priori window with a width of 40nm.
[0145] from Figure 2 As shown in (a), the optimal cross-validation classification losses for the three embodiments are 0.18, 0.21, and 0.17, respectively, corresponding to optimal iteration counts of 30, 35, and 25, and corresponding to optimal feature band counts. The optimal cross-validation classification loss for Comparative Example 3 is 0.27, corresponding to an optimal number of iterations of 22 and an optimal number of feature bands of 22. The optimal loss for all three embodiments was 30; the optimal loss for all three embodiments was significantly lower than that for Comparative Example 3. Figure 2 As can be seen from (b), among the characteristic bands finally selected in the three embodiments, the proportions of the bands falling into the five a priori windows of saponins were 68%, 72% and 65%, respectively, while the proportion in Comparative Example 3 was about 27%.
[0146] from Figure 2 It can be seen that the strategy of wavelength axis densification and resampling described in step S4 of this invention, which uses the center wavelength of the five near-infrared characteristic absorption bands of ginsenosides as the prior center, can be used to select bands with higher chemical relevance, enabling the CARS algorithm to achieve a lower 5-fold cross-validation classification loss with fewer characteristic bands. The near-infrared characteristic absorption of ginsenoside glycosides at OH bonds, CH bonds, and the corresponding combination and sum frequencies carries chemical information about differences in origin, selection, and age. Densifying and resampling the wavelength axis within the saponin prior window makes the candidate band density of CARS match the chemical relevance density, allowing the selection process to prioritize the inclusion of bands with strong discriminative power into the characteristic band set. In contrast, Comparative Example 3 performs full-spectrum uniform sampling without chemical prior, resulting in a large number of candidate bands entering bands unrelated to the chemical differences of saponins, and the discriminative power of the selected characteristic band set is weak. Maintaining the original sampling wavelength outside the window can prevent the candidate space from being completely dominated by the prior, and retain bands sensitive to other chemical differences.
[0147] Experiment 3 employed nine methods: Examples 1, 2, and 3, and Comparative Examples 1, 2, 3, 4, 5, and 6. The metrics used were the classification accuracy for the origin task, selection task, and age task, as well as the joint recognition accuracy for all three tasks. Classification accuracy was defined as the number of correctly predicted samples divided by the total number of samples. The joint recognition accuracy for all three tasks was defined as the number of samples where the outputs for origin, selection, and age were simultaneously correct with the true labels, divided by the total number of samples. This experiment used 500 independent test samples from the synthetic dataset to uniformly test the nine methods. The experimental results are as follows: Figure 3 As shown.
[0148] Figure 3 The horizontal axis of the heatmap represents four indicators: accuracy of origin task, accuracy of seed selection task, accuracy of year task, and accuracy of the three combined tasks. The vertical axis, from top to bottom, represents nine methods: Example 1, Example 2, Example 3, and Comparative Examples 1, 2, 3, 4, 5, and 6. The color of each cell is mapped from light red to dark blue according to the accuracy value; the higher the accuracy, the bluer the color, and the lower the accuracy, the redder the color. The numerical text label of the indicator is superimposed in each cell. The three examples and the six comparative examples are separated by a horizontal line.
[0149] from Figure 3 As can be seen, the accuracy rates of the three examples on the three individual tasks are in the ranges of 94.5-95.5%, 96.2-97.0%, and 90.8-91.5%, respectively, and the joint accuracy rate of the three tasks is in the range of 88.3-89.7%. Comparative Example 1, due to the loss of saponin feature information in the SWIR band by using only a VNIR single camera, saw its accuracy rates on the three individual tasks decrease to 88.1%, 92.3%, and 84.2%, respectively, and the joint accuracy rate of the three tasks further decreased to 78.5%. Comparative Example 4, by replacing normalized mutual information with Pearson correlation coefficient, saw its joint accuracy rate of the three tasks decrease by 3.0 percentage points to 86.7% compared to Example 1. Comparative Example 5, using a single-task CNN without a shared backbone, saw its joint accuracy rate of the three tasks decrease by 3.7 percentage points to 86.0% compared to Example 1. Comparative Example 6 maintained the same accuracy rates on the three individual tasks as Example 1, but its joint accuracy rate of the three tasks decreased due to the loss of saponin feature information in the SWIR band. The constraint decreased by 5.2 percentage points to 84.5%.
[0150] The present invention includes steps S1 (dual-camera broadband acquisition), S5 (constructing a task relevance matrix using normalized mutual information), S6 (multi-task parallel convolutional neural network shared backbone design), and S7 (…). All constraints positively contribute to the final simultaneous recognition performance of the three tasks. This conclusion can be explained mechanistically as follows: the VNIR band provides visible color and absorption information below 1000nm in the near-infrared spectrum, while the SWIR band supplements the absorption band information of saponins above 1000nm. The continuous broad spectrum formed by splicing these two bands allows the classifier to obtain more complete chemical discrimination evidence; normalized mutual information adapts to the statistical characteristics of disordered category labels such as origin and seed selection, avoiding the artificial correlation bias introduced by the Pearson correlation coefficient due to its dependence on integer encoding order; the shared backbone of the multi-task parallel convolutional neural network enables the three tasks to obtain mutually compatible discriminative representations from the same perceptual front end, improving data utilization and generalization ability. The constraint introduces a discrete prior obtained from a reasonable combination of priors derived from the training labeled data outside the probability likelihood space, ensuring that the final output triples are physically consistent. This conclusion proves that steps S1, S5, S6, and S7 of this invention are feasible and have beneficial effects.
[0151] Experimental Example 4 uses Examples 1, 2, and 3, and Comparative Examples 1, 4, 5, and 6. The metrics used are noise robustness curves and the proportion of outputs with physical contradictions. The noise robustness curve refers to the curve showing the change in the joint recognition accuracy of the three tasks as a function of the noise standard deviation after superimposing zero-mean Gaussian white noise with different standard deviations onto the preprocessed spectral matrix. The proportion of outputs with physical contradictions refers to the proportion of triplets output by the method that are physically absent from the set of triplets for origin, variety selection, and age. The proportion of triples in the sample. The noise standard deviation in this experiment was set at eight levels: 0, 0.01, 0.02, 0.03, 0.05, 0.08, 0.10, and 0.15.
[0152] Experimental results are as follows Figure 4 As shown, Figure 4 In the middle (a), there is a line graph of the accuracy of the joint recognition of the three tasks under different noise levels. The horizontal axis is the standard deviation of zero-mean Gaussian white noise, and the vertical axis is the accuracy of the joint recognition of the three tasks. The seven curves correspond to Example 1, Example 2, Example 3 and Comparative Example 1, Comparative Example 4, Comparative Example 5 and Comparative Example 6, respectively. The curves of the examples are represented by solid blue lines, and the curves of the comparative examples are represented by dashed red lines. Figure 4 (b) is a bar chart showing the output ratio of physical contradictions for different methods. The horizontal axis corresponds to Example 1, Example 2, Example 3 and Comparative Example 6 from left to right. The vertical axis represents the output ratio of physical contradictions. The bars for the examples are in blue, and the bars for the comparative examples are in red. The ratio values are marked at the top of the bars.
[0153] from Figure 4As can be seen from (a), in Example 1, as the noise standard deviation increased from 0 to 0.15, the accuracy of the three-task joint recognition decreased from 89.7% to 52.3%; in Comparative Example 6, due to loss of... The constraint was 5.2 percentage points lower than in Example 1 under zero noise, and decreased even faster as noise increased, reaching only 32.7% at a noise standard deviation of 0.15; Comparative Example 1 was 11.2 percentage points lower than in Example 1 under zero noise, decreasing to 19.8% as the noise standard deviation increased to 0.15. From Figure 4 As can be seen from (b), the physical contradiction output ratios of the three embodiments are 1.8%, 0.9%, and 3.2%, respectively, all significantly lower than the 12.5% of Comparative Example 6; Example 2 has a triplet reward coefficient Take 1.2, which is larger. The constraint is strongest, and the output ratio of physical contradictions is lowest; Example 3 is due to Taking 0.5 as a smaller value results in a relatively higher proportion of physical contradictions being output, which aligns with the scoring formula of this invention. The larger the value, the more likely it is to correspond to The stronger the constraint, the more consistent it is with the physical meaning.
[0154] Step S7 of this invention is based on a set of tripartite relationships of origin, seed selection, and age. The scoring constraint, when the probability vectors exhibit contradictory local maxima, can cause the overall score to tend to select physically reasonable combinations, improving the robustness of the three-task joint recognition under noise perturbation and probability contradictions, and the triplet reward coefficient The physical meaning of this has been verified in different implementations. The conclusion can be explained mechanistically as follows: when noise increases or local contradictions appear in the 3-task probability vectors, the triplet selected purely based on the independent argmax of each task probability may fall into a physically non-existent combination, such as selecting a physically contradictory combination of forest ginseng with a growth period of 3 to 4 years, while forest ginseng needs to grow for more than 15 years under wild conditions; Constraints outside the likelihood term provide a size for reasonable combinations. The discrete rewards cause the scoring function to form a potential well near a reasonable combination. Even if the likelihood term is disturbed by noise and has a local maximum, as long as the reward term is sufficient, the overall score will still tend to fall within a reasonable triplet. The larger the value, the higher the relative weight of the reward item compared to the likelihood item, and the more obvious the contradiction suppression effect.
[0155] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for tracing the origin of ginseng slices based on spectral analysis, characterized in that, Includes the following steps: S1: Frame-synchronous acquisition of ginseng slice sections was performed using a visible-near-infrared (VNIR) band hyperspectral camera and a short-wave infrared (SWIR) band hyperspectral camera to obtain VNIR and SWIR band hyperspectral reflectance images. Distortion correction, spatial registration, spatial resolution resampling, and wavelength axis unification were performed on the VNIR and SWIR band hyperspectral reflectance images to make them the same cross-sectional coordinate system. The images were then stitched together according to the band dimensions to obtain the original hyperspectral image. S2: Perform pixel-by-pixel relative radiometric correction on the original hyperspectral image based on the pre-acquired dark field image and whiteboard image, and then perform spectral preprocessing on the radiometrically corrected reflectance image based on the reference spectrum and mean vector determined in advance during the training phase to obtain the preprocessed spectral matrix. S3: Based on at least two bands that reflect the differences in the tissue structure of ginseng slices, construct a region segmentation feature map, and combine clustering algorithm and radial distance constraint to perform region segmentation on the preprocessed spectral matrix to obtain a multi-region spectral matrix composed of representative spectra of the four anatomical regions: the outer skin region, the phloem region, the cambium and the xylem. S4: Within a specified window centered on the near-infrared characteristic absorption band of ginsenosides, the multi-region spectral matrix is resampled by wavelength axis interpolation. Based on a pre-determined set of characteristic bands, the corresponding columns are extracted from the resampled multi-region spectral matrix to obtain the multi-region characteristic spectral matrix. S5: The multi-region feature spectral matrix is weighted based on a pre-determined fusion weight matrix to obtain a multi-task feature tensor; S6: The multi-task feature tensor, the multi-channel spatial image extracted from the preprocessed spectral matrix according to the feature band set, and the texture feature vector extracted based on the gray-level co-occurrence matrix are respectively fed into the spectral branch, spatial branch, and texture branch of the pre-trained multi-task parallel convolutional neural network. The three task branches of the multi-task parallel convolutional neural network output the probability vectors of the origin task, the seed selection task, and the age task, respectively. S7: Based on the set of triplets of origin, variety, and age pre-constructed from existing labeled samples, score each candidate triplet by traversing the three probability vectors output in step S6, and select the triplet that makes the score the maximum as the final result output.
2. The method for tracing the origin of ginseng slices based on spectral analysis according to claim 1, characterized in that, Step S1 specifically includes: S11: Place the ginseng slice to be tested inside the limiting ring of the sample stage, so that the cut surface of the ginseng slice to be tested faces the direction of spectral acquisition; S12: Simultaneously send acquisition trigger signals to the VNIR band hyperspectral camera and the SWIR band hyperspectral camera through a synchronization trigger, so that the VNIR band hyperspectral camera and the SWIR band hyperspectral camera synchronously acquire the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image of the cross section of the ginseng slice to be tested. S13: Using the pre-stored intrinsic and extrinsic parameter matrices of the VNIR band hyperspectral camera and the SWIR band hyperspectral camera, lens distortion correction is performed on the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image, and the two are mapped to the same sectional coordinate system through homography transformation; S14: Downsample the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image with higher resolution after mapping to the same sectional coordinate system, so that the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image have the same spatial resolution, and obtain the spatially registered VNIR band hyperspectral reflectance image and SWIR band hyperspectral reflectance image. S15: Based on a pre-determined unified wavelength axis, the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image, after spatial registration, are respectively interpolated along the band dimension to make their wavelength sampling positions consistent; within the overlapping region of the spectral response of the two cameras, response consistency correction is performed on the overlapping band based on the dual-camera response consistency correction coefficient pre-determined during the training phase. S16: Stitch the VNIR band hyperspectral reflectance image and the SWIR band hyperspectral reflectance image after response consistency correction in the band dimension to obtain a size of [missing information]. The original hyperspectral image, wherein The number of rows in the image. The number of columns in the image. This represents the total number of bands after merging.
3. The method for tracing the origin of ginseng slices based on spectral analysis according to claim 1, characterized in that, Step S2 specifically includes: S21: Close the light-blocking dark field cover and acquire a dark field image. The dark field image is located at the pixel position. ,wavelength The DN value at the location is denoted as ; S22: Flip the whiteboard into the acquisition field of view and acquire the whiteboard image. The whiteboard image is located at pixel position. ,wavelength The DN value at the location is denoted as ; S23: Based on the dark field image and the whiteboard image, perform relative radiometric correction on the original hyperspectral image pixel by pixel and band by band according to the following formula to obtain the reflectance image: ; In the formula, pixel position At wavelength Reflectance at that location; These are the row coordinates of the image; These are the column coordinates of the image; Wavelength (nm); For the original hyperspectral image at pixel location ,wavelength The DN value at that location; For the dark field image at pixel position ,wavelength The DN value at that location; The whiteboard image at pixel position ,wavelength The DN value at that location; S24: Perform Savitzky-Golay smoothing on the reflectance image along the band dimension; S25: Perform multivariate scattering correction on the Savitzky-Golay smoothed reflectance image based on the reference spectrum predetermined and stored during the training phase; then perform mean centering processing on the multivariate scattering corrected reflectance image along the band dimension based on the mean vector predetermined and stored during the training phase to obtain the preprocessed spectral matrix.
4. The method for tracing the origin of ginseng slices based on spectral analysis according to claim 1, characterized in that, Step S3 specifically includes: S31: Extract the two-dimensional grayscale image corresponding to the 660nm band from the preprocessed spectral matrix, perform morphological opening operation on the two-dimensional grayscale image, and obtain the foreground binary mask of the ginseng slice section. S32: Extract at least two two-dimensional grayscale images corresponding to bands that reflect differences in tissue structure from the preprocessed spectral matrix. The at least two bands include the 1450nm band, which is sensitive to water content, and the 1690nm band, which is sensitive to CH bond content. Stack the reflectance values corresponding to the at least two bands to form a multidimensional segmentation feature vector for each pixel position in the foreground binary mask, and obtain a region segmentation feature map. S33: For the pixels within the foreground binary mask, perform K-means clustering based on the multidimensional segmentation feature vector, with a cluster size of 4, resulting in 4 clusters; S34: Determine the geometric center of the foreground binary mask, calculate the average radial distance from all pixels in each cluster to the geometric center, and sequentially label the four clusters as the corresponding anatomical regions of the epidermis, phloem, cambium, and xylem according to the average radial distance from far to near, to obtain the first... Binary mask for each anatomical region ,in The numbers are 1, 2, 3, and 4. S35: Calculate the representative spectrum of each of the four anatomical regions using the following formula: ; In the formula, For the first Each anatomical region at wavelength The representative spectral value at that location; For indexing anatomical regions. , , , These correspond to the outer bark, phloem, cambium, and xylem, respectively. Wavelength (nm); For the first The set of all pixel locations within an anatomical region, defined by the binary mask. Sure; For set The number of elements; These are the row and column coordinates of the pixel; The preprocessed spectral matrix at the pixel position ,wavelength The reflectance value at that location; S36: Stack the representative spectra of the four anatomical regions row by row to obtain 4 rows. The multi-region spectral matrix of the column, wherein The total number of bands in the preprocessed spectral matrix.
5. The method for tracing the origin of ginseng slices based on spectral analysis according to claim 1, characterized in that, Step S4 specifically includes: S41: The center wavelength of the near-infrared characteristic absorption band of ginsenosides is used as the a priori center. The center wavelength of the a priori center includes 1450nm, 1690nm, 1940nm, 2240nm and 2280nm, which correspond to the OH first harmonic, CH first harmonic, OH and water combination frequency, CH and CO combination frequency and CH deformation vibration frequency of ginsenoside molecules, respectively. S42: Within a 20nm window on both sides of the center wavelength of each prior center, the spectral data of the multi-region spectral matrix is mapped to a predetermined unified wavelength axis by wavelength axis interpolation resampling. The sampling interval of the unified wavelength axis within the window is no greater than 2nm, and the original sampling wavelength of the multi-region spectral matrix is maintained outside the window to obtain a candidate spectral matrix. S43: Based on a pre-determined set of characteristic bands Extract the corresponding columns from the candidate spectral matrix to obtain 4 rows. The multi-region characteristic spectral matrix of the column, the set of characteristic bands ,in The first in the set of characteristic bands The wavelengths corresponding to each characteristic band For characteristic band index, The number of characteristic bands in the set of characteristic bands; S44: The set of characteristic bands The candidate spectral matrix of each sample in the training set is pre-determined as follows: Based on the wavelength axis interpolation resampling method described in S42, the candidate spectral matrix of each sample in the training set is constructed; the origin label, seed selection label, and year label of each sample in the training set are concatenated into a reference vector after one-hot encoding; a competitive adaptive reweighted sampling algorithm combined with a partial least squares discriminant analysis model is used, with the column vector corresponding to each candidate band in the candidate spectral matrix as the input feature and the reference vector as the output target, for iterative selection. In each iteration, a partial least squares discriminant analysis model is established by extracting training samples from a Monte Carlo subset and calculating the cross-validation classification loss; the bands corresponding to the subset that minimizes the cross-validation classification loss are selected as the feature band set. .
6. The method for tracing the origin of ginseng slices based on spectral analysis according to claim 1, characterized in that, Step S5 specifically includes: S51: Based on the fusion weight matrix, the four regional components at each feature band position in the multi-region feature spectral matrix are simultaneously weighted. Specifically, for each column of the multi-region feature spectral matrix, three sets of weighted column vectors are obtained by simultaneously weighting the feature band position in the columns corresponding to the origin task, seed selection task, and year task in the fusion weight matrix. The three sets of weighted column vectors obtained at all feature band positions are stacked along the task dimension to obtain a size of... Multitasking feature tensor; The fusion weight matrix is predetermined from the training set through the following steps S52 to S55: S52: For each sample in the training set, the multi-region feature spectral matrix of that sample is averaged along the region dimension to obtain... 3D feature vector, the The 3D feature vector, along with the corresponding origin label, selection label, and year label of the sample, constitutes a training sample pair; using the 3D feature vector of all samples in the training set... 3D eigenvectors at the th The components at each characteristic band position constitute the eigenvector. To train all samples in the task The labels on the vector form a label vector. ; S53: Based on the feature vector and the label vector Construct a dynamic weighted matrix using the following formula. : ; In the formula, For the dynamic weighting matrix at the th Journey, Task Column elements; For characteristic band index; For task indexing, Pick , , These correspond to tasks related to the place of origin, seed selection, and time limit, respectively. For all samples in the training set 3D eigenvectors at the th The feature vector is composed of the components at each feature band position; For all samples in the training set in the task The label vector formed by the labels on the label; The mutual information of the two vectors within the parentheses on the training set; A temporary index for summation; For all samples in the training set 3D eigenvectors at the th The feature vector is composed of the components at each feature band position; The number of characteristic bands in the set of characteristic bands; To prevent small positive numbers with a denominator of zero; S54: Calculate the normalized mutual information between pairs of labels for origin task, seed selection task, and age task on the training set, and construct a 3x3 task relevance matrix. The task relevance matrix The diagonal elements are 1, and the off-diagonal elements are the normalized mutual information between the label vectors of the two corresponding tasks. S55: Construct the intermediate weight matrix using the following formula Then, for the intermediate weight matrix Normalize by column so that the sum of all elements in the column corresponding to each task is 1, thus obtaining the fusion weight matrix. : ; In the formula, This is the intermediate weight matrix; The dynamic weighting matrix; It is a 3x3 identity matrix; The task coupling coefficient is determined by grid search from the validation set partitioned from the training set. This is the task relevance matrix.
7. The method for tracing the origin of ginseng slices based on spectral analysis according to claim 1, characterized in that, Step S6 specifically includes: S61: The multi-task parallel convolutional neural network includes three parallel backbone branches: the spectral branch, the spatial branch, and the texture branch, as well as the three task branch heads located after the output of the three parallel backbone branches; S62: The spectral branch consists of three sequentially connected one-dimensional convolutional layers, each followed by a modified linear unit activation function and a batch normalization layer; the size is... The multi-task feature tensor rearrangement is based on The input tensor, consisting of 12 channels formed by combining 4 anatomical regions and 3 tasks, with each feature band representing the sequence length, serves as the input to the spectral branch. S63: The spatial branch consists of three sequentially connected two-dimensional convolutional layers, each followed by a modified linear unit activation function and a batch normalization layer; the input of the spatial branch is the multi-channel spatial image extracted from the preprocessed spectral matrix according to the feature band set; S64: The texture branch consists of two fully connected layers connected in series; the input of the texture branch is the texture feature vector, which is composed of four statistical quantities: energy, contrast, correlation and entropy of the gray-level co-occurrence matrix extracted from the two-dimensional gray-level image corresponding to the 660nm band in the preprocessed spectral matrix at four directions (0°, 45°, 90° and 135°) and multiple pixel distances. S65: Concatenate the outputs of the spectral branch, the spatial branch, and the texture branch along the channel dimension to obtain a fused feature; S66: Using the fused features as input, the three task branches are derived. Each task branch consists of a fully connected layer, a Dropout layer, and a Softmax layer connected in series. The three task branches output the probability vector of the origin task, respectively. The probability vector of the seed selection task and the probability vector of the time-limited task ; S67: The multi-task parallel convolutional neural network is pre-trained in the following manner: based on the multi-task feature tensor, the multi-channel spatial image, and the texture feature vector of each sample in the training set, and the corresponding origin label, selection label, and age label, the multi-task parallel convolutional neural network is trained end-to-end using a joint loss function expressed in the following formula until the joint loss function converges or the number of iterations reaches a preset value, thus obtaining the trained multi-task parallel convolutional neural network: ; In the formula, The value of the joint loss function; , , The loss weights are respectively for tasks related to production location, seed selection, and age. The cross-entropy loss is calculated using the predicted probability vector of the task within parentheses and the one-hot encoding of the corresponding real label. , , These are respectively: origin tasks, seed selection tasks, and year-limit tasks; The L2 regularization coefficient; It is the set of all trainable parameters of the multi-task parallel convolutional neural network; It is the square of the L2 norm of the vector inside the brackets.
8. The method for tracing the origin of ginseng slices based on spectral analysis according to claim 1, characterized in that, Step S7 specifically includes: S71: Based on the existing labeled samples, pre-construct the set of triplets for origin, variety selection, and age. The set of three elements: origin, variety selection, and age. Each element in the array is a triplet that is known to exist in the existing labeled samples; S72: Based on the set of candidate categories for place of origin Selection of candidate categories and the set of candidate categories based on age Using the Cartesian product as the search space, we traverse each candidate triplet. Each candidate triplet is scored using the following formula: ; In the formula, Candidate Triples The rating; For the set of candidate categories of place of origin Candidate categories; For the set of candidate categories for seed selection Candidate categories; For the set of candidate categories for the year limit Candidate categories; The probability vector of the origin task output in step S6 is categorized as follows: The components on; The probability vector of the seed selection task output in step S6 is in the category The components on; The probability vector of the time-limited task output in step S6 is in the category The components on; To prevent small positive numbers from overflowing in logarithmic calculations; The natural logarithm operator; The triplet reward coefficient is determined by grid search from the validation set partitioned from the training set. This is an indicator function; it takes the value 1 if the condition inside the parentheses is true and 0 if it is false. This refers to the set of ternary pairs of origin, variety selection, and age. For the membership operator; S73: Select to make The candidate triple with the highest value is taken as the final output, and the place of origin corresponding to the final output is denoted as . Seed selection category is Year category The probability vector of the origin task output in step S6 is then used in... The components on, the probability vector of the seed selection task in The components on the time limit and the probability vector of the task in the time limit are in The components on the graph are used as the output confidence levels for origin, variety selection, and age, respectively.
9. A ginseng slice origin traceability device based on spectral analysis, used to implement the method according to any one of claims 1 to 8, characterized in that, It includes a sample stage, a dual-spectrum acquisition module, a standard illumination module, a radiation correction module, an embedded computing unit, a database module, a human-computer interaction display module, and a main control unit; The sample stage is used to hold the ginseng slices to be tested. The dual-spectral acquisition module includes a VNIR band hyperspectral camera, a SWIR band hyperspectral camera, a synchronization trigger, a dual-camera calibration component, and an image registration unit. Both the VNIR and SWIR band hyperspectral cameras are located above the sample stage with their objectives facing the stage. The synchronization trigger is electrically connected to the trigger terminals of both the VNIR and SWIR band hyperspectral cameras. The dual-camera calibration component is used to pre-calibrate the intrinsic and extrinsic parameter matrices of the VNIR and SWIR band hyperspectral cameras. The image registration unit registers the images acquired by the VNIR and SWIR band hyperspectral cameras to the same sectional coordinate system based on the intrinsic and extrinsic parameter matrices. The standard illumination module includes a ring lamp and a diffuse reflection device. The ring lamp is arranged around the outside of the objective lens of the dual-spectrum acquisition module, and the diffuse reflection device is arranged in the optical path between the ring lamp and the sample stage. The radiation correction module includes a flip-up whiteboard and a dark field cover. The flip-up whiteboard is installed between the sample stage and the dual-spectrum acquisition module via a flipping mechanism, and the dark field cover is closed onto the objective lens of the dual-spectrum acquisition module via a driving mechanism. The embedded computing unit is connected to the image output terminal of the dual-spectrum acquisition module via a data interface. The embedded computing unit pre-stores the calibration parameters output by the dual-camera calibration component, the reference spectrum determined during the training phase, the mean vector, the feature band set, the fusion weight matrix, and the model parameters of the trained multi-task parallel convolutional neural network. The embedded computing unit is used to call the trained multi-task parallel convolutional neural network to execute the following steps in the method: image registration and stitching in step S1, radiometric correction and spectral preprocessing in step S2, region segmentation and multi-region spectral extraction in step S3, feature band extraction in step S4, feature weighting in step S5, network inference in step S6, and triplet score output in step S7. The database module is communicatively connected to the embedded computing unit and is used to store training sample features and the set of triplets of origin, variety, and age. The human-computer interaction display module is communicatively connected to the embedded computing unit and is used to display the identification results of origin, variety, and age output by the embedded computing unit, as well as the corresponding confidence level. The main control unit is electrically connected to the dual-spectrum acquisition module, the standard illumination module, the radiation correction module, the embedded computing unit, and the human-computer interaction display module, respectively, and is used to coordinate the above modules to complete the execution flow of steps S1 to S7 of the method.
10. The ginseng slice origin traceability device based on spectral analysis according to claim 9, characterized in that... : The sample stage is provided with a limiting ring for positioning the ginseng slice to be tested. The dual-camera calibration component of the dual-spectrum acquisition module includes a checkerboard calibration plate, which is detachably mounted on the sample stage surface; the image registration unit is an image registration program module deployed on the embedded computing unit. The reflective surface material of the flip-up whiteboard in the radiation correction module is polytetrafluoroethylene, the flipping mechanism includes a stepper motor electrically connected to the main control unit, and the drive mechanism is electrically connected to the main control unit. The device also includes a light shield and a communication module; the light shield is located outside the sample stage, the dual-spectrum acquisition module, the standard illumination module, and the radiation correction module; the communication module is communicatively connected to the embedded computing unit, and the communication module includes one or both of a wired communication interface and a wireless communication interface, used to upload the identification results to a higher-level database or a blockchain traceability platform and receive remotely updated data of the origin, variety, and age tripartite set.