A machine learning-based food sample retention quality monitoring method

By constructing a machine learning model based on dynamic distribution alignment, physical constraint adversarial enhancement, and multi-scale residual spatiotemporal network, the problems of distribution offset, physical laws, and environmental factors in food sample quality monitoring were solved, achieving efficient and real-time quality monitoring and accurate identification of deterioration events in food samples.

CN121327625BActive Publication Date: 2026-02-17SHANDONG INST FOR FOOD & DRUG CONTROL
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511881901.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-15
Publication Date
2026-02-17
Estimated Expiration
2045-12-15

AI Technical Summary

Technical Problem

Existing technologies for monitoring the quality of food samples suffer from problems such as distribution bias, data generation that does not conform to physical laws, difficulty in capturing multi-scale features, and neglect of the influence of environmental factors, leading to decreased model classification performance and inaccurate identification of deterioration events.

Method used

A machine learning model is constructed by employing a dynamic distribution alignment module, a physical constraint adversarial enhancement module, a multi-scale residual spatiotemporal network, and a dynamic attention mechanism. This model monitors food samples in real time using a sensor array and utilizes physical constraints and environmental modulation to enhance the attention mechanism, thereby capturing key spatiotemporal features in the food deterioration process.

Benefits of technology

It enables efficient and real-time quality monitoring of food samples, improves the model's classification performance under various storage conditions, ensures that the generated data conforms to the biochemical laws of food deterioration, and accurately identifies key deterioration events.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121327625B_ABST
    Figure CN121327625B_ABST
Patent Text Reader

Abstract

The application relates to a food sample quality monitoring method based on machine learning, and specifically as follows: a sensor array is arranged in a food sample environment, multi-dimensional physical and chemical characteristic data of the sample are collected in real time, a training set is constructed by using historical normal and deteriorated batch data, and a state is labeled; a machine learning model for food sample quality monitoring is constructed, sample data in the training set is input into the model, sequentially passes through a dynamic distribution alignment module, a physical constraint adversarial enhancement module and a multi-scale residual space-time network, dynamic attention mechanism enhancement is carried out by using physical constraints and environmental modulation, and finally a quality category probability is output by a multi-modal classifier; then, model loss is calculated, the model is iteratively trained, and a trained model is obtained; the trained model is deployed on a sample monitoring terminal, monitoring data newly collected are input, and the quality state of the food sample is predicted. The application can realize efficient and real-time quality monitoring of the food sample.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of artificial intelligence and food monitoring technology, and particularly relates to a food sample quality monitoring method based on machine learning. BACKGROUND

[0002] With the growth of global population and the improvement of living standards, consumers are increasingly demanding food quality, and food safety has become a social focus. Food sample preservation is an important part of food safety management and an important basis for tracing food safety accidents. According to relevant national food hygiene regulations, in order to ensure food hygiene and safety and prevent food poisoning accidents, if food poisoning occurs, the cause of the food poisoning can be found out in time and effective treatment measures can be taken. Food is taken out according to the regulations and a part of it is preserved to implement the food sample preservation system. However, food is easily affected by external environmental factors, and changes in storage conditions will directly affect its quality and safety. Traditional food quality detection methods mainly rely on manual sensory evaluation or limited laboratory detection, which not only consumes time but also makes it difficult to achieve efficient and real-time quality monitoring. With the rapid development of artificial intelligence technology, especially the wide application of deep learning in image recognition, time series analysis and other fields, more and more researchers have begun to try to apply these technologies to food quality monitoring.

[0003] However, the existing technology has many shortcomings in practical application: the conventional data standardization method cannot effectively handle the distribution deviation between different batches, which easily leads to a decrease in model classification performance and makes it difficult to cope with various storage environments. The existing generative adversarial network technology easily ignores the biophysical laws when generating samples, resulting in generated data that does not meet the actual physical conditions and lacks biochemical constraints; the conventional convolutional neural network is difficult to extract both local mutations and global gradual changes in the food deterioration process, and cannot fully capture multi-scale spatiotemporal information; the existing attention mechanism ignores the influence of external environmental factors and has certain limitations when focusing on key deterioration events, making it difficult to accurately identify the key moment of food deterioration.

[0004] Therefore, the present application proposes a food sample quality monitoring method based on machine learning to solve the above problems. SUMMARY

[0005] The present application is developed to solve the problems of the prior art, and provides a food sample quality monitoring method based on machine learning. The present application can realize efficient and real-time quality monitoring of food sample quality.

[0006] The technical scheme for solving the technical problem of the present application is a food sample quality monitoring method based on machine learning, comprising the following steps:

[0007] S1, deploying a sensor array in a food sample environment to collect real-time monitoring data of the food sample, continuously monitoring the multidimensional physical and chemical properties of the sample, constructing a training set from historical normal batch and deteriorated batch data, and labeling the state of the detection data in the training set;

[0008] S2, constructing a machine learning model for food sample quality monitoring, inputting sample data in the training set into the model, sequentially passing through a dynamic distribution alignment module, a physical constraint adversarial enhancement module, and a multi-scale residual spatio-temporal network, using physical constraints and environmental modulation to enhance the dynamic attention mechanism, and finally outputting the quality category probability by a multi-modal classifier; then calculating the model loss, iteratively training the model, and obtaining the trained model;

[0009] S3, deploying the trained model in the sample monitoring terminal, inputting newly collected monitoring data, and predicting the quality state of the food sample.

[0010] S1 is as follows:

[0011] Data is collected at a fixed cycle and frequency, and the collected monitoring data constitutes a time series data matrix, each batch including time series data of a fixed time length;

[0012] The data in the training set covers monitoring data under different storage conditions;

[0013] Data labeling is divided into three quality states: fresh, slightly deteriorated, and severely deteriorated, according to the physicochemical detection results of the sample by food quality inspection experts, each sample is assigned a category label according to the correspondence between sensor data trends and laboratory test reports, and a labeled training set is formed.

[0014] S2 is as follows:

[0015] The machine learning model for food sample quality monitoring is constructed, the time series data matrix composed of detection data in the training set is input into the model, first passes through a dynamic distribution alignment module, the conditional mutual information of the time series data matrix and the global reference distribution is calculated, a differentiable alignment matrix is dynamically constructed, and aligned data is generated; then the sample data is physically constrained through a physical constraint adversarial enhancement module, a food property driven adversarial regularization term is calculated, the generator is constrained to satisfy the differential relationship defined by the domain knowledge, and enhanced data is generated; the aligned data and the enhanced data are input into a multi-scale residual spatio-temporal network, through a double-path residual architecture, the cross-time scale feature interaction is captured by using a dilated convolution kernel and an expanded long short-term memory network, multi-scale features are extracted, and fusion features are output; the dynamic attention mechanism is enhanced by using physical constraints and environmental modulation, the historical degradation mode and the fusion features are combined to enhance the focusing ability of the key spatio-temporal features in the food degradation process, and attention weighted features are output; finally, a quality category probability is output by a multi-modal classifier; then, an environmental modulation factor and a historical degradation mode are combined to construct a multi-task loss function to calculate the model loss, and a small batch gradient descent method is used to iteratively train the model to obtain a trained model.

[0016] The operations in the dynamic distribution alignment module are as follows:

[0017] The KL divergence between the data distribution of each sensor in the sensor set and the global reference distribution is calculated, and the Pearson correlation coefficient between the time series data of the sensor and the global reference sensor time series data is calculated, then the coupling results of the two are exponentially transformed and averaged to obtain the alignment factor of the food for dynamically adjusting the alignment strength;

[0018] The combination of the affine transformation matrix and the rotation matrix is controlled by the alignment factor, and the original data is input into a multi-layer perception network for nonlinear transformation, and the global mean vector and the global standard deviation vector are combined to perform linear transformation through the hyperbolic tangent activation function, and the aligned data is obtained by weighted summation after dynamic correction.

[0019] The operations in the physical constraint adversarial enhancement module are as follows:

[0020] The coupling relationship between multiple sensors in the key sensor state vector is defined to form a physical constraint function describing the coupling law of the sensors in the food degradation process;

[0021] The discriminator output probability of the real data and the generated data is calculated by the expectation operator, and the Frobenius norm of the Jacobian matrix of the physical constraint function is combined as a regularization term, and a weighting factor is used to control the importance of the regularization term, so that the generated samples are forced to satisfy the physical constraint function when training the discriminator;

[0022] The base data is output by the generator, transformed by the physical constraint mapping network, expanded to the sensor dimension by tensor product operation using the physical constraint mask matrix, and then output by the physical constraint enhancement weight control correction strength, which conforms to the sensor coupling relationship in the food deterioration process.

[0023] The operation in the multi-scale residual spatio-temporal network is as follows:

[0024] The enhanced data and the aligned data are spliced along the feature dimension and input into the residual block, and the multi-scale features output by the parallel branches are extracted by setting convolution kernels with different hole rates.

[0025] The aligned data after the transformation of the gating weight matrix and the enhanced data after the hyperbolic tangent activation are input into the dilated long short-term memory network, the memory dependence range of the time dimension is expanded by setting the dilation step, and the output features of the global gradual change path for capturing the long-term gradual trend in the food deterioration process are obtained.

[0026] After splicing the local mutation features and the global gradual change features along the feature dimension, the weighted transformation is performed through the Sigmoid activated attention weight vector and the hyperbolic tangent activated fusion weight matrix, respectively, and then the fusion features are obtained after combining the physical attention features.

[0027] The process of dynamic attention mechanism enhancement of physical constraints and environmental modulation is as follows:

[0028] The similarity between the average physical constraint features and the historical deterioration mode is calculated, and the environmental factors are modulated to dynamically generate the attention weight at each time point.

[0029] The linear transformation of the average fusion features and the average physical constraint output is combined with the Sigmoid activation function to calculate the attention weight of the feature channel.

[0030] The time attention weight and the feature channel attention weight are combined through the outer product operation to generate the spatio-temporal attention matrix, and the element-wise multiplication is performed with the fusion features, while the projection of the physical attention features is introduced as a residual term to generate the attention weighted features.

[0031] The quality classification logic value is generated by calculating the gated product of the time aggregation vector of the attention weighted features and the environmental factor modulation vector, and combining the historical deterioration mode matching score, and the quality category probability is obtained by the Softmax function.

[0032] The calculation process of the loss function is as follows:

[0033] The cross entropy between the quality category probability and the degree of violation of the physical constraint is calculated, and the environmental modulation factor and the physical constraint prototype are combined to construct a physical constraint consistency loss term;

[0034] The weights of the classification loss and the physical constraint loss are dynamically adjusted by the environmental modulation factor and the historical matching score, and a weight decay regularization term is combined to construct a multi-task loss function.

[0035] The iterative training process of the model is as follows:

[0036] The model training adopts a small batch gradient descent method, and each iteration includes two stages of forward propagation and back propagation;

[0037] In the forward propagation stage, the input batch data sequentially performs dynamic distribution alignment, physical constraint counter-enhancement, multi-scale feature extraction, dynamic attention enhancement and classification output operation to generate a quality category probability vector;

[0038] In the back propagation stage, the gradient is calculated based on the total loss of the model, and the model parameters are updated by the adaptive optimizer;

[0039] The training stop condition is set, and when the condition is met, the training of the model is completed.

[0040] S3 is as follows:

[0041] For food sample quality monitoring, the trained model is deployed to the sample monitoring terminal in the monitoring stage, the monitoring data of the food sample recorded by the sensor are collected in real time, input into the trained model, the quality state of the food sample is predicted, and the corresponding warning signal is triggered according to the prediction result, and the deterioration time point and the associated sensor abnormal index are recorded, and a report can be generated for the quality inspector to review.

[0042] The effects provided in the summary of the invention are only the effects of the embodiments, not all the effects of the invention, and the above technical solutions have the following advantages or beneficial effects:

[0043] The application discloses a food sample quality monitoring method based on machine learning, and specifically solves the distribution deviation problem of food sensor data between different batches through a dynamic distribution alignment technology, avoids the problem of blurred quality discrimination boundary caused by conventional Z-score standardization, and thus improves the classification performance of the model under various storage conditions; the application also adopts a physically constrained generative adversarial network, and in combination with a food characteristic driven physical coupling equation, can ensure that the generated data conforms to the biochemical law in the food deterioration process, and avoids the risk of generating unrealistic data by violating the physical law in the conventional generative adversarial network; the multi-scale residual spatio-temporal feature extraction network designed by the application can capture both the local mutation features and the global gradual change features in the food deterioration process, and thus overcomes the deficiency of the conventional convolutional neural network that is difficult to extract multi-scale information; the dynamic attention mechanism with physical constraints and environmental modulation proposed by the application dynamically adjusts the attention weight by combining the historical deterioration mode and real-time environmental factors, improves the focusing ability of the system on the key spatio-temporal features in the food deterioration process, and solves the problem that the conventional attention mechanism cannot accurately capture the key deterioration events. BRIEF DESCRIPTION OF DRAWINGS

[0044] The accompanying drawings are included to provide a further understanding of the application, and constitute a part of the specification, illustrate the application, and are used to explain the application together with the embodiments of the application, and do not constitute a limitation on the application.

[0045] Figure 1 It is a method flowchart of the application.

[0046] Figure 2 It is the change trend of pH value of fresh milk under different quality states.

[0047] Figure 3 It is the change trend of lactic acid bacteria concentration of fresh milk under different quality states.

[0048] Figure 4 It is the change trend of temperature of fresh milk under different quality states.

[0049] Figure 5 Importance score of different characteristics for fresh milk quality detection.

[0050] Figure 6 Robustness comparison of the method of the application and the existing method under sensor noise. DETAILED DESCRIPTION

[0051] In order to clearly illustrate the technical features of the scheme, the application will be described in detail below with reference to the specific embodiments and the accompanying drawings.

[0052] Example 1

[0053] As Figure 1As shown, a machine learning-based food sample quality monitoring method includes the following steps:

[0054] S1, deploying a sensor array in a food sample environment to collect food sample monitoring data in real time, continuously monitoring the multidimensional physical and chemical properties of the sample, constructing a training set from historical normal batch and deteriorated batch data, and labeling the state of the detection data in the training set;

[0055] S2, constructing a machine learning model for food sample quality monitoring, inputting sample data in the training set into the model, sequentially passing through a dynamic distribution alignment module, a physical constraint adversarial enhancement module, and a multi-scale residual spatio-temporal network, using physical constraints and environmental modulation to enhance the dynamic attention mechanism, and finally outputting the quality category probability by a multi-modal classifier; Then calculate the model loss, iterate the model training, and get the trained model;

[0056] S3, deploying the trained model in the sample monitoring terminal, inputting the newly collected monitoring data, and predicting the quality state of the food sample.

[0057] In the specific implementation process, the method is used for quality monitoring of fresh milk samples. Fresh milk is a dairy product that is prone to spoilage. It is monitored at different stages of production, transportation, and storage. The spoilage stage and cause can be traced, and appropriate improvement measures can be taken to ensure product quality.

[0058] In the specific implementation, S1 is as follows:

[0059] The food sample monitoring data is collected in real time by a sensor array deployed in the fresh milk sample environment. Specifically, a variety of sensors are used to continuously monitor the multidimensional physical and chemical properties of the sample video. The sensors are determined according to the characteristics of fresh milk and the storage environment. In the specific implementation process, 15 food quality monitoring sensors are used, including:

[0060] Temperature, in degrees Celsius (℃), monitored directly by a temperature sensor;

[0061] pH value, dimensionless, monitored by a pH electrode sensor;

[0062] Conductivity, in microsiemens per centimeter (μS / cm), monitored by a conductivity sensor;

[0063] Lactic acid bacteria concentration, in colony forming units per milliliter (CFU / mL), monitored by a biological optical sensor or impedance method;

[0064] Fat content, in percentage (%), monitored by a near-infrared spectroscopy sensor;

[0065] Protein content, in percent (%), monitored by near-infrared spectroscopy sensor;

[0066] Viscosity, in millipascal-seconds (mPa·s), monitored by rotational viscosity sensor;

[0067] Oxidation-reduction potential, in millivolts (mV), monitored by ORP sensor;

[0068] Carbon dioxide concentration, in percent (%), monitored by NDIR carbon dioxide sensor;

[0069] Illumination intensity, in lux, monitored by light-sensitive sensor;

[0070] Vibration, in acceleration (m / s²), monitored by acceleration sensor;

[0071] Sound, in decibels (dB), monitored by microphone sensor;

[0072] Color, in Lab values, monitored by color sensor reflectance spectrum;

[0073] Odor, in volatile organic compound concentration (ppm), monitored by electronic nose sensor array;

[0074] Humidity, in percent relative humidity (%RH), monitored by humidity sensor;

[0075] The data collection period is fixed at 8 hours, with sampling every 5 minutes, and a sensor time series data matrix of length 100 is generated for each batch.

[0076] The training data set is composed of historical normal batch and deterioration batch data, covering monitoring data under different storage conditions, and the data labeling is divided into three quality states by food quality inspection experts according to the physicochemical detection results of the sample (such as microbial over-standard, rancidity index): fresh (in line with food safety standards), slight deterioration (partially critical over-standard), and severe deterioration (multiple indicators over-standard).

[0077] During the labeling process, experts assign class labels to each sample based on the correspondence between sensor data trends and laboratory test reports, forming a labeled training data set for subsequent supervised learning of the model.

[0078] In the specific implementation, a machine learning model for food sample quality monitoring is constructed, and S2 is specifically as follows:

[0079] The food data standardization based on dynamic distribution alignment, the physical constraint-based adversarial enhancement based on food characteristics, the multi-scale residual spatio-temporal feature extraction network, the dynamic attention enhancement of physical constraint and environmental modulation, the food sample quality classification output and loss function calculation, and the machine learning model iterative training are sequentially performed.

[0080] In the embodiment, the food data standardization based on dynamic distribution alignment is specifically as follows:

[0081] Due to the distribution offset problem between batches of food monitoring data, the sensor numerical fluctuation under different storage conditions is significant, the conventional processing method adopts Z-score standardization, but the discrimination boundary between different quality states is easy to be blurred, resulting in the decline of classification performance. Therefore, the conditional mutual information of the fresh milk sensor time series data matrix and the global reference distribution is calculated, and a differentiable alignment matrix is dynamically constructed, so as to eliminate the distribution offset between batches while retaining the quality discrimination features. The specific steps are as follows:

[0082] 1) Constructing a dynamic alignment factor

[0083] The KL divergence between the data distribution of each sensor in the sensor set and the global reference distribution is calculated, and the Pearson correlation coefficient between the time series data of the sensor and the time series data of the global reference sensor is calculated. Then, the coupling results of the two are exponentially transformed and averaged to obtain the alignment factor of fresh milk for dynamically adjusting the alignment strength, and then the distribution offset degree between batches is quantified, which is expressed as:

[0084]

[0085] In the formula, The alignment factor of the food is a scalar, which is used to dynamically adjust the alignment strength, and the value range is 0 to 1. The smaller the value is, the more significant the distribution offset is, and the stronger the alignment is required.

[0086] Indicates a sensor set, S = 15;

[0087] Indicates the sensor index;

[0088] Indicates the data distribution of the s-th sensor, which is used to describe the probability characteristics of the sensor data and is learned from the historical sensor time series data. Specifically, the Gaussian kernel function is used to smooth the probability density estimation of the sensor data points;

[0089] Indicates the global s-th sensor reference distribution, which is a reference distribution obtained by statistical analysis of a large number of normal batch sensor data, representing the ideal state of the data distribution, and is used as the reference for distribution alignment;

[0090] denotes the KL divergence, term is used to measure the distribution difference between ;

[0091] denotes the Pearson correlation coefficient, term is used to quantify the degree of linear correlation between ;

[0092] denotes the sensor time series data matrix of the s-th sensor, with dimensions ;

[0093] is the number of time points, set to 100 by default, corresponding to a typical food monitoring period, for example, sampling every 5 minutes, with a total duration of about 8 hours;

[0094] denotes the sensor time series data of the s-th sensor in the global reference distribution, obtained by aggregating historical normal batch data and calculating the average value at each time point, with dimensions , as a reference for distribution alignment;

[0095] denotes the natural exponential function;

[0096] In this embodiment, the food refers to fresh milk.

[0097] 2) Differentiable alignment transformation

[0098] The combination of affine transformation matrix and rotation matrix is controlled by the alignment factor, and the original data is input into the multi-layer perception network for nonlinear transformation, while the global mean vector and global standard deviation vector are combined to perform linear transformation through the hyperbolic tangent activation function. The aligned food data is obtained by weighted summation after dynamic correction, so as to eliminate the distribution deviation between batches while maintaining clear discrimination boundary, represented as:

[0099]

[0100] In the formula, denotes the aligned food data, with dimensions , maintaining clear discrimination boundary while eliminating distribution deviation;

[0101] denotes the original food data, with dimensions , 15 represents the number of monitoring sensors;

[0102] denotes the transpose operation;

[0103] is the transpose of , specifically transposing the last two dimensions of , i.e., converting from dimensions to so that it can be matrix multiplied with ;

[0104] is the number of training samples;

[0105] represents the hyperbolic tangent activation function;

[0106] is an affine transformation matrix of dimension , trainable parameters, used to perform a linear transformation on the original data;

[0107] is a two-layer perceptron network with output dimension , used to introduce the ability of non-linear transformation;

[0108] represents a rotation matrix of dimension , which is a trainable parameter used to maintain the consistency of the output dimension;

[0109] represents the global mean vector of dimension , i.e., the average of all historical normal batch data of each sensor, forming a 15-dimensional vector as the reference offset for alignment;

[0110] represents element-wise multiplication, i.e., Hadamard product;

[0111] is the global standard deviation vector of dimension , which is used to scale the data of each sensor to maintain the consistency of the data distribution shape.

[0112] In the specific implementation, the adversarial enhancement operation based on the physical constraints of food characteristics is as follows:

[0113] Since there is a nonlinear sensor coupling in the food quality deterioration process, such as the phenomenon of pH value decrease and conductivity change caused by lactic acid bacteria proliferation, the conventional processing method generates samples using a generative adversarial network, but it is easy to violate the biochemical constraints, resulting in generated data that does not comply with the actual physical laws. Therefore, the present application constrains the generator to satisfy the differential relationship defined by the field knowledge by calculating the food characteristic driven adversarial regularization term, so as to ensure that the generated samples comply with the physical constraints, and the specific steps are as follows:

[0114] 1) Constructing food sensor coupling equations

[0115] Define the coupling relationship between multiple sensors in the key sensor state vector, form the physical constraint function describing the coupling law of the sensors in the food deterioration process, expressed as:

[0116]

[0117] In the formula, The physical constraint function is represented by the output dimension , used to define the differential relationship constraint between sensors;

[0118] The key sensor state vector is defined as , with a dimension of ;

[0119] The rate of change of pH with time is calculated by time series difference;

[0120] The rate of change of lactic acid bacteria concentration with time is calculated by time series difference;

[0121] The food-related constant is represented by , with a typical value of 0.15-0.25 and a default setting of 0.2;

[0122] The rate of change of conductivity with time is calculated by time series difference;

[0123] The rate of change of temperature with time is calculated by time series difference;

[0124] The food-related constant is represented by , with a typical value of 0.1-0.3 and a default setting of 0.15;

[0125] The conductivity change threshold is represented by , with a default setting of 0.01;

[0126] The rate of change of viscosity with time is calculated by time series difference;

[0127] The viscosity and lactic acid bacteria coupling constant is represented by , with a typical value of 0.05-0.15 and a default setting of 0.1;

[0128] The viscosity change threshold is represented by , with a default setting of 0.005;

[0129] represents the rate of change of the redox potential over time, calculated by time-differencing;

[0130] represents the coupling constant of the redox potential to the lactic acid bacteria, with a typical value of 0.1-0.3 and a default setting of 0.2;

[0131] represents the change threshold of the redox potential, with a default setting of 0.02;

[0132] represents the rate of change of the carbon dioxide concentration over time, calculated by time-differencing;

[0133] represents the coupling constant of the carbon dioxide concentration to the lactic acid bacteria, with a typical value of 0.2-0.4 and a default setting of 0.3;

[0134] represents the change threshold of the carbon dioxide concentration, with a default setting of 0.01;

[0135] represents the rate of change of the fat content over time, calculated by time-differencing;

[0136] represents the coupling constant of the fat content to the redox potential, with a typical value of 0.05-0.15 and a default setting of 0.1;

[0137] represents the change threshold of the fat content, with a default setting of 0.005;

[0138] represents the rate of change of the protein content over time, calculated by time-differencing;

[0139] represents the coupling constant of the protein content to the pH, with a typical value of 0.1-0.3 and a default setting of 0.2;

[0140] represents the change threshold of the protein content, with a default setting of 0.01;

[0141] represents the rate of change of the color value over time, calculated by time-differencing;

[0142] represents the coupling constant of the color to the lactic acid bacteria, with a typical value of 0.05-0.15 and a default setting of 0.1;

[0143] represents the change threshold of the color, with a default setting of 0.005;

[0144] denotes the max function.

[0145] 2) Physical regularization adversarial training

[0146] The discriminator output probability of real data and generated data is calculated by the expectation operator, and the Frobenius norm of the Jacobian matrix of the physical constraint function is combined as a regularization term, and a trade-off factor is used to control the importance of the regularization term, so as to force the generated samples to satisfy the physical constraint function when training the discriminator, denoted as:

[0147]

[0148] In the formula, denotes the discriminator loss function, which is used to train the discriminator to distinguish real / generated data while forcing the physical constraint;

[0149] denotes the expectation operator, which calculates the expected value of the corresponding item;

[0150] denotes the discriminator function, which specifically adopts a 5-layer convolutional neural network structure, and the input dimension is 64, and the output sample is the probability that the real data is true;

[0151] denotes the generator function, which specifically adopts a 7-layer deconvolutional neural network structure, and the input noise dimension is 100, and the output is the same dimension as ;

[0152] denotes the noise vector in the latent space, which is sampled from the standard normal distribution;

[0153] denotes the trade-off factor, which is used to control the importance of the physical regularization term, set to 0.3;

[0154] denotes the Jacobian matrix of the physical constraint function ;

[0155] denotes the Frobenius norm.

[0156] In specific implementation, the Jacobian matrix is calculated by automatic differentiation, that is, the partial derivative matrix of the physical constraint function with respect to the generated sample , where is taken from the corresponding sensor data in the output of the generator.

[0157] 3) Physical constraint enhanced data generation

[0158] The basic data is output by the generator, combined with the physical constraint function, and output by the physical constraint mapping network, and expanded to the sensor dimension by the tensor product operation using the physical constraint mask matrix, and then the correction strength is controlled by the physical constraint enhancement weight, so that the obtained enhanced data conforms to the sensor coupling relationship in the food deterioration process, which is expressed as:

[0159]

[0160] In the formula, Enhanced data, dimension is the generated data after physical constraint enhancement, which is obtained by superimposing the physical regularization correction on the basic output of the generator, to ensure that the data conforms to the sensor coupling relationship in the food deterioration process;

[0161] Physical constraint enhancement weight, preferably set to 0.3, used to control the strength of the physical constraint correction;

[0162] Physical constraint mapping network, the specific structure is two fully connected layers, the input dimension is , the hidden layer dimension is 32, and the output dimension is 15, using ReLU activation function, used to map the output of the physical constraint function to the sensor dimension, realizing the conversion from constraint to data;

[0163] Physical constraint feature dimension, default set to 8, corresponding to the output dimension of the physical constraint function;

[0164] Tensor product operation;

[0165] Physical constraint mask matrix, dimension is a predefined fixed matrix, defined based on the correlation between the sensor and the physical constraint;

[0166] Physical related sensor subset in the generated data, specifically including pH value, lactic acid bacteria concentration, conductivity, temperature, a total of 4 sensors, dimension N x T x 4.

[0167] In the specific implementation process, the physical constraint mask matrix is defined based on the correlation between the sensor and the physical constraint, for example, for the pH constraint, only the weight corresponding to the pH sensor is set to 1, and the other sensors are 0, realizing the targeted correction of the specific sensor, and in the tensor product operation, is used for linear transformation of the output of , to ensure that the correction term only affects the related sensors, in addition, the tensor product operation The matrix multiplication along the last two dimensions, i.e., for each sample, is represented as Term with physical constraint mask matrix The matrix multiplication of the term with the physical constraint mask matrix, with the output dimension of .

[0168] In the detailed implementation, the multi-scale residual spatio-temporal feature extraction network operates as follows:

[0169] The food deterioration process simultaneously exists local mutation and global gradual change, such as lactic acid bacteria explosive proliferation and fat oxidation phenomenon, in order to give full play to multi-scale features and fully extract features, the present application designs a double-path residual architecture, uses a hollow convolution kernel and an expanded long short-term memory network to capture cross-time scale feature interaction, thereby extracting multi-scale features, and the specific steps are as follows:

[0170] 1) The local mutation path adopts three-branch convolution with increasing hollow rate

[0171] The enhanced data and the aligned data are spliced along the feature dimension and input into the residual block, the multi-scale features output by each branch are extracted in parallel by setting different hollow rate convolution kernels, the local mutation mode in the food deterioration process is captured by using the feature of expanding the receptive field of the hollow convolution, and is represented as:

[0172]

[0173] In the formula, The output feature of the i-th branch of the local mutation path is represented as , and the dimension is , which is used for capturing local mutation features of different scales;

[0174] The batch size is represented as

[0175] The feature splicing operation is represented as

[0176] The branch index is represented as

[0177] The residual block function is represented as

[0178] The convolution kernel size is represented as , and the default value is 3, which defines the receptive field size of the convolution operation;

[0179] The hollow rate is represented as , and the value set is , which is used to control the inflation degree of the convolution kernel to capture multi-scale features.

[0180] In practice, the residual block consists of two convolutional layers, each followed by batch normalization and a ReLU activation function. The first convolutional layer uses a dilatation rate of [missing value]. The dilated convolution maps the number of input channels from 30 to 32. The second convolutional layer maintains the number of channels at 32. Furthermore, the skip connections add the input and output through a 1×1 convolution and are then activated by ReLU. Therefore, the residual block structure allows the network to learn the residual function, alleviates gradient vanishing, and facilitates deep network training.

[0181] 2) Global gradual change pathways utilize expanded long short-term memory networks.

[0182] The aligned data after gating weight matrix transformation and the weighted result of the hyperbolic tangent activation are input into the extended long short-term memory network. By setting the expansion step size, the memory dependency range in the time dimension is expanded. The output features of the global gradual pathway are used to capture the long-term gradual trend in the food deterioration process, as shown below:

[0183]

[0184] In the formula, The output features of the global gradient path are represented by the dimension . This is used to capture long-term dependencies and global gradient features;

[0185] This represents the gate weight matrix, with a dimension of 15×15, which performs a linear transformation on the augmented data.

[0186] This represents the data augmentation weights and calculates the degree of violation of physical constraints. Set to 0.2;

[0187] This represents an extended long short-term memory network function;

[0188] This indicates the expansion step size, with a default value of 5, used to skip some time steps to expand the receptive field.

[0189] In practice, the extended long short-term memory network introduces an expanded step size into the standard long short-term memory network. Each Long Short-Term Memory (LSTM) network unit contains an input gate, a forget gate, an output gate, and a cell state. However, in the temporal dimension, the update of the hidden state depends on the previous state. The hidden state at each time step, i.e. ,in, For the first The hidden state of the time step, with dimension . This indicates that the Long Short-Term Memory network is in the first... The memory state of a time step. For the first The input for the time step has the following dimensions. The corresponding sensor data is in the first Observations at the time step, For the first The hidden state of the time step. This is a standard Long Short-Term Memory (LSTM) network unit function that implements input gate, forget gate, output gate, and cell state updates. This is the time step index, and its value range is... arrive In this implementation, the extended long short-term memory network has 2 layers, 64 hidden units, and an expansion step size of [missing information]. =5, thereby expanding the receptive field to capture long-term trends.

[0190] 3) Feature fusion and dimensionality reduction

[0191] After concatenating local mutation features and global gradual change features along the feature dimension, the resulting fusion features are weighted using the attention weight vector activated by Sigmoid and the fusion weight matrix activated by hyperbolic tangent, respectively. This weighted transformation is then combined with the physical attention features to obtain the fused features. This achieves dynamic fusion and information compression of multi-scale features, as expressed below:

[0192]

[0193] In the formula, Represents the fusion feature, with dimension 1. It is a fusion output of local mutation features and global gradual change features. Through attention gating mechanism, it dynamically weights multi-scale features, preserves spatiotemporal details while emphasizing important time points, and characterizes the comprehensive multi-scale pattern in the food deterioration process.

[0194] This represents the Sigmoid activation function;

[0195] Representing physical attention features, with dimensions N×T×32, specifically calculated through a physical attention mechanism. The input is a subset of physical-related sensors, including four attributes: pH value, lactic acid bacteria, conductivity, and temperature. These attributes are mapped to 32-dimensional attention weights through a pre-defined fully connected layer, multiplied by the original sensor features, and then reduced in dimensionality through another pre-defined fully connected layer to output the dimensionality. ;

[0196] This represents the attention weight vector, used to calculate the attention score. It consists of trainable parameters with dimensions of . ;

[0197] express and concatenation operation along the feature dimension;

[0198] denotes the fusion weight matrix, used for feature transformation, is a trainable parameter, and has a dimension of .

[0199] In the specific implementation, the dynamic attention enhancement operation of the physical constraint and the environment modulation is as follows:

[0200] The food deterioration process involves complex interactions of multiple sensor data and is affected by temperature and humidity environmental factors. To avoid neglecting the dynamic modulation of physical constraints and external environmental factors, the attention weight distribution is unreasonable, and the key deterioration events cannot be accurately captured. The present application enhances the focusing ability on the key spatio-temporal features in the food deterioration process by adopting a dynamic attention mechanism driven by physical constraints and environmental factors, combining historical deterioration patterns and multi-scale features. The specific steps are as follows:

[0201] 1) Physical constraint time attention

[0202] By calculating the similarity between the average physical constraint feature and the historical deterioration pattern, and combining the environmental factors for modulation, the attention weight of each time point is dynamically generated, so as to highlight the key time points in the deterioration process, which is represented as:

[0203]

[0204] In the formula, denotes the time attention weight matrix, which has a dimension of , used to quantify the importance of each time point, and the value range is 0 to 1, and the larger the value, the more critical the time point in the deterioration process;

[0205] denotes the Softmax function;

[0206] denotes the dimension of the key vector, which is set to 32 by default, used to scale the dot product attention;

[0207] denotes the query weight matrix, which is a trainable parameter, and has a dimension of , used to map the physical constraint feature to the query space;

[0208] is the transpose of ;

[0209] denotes the transpose of ;

[0210] denotes the dimension a full 1 row vector, items are obtained through a broadcast mechanism matrix, used to modulate attention scores;

[0211] represents the average physical constraint feature, obtained by averaging physical constraint features in the time dimension, with a dimension of , used to summarize the physical state of the entire sequence;

[0212] represents the physical constraint feature, obtained by the physical constraint function applied to the alignment data , with a dimension of , providing semantic information at the physical level, used to identify key time points that violate physical laws, and enhance sensitivity to degradation events;

[0213] represents the key weight matrix, which is a trainable parameter, with a dimension of , used to map historical degradation patterns to the key space;

[0214] represents the historical feature dimension, which is set to 16 by default, representing the abstract representation of historical patterns;

[0215] represents the historical degradation pattern matrix, which is a typical degradation sequence extracted from historical normal batch data, with a dimension of ;

[0216] represents the environmental modulation factor, used to modulate the influence of temperature and humidity environmental factors on attention weights, quantifying the accelerating or inhibiting effect of environmental conditions on the degradation process, with a dimension of , calculated as ;

[0217] is the temperature weight coefficient, which is a trainable scalar parameter, with a default initial value of 0.5, used to adjust the contribution of temperature to the environmental modulation factor;

[0218] is the humidity weight coefficient, which is a trainable scalar parameter, with a default initial value of 0.5, used to adjust the contribution of humidity to the environmental modulation factor;

[0219] represents the environmental factor dimension, which is set to 2 by default, corresponding to temperature and humidity sensors.

[0220] In the implementation process, the historical degradation pattern matrix is extracted from historical data through principal component analysis The principal components are obtained as follows: collect all sensor time series data from historical normal batches, align to the same time length For each time point, calculate the mean of sensor data of all historical samples to form a reference sequence, then perform principal component analysis on the reference sequence to extract the first principal components to form the historical degradation mode matrix Each row represents a principal component sequence.

[0221] 2) Physical guidance feature channel attention

[0222] The attention weight of the feature channel is calculated by averaging the fusion feature and the linear transformation of the average physical constraint output combined with the Sigmoid activation function, so as to highlight the key feature channels related to the food degradation process (such as the feature channels corresponding to lactic acid bacteria and pH value), denoted as:

[0223]

[0224] In the formula, represents the feature channel attention weight matrix, with a dimension of , which is used to emphasize important feature channels, and the value range is 0 to 1, and the larger the value, the more important the feature channel in classification;

[0225] represents the feature weight matrix, which is a trainable parameter, with a dimension of , which is used for linear transformation of the fusion feature;

[0226] is the transpose of ;

[0227] represents the average fusion feature, which is obtained by averaging the fusion feature in the time dimension, with a dimension of , representing the global feature representation of the entire sequence;

[0228] represents the physical constraint weight matrix, which is a trainable parameter, with a dimension of , which is used to map the physical constraint output to the feature channel space;

[0229] is the transpose of ;

[0230] represents the average physical constraint output, which is obtained by averaging the output of the physical constraint function in the time dimension, with a dimension of , which is used to provide global information of the physical constraint.

[0231] It should be noted that the characteristic channel attention mechanism pays attention to the characteristic channels related to pH value, lactic acid bacteria concentration, conductivity and temperature. The pH value and lactic acid bacteria concentration reflect the fermentation degree, the conductivity is related to the ion concentration and is affected by the metabolic products, and the temperature drives the reaction rate and affects the microbial activity, so these characteristic channels are directly related to the food deterioration process.

[0232] 3) Attention feature enhancement

[0233] The time attention weight and the feature channel attention weight are combined through the outer product operation to generate a spatio-temporal attention matrix, and an element-wise multiplication is performed with the fusion feature, and a projection of the physical attention feature is introduced as a residual term, so as to enhance the feature representation and retain the physical constraint information, which is represented as:

[0234]

[0235] In the formula, represents the attention weighted feature, and the dimension is , which combines the time attention and the feature channel attention to dynamically weight the key spatio-temporal region;

[0236] represents the fusion feature, and the dimension is , which is output from the multi-scale residual spatio-temporal feature extraction network;

[0237] represents the outer product operation;

[0238] represents the projection weight matrix, which is a trainable parameter, and the dimension is , which is used to project the physical attention feature to the same dimension as the fusion feature.

[0239] It should be noted that, The term combines the time attention weight matrix and the feature channel attention weight matrix into a spatio-temporal attention matrix, and the dimension is , which is used to modulate the time dimension and the feature dimension at the same time, and the outer product operation is realized through the broadcast mechanism, that is, is expanded to , is expanded to , and then the feature dimension obtained by multiplication is , and the projection weight matrix is initialized orthogonally to avoid gradient disappearance, so that the enhancement mechanism ensures that the attention weight considers the time dynamics, the feature importance and the physical constraint at the same time, thereby improving the representation ability of the food deterioration mode.

[0240] In the detailed implementation, the food sample quality classification output and the loss function calculation operation are as follows:

[0241] Food quality classification needs to consider multi-scale spatio-temporal features, physical constraints and environmental factors. In order to avoid the difficulty in balancing classification accuracy and physical consistency when using cross-entropy loss function, and the problem of ignoring environmental modulation and historical patterns, the present application designs a multi-modal classification output, a physical constraint consistency loss and a dynamically weighted multi-task loss function, combines environmental modulation factors and historical deterioration patterns, ensures that the classification results conform to the physical law of food deterioration while optimizing the generalization ability of the model, and the specific steps are as follows:

[0242] 1) Multi-modal quality classification output

[0243] The time aggregation vector of the attention weighted feature and the gating product of the environmental factor modulation vector are calculated, and the quality classification logic value is generated by combining the historical deterioration pattern matching score. Then, the quality category probability is obtained by using the Softmax function, so as to fuse spatio-temporal features, environmental factors and historical knowledge for comprehensive classification, which is expressed as:

[0244]

[0245] In the formula, represents the quality category probability vector, and the value range is 0 to 1, which represents the probability of each sample belonging to each quality category;

[0246] is the number of quality categories, and the default number of quality categories is corresponding to fresh, slightly deteriorated and severely deteriorated;

[0247] represents the classification weight matrix, which is a trainable parameter, and the dimension is , which is used to map the modulated feature to the category space;

[0248] represents the gating weight matrix, which is a trainable parameter, and the dimension is , which is used to map the average environmental factor to the feature modulation vector;

[0249] is the transpose of ;

[0250] represents the average environmental factor matrix, and the dimension is , which is obtained by averaging the environmental factor tensor in the time dimension;

[0251] is an environmental factor tensor, which is an environmental factor matrix directly extracted from sensor data, with a dimension of , containing temperature and humidity sensor data, the environmental factor matrix at the th time point is a slice of the environmental factor tensor corresponding to the tth time point in the time dimension;

[0252] represents the environmental factor matrix at the th time point, with a dimension of , directly extracted from sensor data, including temperature and humidity;

[0253] represents a classification bias vector, with a dimension of , which is a trainable parameter;

[0254] represents a historical matching weight coefficient, which is a trainable scalar parameter, with a default initial value of 0.1, used to control the importance of the historical matching score;

[0255] represents a similarity weight matrix, which is a trainable parameter, with a dimension of , used to calculate the association between features and historical patterns;

[0256] represents a historical output weight matrix, which is a trainable parameter, with a dimension of , used to map historical attention weights to the category space.

[0257] It should be noted that is obtained by averaging the attention weighted features over time, specifically by averaging the attention weighted features in the time dimension, achieving aggregation of global spatio-temporal information, reducing temporal fluctuation noise, preserving overall sequence features, and facilitating classifier processing; is used to quantify the similarity between the current feature and the historical degradation pattern, by calculating the similarity between the current feature and the historical degradation pattern, and using the Softmax function to generate time attention weights, thereby quantifying the matching degree between the current sample and the historical degradation pattern, and enhancing the classification basis.

[0258] In the specific implementation process, if the temperature sensor reading is , and the humidity sensor reading is , then for a single sample, the environmental factor matrix at the th time point .

[0259] 2) Physical constraint consistency loss

[0260] ​By calculating the cross-entropy between the quality category probability and the degree of physical constraint violation, and combining the environmental modulation factor and the physical constraint prototype, a physical constraint consistency loss term is constructed to ensure that the classification results conform to the physical laws of food deterioration, expressed as:

[0261]

[0262] In the formula, This represents the physical constraint consistency loss, which is a scalar used to penalize cases where the classification results are inconsistent with the physical constraints.

[0263] Indicates the first The sample belongs to the first The probability of each category is a quality category probability vector. The Line number Column elements;

[0264] This is a quality category index, with a value range of [value range missing]. arrive ;

[0265] To distinguish from The quality category index, with a value range of arrive ;

[0266] This represents a temperature parameter used to control the smoothness of the distribution. Set to 1.0;

[0267] Represents the square of the L2 norm;

[0268] Indicates the first The physical constraint output vector for each sample has a dimension of . By applying physical constraint functions Applied to the Sensor data for each sample was obtained;

[0269] Indicates the first The physical constraint prototype vectors for each quality category, with dimension [missing information]. Learned from training data, for example, the fresh category corresponding to Characterizing that the physical constraints are satisfied, the two degradation categories correspond to and Characterizing violations of physical constraints;

[0270] Indicates the first Physical constraint prototype vectors for each quality category;

[0271] Represents the environmental modulation weighting coefficient. Set to 0.1 to adjust the impact of environmental factors on physical constraint loss;

[0272] Indicates the first The environmental modulation factor for each sample is a scalar, calculated as follows: ;

[0273] Indicates the first The average temperature value of a sample is obtained by averaging the temperature sensor data of that sample over time, and is a scalar.

[0274] Indicates the first The average humidity value of a sample is obtained by averaging the humidity sensor data of that sample over time, and is a scalar.

[0275] Indicates the sample index;

[0276] It is a logarithmic function, with the default base being the natural constant.

[0277] In practical implementation, the physical constraint prototype vector Initialized using a clustering algorithm and updated during training, it captures typical physical states of different quality categories.

[0278] It should be noted that the environmental modulation factor The accelerated effect of environmental conditions on the degradation process is quantified. When the environment is harsh, such as high temperature and high humidity, the weight of physical constraint loss increases.

[0279] 3) Dynamically weighted multi-task loss function

[0280] By dynamically adjusting the weights of classification loss and physical constraint loss using environmental modulation factors and historical matching scores, and combining this with a weight decay regularization term, a multi-task loss function is constructed to optimize model parameters and ensure consistency between classification performance and physical constraints. This is expressed as:

[0281]

[0282] In the formula, The total loss function is a scalar used to comprehensively optimize classification accuracy, physical consistency, and model complexity.

[0283] The average environmental modulation factor is a scalar, calculated as follows: , for dynamically adjusting the loss weight, the value range is 0 to 1, the larger the value, the worse the environmental condition, and the more emphasis on the physical constraint loss;

[0284] represents the classification cross-entropy loss, a scalar, calculated as ;

[0285] represents the true label of the first sample, the first class value in one-hot encoding format;

[0286] represents the weight decay coefficient, set to 0.001, used to control the model complexity and prevent overfitting;

[0287] represents the set of all trainable parameters of the model.

[0288] In specific implementation, the loss weight dynamically adapts to the environmental condition. When the average environmental modulation factor is high, it indicates that environmental factors may accelerate degradation, so the weight of the physical constraint loss is strengthened to ensure that the generated sample meets the actual physical law, and when the average environmental modulation factor is low, more attention is paid to classification accuracy.

[0289] In the specific implementation, the machine learning model iterative training operation is as follows:

[0290] The model training adopts the mini-batch gradient descent method, and each iteration includes two stages of forward propagation and back propagation: in the forward propagation stage, the input batch data sequentially performs dynamic distribution alignment, physical constraint adversarial enhancement, multi-scale feature extraction, dynamic attention enhancement and classification output operation to generate quality category probability vector;

[0291] In the back propagation stage, the gradient is calculated based on the total loss function , and the model parameters are updated through the adaptive optimizer.

[0292] The training stopping condition is that the validation set loss does not decrease for 10 consecutive iteration periods, or the total training period reaches 500 times. After training is completed, the model parameters with the optimal validation set performance are saved for subsequent monitoring tasks.

[0293] In the specific implementation, S3 is as follows:

[0294] In the monitoring stage, the trained model is deployed to the sample monitoring terminal.

[0295] The real-time collected sensor data is first input into a dynamic distribution alignment module to eliminate batch-to-batch distribution offset and output standardized data, then through a physically constrained adversarial enhancement module to generate enhanced data conforming to biochemical laws, and then through a multi-scale residual spatio-temporal network to extract local mutation and global gradual change features, then use a dynamic attention mechanism with physical constraints and environmental modulation to focus on key spatio-temporal features, and finally output quality category probability by a multi-modal classifier.

[0296] The system determines the state of the sample according to the maximum probability value, triggers a warning signal when a deterioration category is detected, and records the deterioration time point and related sensor abnormal indicators (such as sudden increase in lactic acid bacteria concentration and decrease in pH value), and generates a monitoring report for quality inspection personnel to review.

[0297] Example 2

[0298] As shown in Figures 2 to 4 , based on the monitoring method of the quality of the fresh milk sample in Example 1, the change trend of the sensor parameters of the fresh milk under different quality states is further analyzed, and the correlation between the sensor data and the quality state is analyzed. Three sensor parameters closely related to the deterioration of fresh milk are selected as examples, including pH value, lactic acid bacteria concentration and temperature. Figures 2 to 4 In each parameter, the change trend is visualized by the change curve under the fresh, slightly deteriorated and severely deteriorated states. The abscissa is the storage time, in hours; the ordinate is the pH value (dimensionless), the lactic acid bacteria concentration (colony forming units per milliliter) and the temperature (degrees Celsius), respectively. As shown in Figure 2 , from the pH value change trend, it can be seen that the pH value of the fresh state remains relatively stable, the slightly deteriorated state shows a slow downward trend, and the severely deteriorated state shows a significant decrease, which is consistent with the biochemical process of lactic acid bacteria fermentation to produce acidic substances. As shown in Figure 3 , in terms of lactic acid bacteria concentration, the fresh state and the slightly deteriorated state grow slowly, and the severely deteriorated state grows faster, reflecting the typical characteristics of microbial reproduction. As shown in Figure 4 , the temperature change also shows differences in different quality states, reflecting the physical and chemical processes such as metabolic heat production.

[0299] Example 3

[0300] As shown in Figure 5 , the recognition effect of different features on the key indicators of fresh milk quality monitoring is explored. By evaluating the relative importance of 15 sensor features in quality classification, the core sensors more relevant to the food deterioration process are verified. From the experimental results, it can be seen that the key biochemical indicator sensors have significantly higher importance scores, and the vibration sensor and the sound sensor have lower scores. The relatively low scores are consistent with the actual physical laws, because the influence of environmental factors on food quality is relatively indirect.

[0301] Example 4

[0302] As Figure 6 shown, the robustness of the comparative analysis model to noise is compared by comparing the performance retention ability of each method under different sensor noise levels through the broken line graph, and the stability of the technology in the real complex environment is evaluated. Based on the same five methods, the experiment simulates five levels of sensor noise levels from low to high, the horizontal coordinate represents the noise level, the larger the value represents the stronger the noise interference; the vertical coordinate represents the performance retention rate, the unit is the ratio value, which reflects the performance maintenance degree of the method under noise. Figure 6 The broken line shows that as the noise level increases, the performance retention rate of all methods decreases, but the decline of the present technology is the smallest, and it can still maintain a relatively high performance level in a high noise environment, while the performance of conventional methods such as long short-term memory network and standardized convolutional neural network decays significantly. The experimental results show that the physical constraint consistency loss and the dynamic weighted multi-task loss function of the present application adaptively adjust the model weight through the environment modulation factor, enhance the fault tolerance of the system to sensor data anomalies, and the multi-scale feature extraction network can retain effective discriminative information from noisy data.

[0303] Although the specific embodiments of the application have been described above with reference to the accompanying drawings, the description is not a limitation on the scope of protection of the application. Various modifications or variations made by those skilled in the art without creative labor on the basis of the technical solutions of the present application are still within the scope of protection of the present application.

Claims

1. A method for quality monitoring of a food sample based on machine learning, characterized by, The method comprises the following steps: S1, deploying a sensor array in a food sample environment to collect monitoring data of the food sample in real time, continuously monitoring the multidimensional physical and chemical properties of the sample, constructing a training set from historical normal batch and deteriorated batch data, and labeling the state of the detection data in the training set; The sensor array uses 15 food quality monitoring sensors, and the collected data includes temperature, pH value, conductivity, lactic acid bacteria concentration, fat content, protein content, viscosity, oxidation-reduction potential, carbon dioxide concentration, light intensity, vibration, sound, color, odor and humidity; S2, constructing a machine learning model for food sample quality monitoring, inputting the sample data in the training set into the model, sequentially passing through a dynamic distribution alignment module, a physical constraint adversarial enhancement module, and a multi-scale residual spatio-temporal network, using physical constraints and environmental modulation to enhance the dynamic attention mechanism, and finally outputting the quality category probability by a multi-modal classifier; then calculating the model loss, iteratively training the model, and obtaining the trained model; S2 is as follows: Constructing a machine learning model for food sample quality monitoring, inputting the time series data matrix composed of detection data in the training set into the model, first passing through a dynamic distribution alignment module, calculating the conditional mutual information of the time series data matrix and the global reference distribution, dynamically constructing a differentiable alignment matrix, and generating aligned data; Then, the sample data is subjected to physical constraint through a physical constraint adversarial enhancement module, a food property driven adversarial regularization term is designed, the generator is constrained to satisfy the differential relationship defined by the domain knowledge, and enhanced data is generated; The aligned data and enhanced data are input into a multi-scale residual spatio-temporal network, a double-path residual architecture is used to capture cross-time scale feature interactions using a dilated convolution kernel and an expanded long short-term memory network, multi-scale features are extracted, and fusion features are output; The dynamic attention mechanism is enhanced using physical constraints and environmental modulation, the historical deterioration mode and the fusion features are combined to enhance the focusing ability on the key spatio-temporal features in the food deterioration process, and the attention weighted features are output, and then the multi-modal classifier outputs the quality category probability; then, a multi-task loss function is constructed combining the environmental modulation factor and the historical deterioration mode to calculate the model loss, and the model is iteratively trained using the small batch gradient descent method to obtain the trained model; The process of dynamic attention mechanism enhancement using physical constraints and environmental modulation is as follows: The similarity between the average physical constraint feature and the historical deterioration mode is calculated, and the environmental factor is modulated to dynamically generate the attention weight at each time point; The linear transformation of the average fusion feature and the average physical constraint output is calculated, combined with the Sigmoid activation function, and the attention weight of the feature channel is calculated; The time attention weight and the feature channel attention weight are combined through the outer product operation to generate a spatio-temporal attention matrix, and are multiplied with the fusion feature element by element, and the projection of the physical attention feature is introduced as a residual term to generate the attention weighted feature; The quality classification logic value is generated by calculating the gated product of the time aggregation vector of the attention weighted feature and the environmental factor modulation vector, and combining the historical deterioration mode matching score, and the quality category probability is obtained through the Softmax function; The function representation of the physical constraint is: , wherein, represents a physical constraint function; is a critical sensor state vector; represents a rate of change of pH over time; represents a rate of change of lactic acid bacteria concentration over time; represents a food-related constant; represents a rate of change of electrical conductivity over time; represents a rate of change of temperature over time; represents a food-related constant; represents an electrical conductivity change threshold; represents a rate of change of viscosity over time; represents a viscosity and lactic acid bacteria coupling constant; represents a viscosity change threshold; represents a rate of change of oxidation-reduction potential over time; represents an oxidation-reduction potential and lactic acid bacteria coupling constant; represents an oxidation-reduction potential change threshold; represents a rate of change of carbon dioxide concentration over time; represents a carbon dioxide concentration and lactic acid bacteria coupling constant; represents a carbon dioxide concentration change threshold; represents a rate of change of fat content over time; represents a fat content and oxidation-reduction potential coupling constant; represents a fat content change threshold; represents a rate of change of protein content over time; represents a protein content and pH coupling constant; represents a protein content change threshold; represents a rate of change of color value over time; represents a color and lactic acid bacteria coupling constant; represents a color change threshold; represents a maximum function; S3, deploy the trained model on the sample monitoring terminal, input the newly collected monitoring data, and predict the quality state of the food sample.

2. The machine learning based food sample retention quality monitoring method according to claim 1, characterized in that, S1 is as follows: Data acquisition is performed at a fixed cycle and a fixed frequency, and the collected monitoring data forms a time series data matrix, and each batch includes time series data of a fixed time length; The data in the training set covers monitoring data under different storage conditions; Data labeling is performed by a food quality inspection expert according to the physicochemical test results of the sample, and the sample is divided into three quality states: fresh, slightly deteriorated and severely deteriorated. The expert assigns a category label to each sample based on the correspondence between the sensor data trend and the laboratory test report, and forms a labeled training set.

3. The machine learning based food sample retention quality monitoring method according to claim 1, characterized in that, The operations in the dynamic distribution alignment module are as follows: The alignment factor of the food is obtained by calculating the KL divergence between the data distribution of each sensor in the sensor set and the global reference distribution, calculating the Pearson correlation coefficient between the time series data of the sensor and the global reference sensor time series data, and then performing exponential transformation on the coupling result of the two to obtain the alignment factor of the food for dynamically adjusting the alignment strength; The combination of the affine transformation matrix and the rotation matrix is controlled by the alignment factor, and the original data is input into a multi-layer perception network for nonlinear transformation. Meanwhile, the global mean vector and the global standard deviation vector are linearly transformed by the hyperbolic tangent activation function, and the aligned data after dynamic correction is obtained by weighted summation.

4. The machine learning based food sample retention quality monitoring method according to claim 1, characterized in that, The operations in the physical constraint adversarial enhancement module are as follows: The coupling relationship between multiple sensors in the key sensor state vector is defined to form a physical constraint function describing the coupling law of the sensors in the food deterioration process; The discriminator output probability of the real data and the generated data is calculated by the expectation operator, and the Frobenius norm of the Jacobian matrix of the physical constraint function is used as a regularization term. The importance of the regularization term is controlled by a weighting factor, so that the generated samples are forced to satisfy the physical constraint function when training the discriminator; The base data output by the generator is transformed by the physical constraint mapping network, and the physical constraint mask matrix is expanded to the sensor dimension through tensor product operation, and then the correction strength is controlled by the physical constraint enhancement weight, and the enhanced data conforming to the sensor coupling relationship in the food deterioration process is output.

5. The machine learning based food sample retention quality monitoring method according to claim 1, characterized in that, The operations in the multi-scale residual spatio-temporal network are as follows: The enhanced data and the aligned data are spliced along the feature dimension and input into the residual block, and the multi-scale features of each branch output are extracted in parallel by setting convolution kernels with different hole rates; The aligned data after transformation of the gating weight matrix and the enhanced data after hyperbolic tangent activation are input into the dilated long short-term memory network, and the memory dependence range of the time dimension is expanded by setting the dilated step, and the output features of the global gradual change path for capturing the long-term gradual change trend in the food deterioration process are obtained. After concatenating the local mutation feature and the global gradual change feature along the feature dimension, the weighted transformation is performed by the attention weight vector activated by Sigmoid and the fusion weight matrix activated by hyperbolic tangent, and then the fusion feature is obtained after combining the physical attention feature.

6. The machine learning based food sample retention quality monitoring method according to claim 1, wherein, The calculation process of the loss function is as follows: The cross entropy between the quality category probability and the degree of violation of physical constraints is calculated, and the environmental modulation factor and the physical constraint prototype are combined to construct the physical constraint consistency loss term; The weights of the classification loss and the physical constraint loss are dynamically adjusted by the environmental modulation factor and the historical matching score, and the weight decay regularization term is combined to construct the multi-task loss function.

7. The machine learning based food sample retention quality monitoring method according to claim 1, wherein, The iterative training process of the model is as follows: The model training adopts the mini-batch gradient descent method, and each iteration includes two stages of forward propagation and back propagation; In the forward propagation stage, the input batch data sequentially performs the operations of dynamic distribution alignment, physical constraint counter-enhancement, multi-scale feature extraction, dynamic attention enhancement and classification output to generate the quality category probability vector; In the back propagation stage, the gradient is calculated based on the total loss of the model, and the model parameters are updated by the adaptive optimizer; And set the training stop condition, when the condition is met, the training of the model is completed.

8. The machine learning based food sample retention quality monitoring method according to claim 1, characterized in that, S3 is as follows: For quality monitoring of food samples, the trained model is deployed to the sample monitoring terminal in the monitoring stage, the monitoring data of the food samples recorded by the sensors are collected in real time, and input into the trained model to predict the quality state of the food samples, and trigger the corresponding warning signal according to the prediction result, record the deterioration time point and the associated sensor abnormal index, and generate a monitoring report for the quality inspector to review.

Citation Information

Patent Citations

  • Food quality detection method and device based on machine learning

    CN117831026A

  • Three-dimensional point-cloud semantic segmentation method based on multi-level boundary enhancement for unstructured environment

    WO2024230038A1