Lightweight freshness time series prediction method for mobile terminal real-time inference

CN123016161APending Publication Date: 2026-10-30ZHEJIANG FORESTRY UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

[0005]综上所述,Li等(2025b)公开的BiLSTM牛肉货架期预测方案虽然精度较高,但存在以下核心缺陷:(1)双向结构依赖未来数据,在线推理存在未来信息泄露;(2)参数规模约8.5万,无法在中端移动终端上实现实时推理;(3)无离线部署方案,依赖云端计算,无法适用于冷链运输等网络不可达场景

Benefits of technology

(1)将知识蒸馏技术引入食品品质时序预测领域,实现了BiLSTM向单向LSTM的结构性蒸馏。学生模型在独立测试集上的滚动预测R2≥0.97,RMSE≤0.17,显著优于同参数规模从头训练的单向LSTM模型(R2提升约0.05,RMSE降低30%以上),且完全消除了在线推理的未来信息泄露问题。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123016161A_ABST
    Figure CN123016161A_ABST
Patent Text Reader

Abstract

The application discloses a kind of light meat freshness time series prediction methods for mobile terminal real-time inference, it is related to deep learning model compression and mobile terminal deployment technical field, including: training high-performance BiLSTM teacher model;Soft label is generated using temperature parameter;Lightweight unidirectional LSTM student model is constructed, and training is carried out through the total loss function of multilevel knowledge distillation;The student model after distillation is converted into mobile terminal inference format and deployed to terminal offline operation;The light meat freshness time series prediction method for mobile terminal real-time inference provided in the application realizes the structural distillation of BiLSTM to unidirectional LSTM for the first time, the trend consistency loss is effectively solved the trend lag problem in time series prediction, the parameter scale of student model is greatly reduced compared with teacher model, single inference time is short, and real-time offline prediction of meat freshness can be realized in unreachable network environment.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of deep learning model compression and mobile deployment technology, and in particular to a lightweight time-series prediction method for meat freshness for real-time inference on mobile terminals. Background Technology

[0002] Deep learning-based time-series prediction models for food quality have achieved excellent performance in offline environments. Bidirectional Long Short-Term Memory (BiLSTM) networks, due to their ability to simultaneously capture both forward and backward information of a sequence, have shown optimal performance in offline full-sequence fitting scenarios—Kim et al. (2024) used BiLSTM to achieve high-precision fitting of the post-harvest aging process of fruits and vegetables; Li et al. (2025b) used BiLSTM to obtain a goodness of fit R0 in multi-step prediction of beef shelf life. 2 This solution is the closest existing technology to the present invention.

[0003] However, BiLSTM faces fundamental obstacles when performing online inference in the cold chain: First, the bidirectional structure requires accessing data after the current time step to perform backward hidden state calculations, which contradicts the constraint of "only allowing the use of historical observation data" in online scenarios. Direct deployment will lead to future information leakage, and even if only the forward layer is used, there are still problems such as incomplete model structure migration and parameter redundancy. Second, the parameter scale of BiLSTM is about twice that of a unidirectional Long Short-Term Memory (LSTM) network with the same configuration, which significantly increases inference time and memory consumption, making it difficult to run smoothly on mobile terminals where computing resources, storage space, and power consumption are severely limited. Third, existing solutions mostly adopt an "edge-end acquisition-cloud inference" architecture, which relies on network connectivity and cannot achieve offline real-time prediction in scenarios where the network is unavailable, such as during cold chain transportation.

[0004] Existing lightweight model techniques mainly include knowledge distillation, model pruning, and weight quantization. Knowledge distillation has shown significant effectiveness in computer vision tasks such as image classification and object detection, conveying "hidden knowledge" to student models through soft labels generated by the teacher model. However, for time series prediction tasks, relying solely on standard soft label distillation has obvious limitations: soft labels mainly convey similarity information between categories and are difficult to effectively convey dynamic time series features, especially the sensitivity to key trend changes such as the inflection point of an S-shaped growth curve, causing the student model's prediction trend to often lag behind the true value. Currently, there is no publicly available technical solution for applying knowledge distillation to food quality time series prediction models, especially for BiLSTM to unidirectional LSTM structural distillation and achieving offline deployment on mobile devices.

[0005] In summary, although the BiLSTM beef shelf-life prediction scheme disclosed by Li et al. (2025b) has high accuracy, it has the following core defects: (1) the bidirectional structure depends on future data, and online inference may lead to the leakage of future information; (2) the parameter scale is about 85,000, which cannot be implemented in real-time inference on mid-range mobile terminals; (3) there is no offline deployment scheme, and it relies on cloud computing, which cannot be applied to network-inaccessible scenarios such as cold chain transportation. Summary of the Invention

[0006] The purpose of this invention is to provide a lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, thereby solving the aforementioned problems in the prior art.

[0007] To achieve the above objectives, this invention provides a lightweight time-series prediction method for meat freshness based on real-time inference on mobile terminals, comprising the following steps: S1. Using the standardized RGB time-series spectral feature matrix of multiple meat samples during the complete storage period as input, and the true standardized spoilage index (SSI) of the corresponding time node as output label, a double-layer stacked BiLSTM is trained to generate a teacher model; SSI is the standardized spoilage index, and BiLSTM is a bidirectional long short-term memory network. S2. Input the standardized RGB time-series spectral feature matrix into the teacher model, obtain the SSI prediction value output by the teacher model at each time step, and use the temperature parameter... Gaussian kernel smoothing is applied to the temporal distribution of SSI predictions to generate soft-label sequences. S3. Construct a lightweight unidirectional LSTM as the student model and perform joint training and multi-level knowledge distillation training; LSTM is a Long Short-Term Memory network. S4. Deploy the student model to a mobile terminal, where the mobile terminal performs inference and generates prediction results offline.

[0008] Preferably, the specific process in S1 is as follows: S11. Collect time-series RGB image data and total volatile basic nitrogen (TVB-N) content data of meat products at corresponding time points during the complete storage period of multiple meat samples, and divide them into training set, validation set and independent test set according to the proportion; TVB-N is volatile basic nitrogen. S12. For the RGB image time-series data in the training set, calculate the mean of the three RGB channels, generate the standard deviation of the three RGB channels through Z-score standardization, and obtain the standardized RGB time-series spectral feature matrix; for the meat TVB-N content data in the training set, calculate the TVB-N mean, generate the TVB-N standard deviation through Z-score standardization, and obtain the true SSI based on the TVB-N mean and TVB-N standard deviation. S13. Using the standardized RGB time-series spectral feature matrix as input and the real SSI as output, train the double-layer stacked BiLSTM. After training, the teacher model is obtained. S14. After training, the teacher model's full sequence fit R on the independent test set is... 2 ≥0.99.

[0009] Preferably, in S2: temperature parameter The value ranges from 3 to 10. The higher the temperature, the smoother the distribution of soft tags and the richer the retained temporal evolution dark knowledge.

[0010] Preferably, the specific process in S3 is as follows: S31. Construct a lightweight unidirectional LSTM as the student model: The hidden layer dimension of the student model is 1 / 4 to 1 / 2 of the hidden layer dimension of the teacher model, and the parameter size of the student model does not exceed 1 / 4 of that of the teacher model. S32, Introduce a learnable linear mapping layer By jointly training with the student model, a linear mapping layer can be learned to store the one-way hidden states of the student model. Mapped to the bidirectional hidden state concatenated with the teacher model Same dimension, express The forward hidden state at any given moment express The backward hidden state at time step; at the same time, multi-level knowledge distillation training is performed on the lightweight unidirectional LSTM student model through the total loss function.

[0011] Preferred total loss function The expression is: ; In the formula, Represents the hard loss term; Indicates the soft loss term; This represents the hidden state alignment loss term; This represents the trend consistency loss term; This represents the hard loss weight, with a value ranging from 0.1 to 0.3. This represents the soft loss weight, with a value ranging from 0.3 to 0.5. This represents the weight of the hidden state alignment loss, with a value ranging from 0.2 to 0.3. This represents the trend consistency loss weight, with a value ranging from 0.1 to 0.2, satisfying... .

[0012] Preferably, the hard loss term is the mean squared error between the SSI predicted by the student model and the true SSI. The soft loss term is the Kullback-Leibler divergence between the SSI predictions output by the student model and the soft label sequence. The temperature parameter is kept consistent with step S2 during the calculation. The hidden state alignment loss term is the mean squared error between the unidirectional hidden state of the student model at the key time step, projected through the learnable linear mapping layer, and the concatenated bidirectional hidden state of the teacher model at the corresponding time step. The key time step is at least one of the terminal region of the predicted sequence or the region near the inflection point of the SSI change curve. The terminal region of the predicted sequence refers to the last 1 / 4 to 1 / 3 of the predicted sequence time steps, corresponding to the saturation stage of putrefaction evolution. The region near the inflection point of the SSI change curve refers to 1 to 3 time steps before and after the point when the second difference of SSI turns from positive to negative, corresponding to the inflection point stage when the putrefaction rate changes from increasing to decreasing. If there are multiple inflection points in the predicted sequence, 1 to 3 time steps before and after each inflection point are selected as key time steps.

[0013] The trend consistency loss term is used to penalize the number of steps in which the student model's predicted sequence and the teacher model's predicted sequence show inconsistent trends at adjacent time steps.

[0014] Preferably, the expression for the trend consistency loss term is: ; In the formula, This represents the common prediction step size of the student model and the teacher model; This is the index of the time step, with a value range of... ; This indicates an indicator function that takes the value 1 when the condition inside the parentheses is true, and 0 otherwise. This represents a sign function that returns 1 when the input value is greater than 0, -1 when it is less than 0, and 0 when it is equal to 0. If the return values ​​of the two sign functions are the same, they are considered to be of the same trend. and These represent the first output of the student model, respectively. The time step and the first SSI prediction values ​​at each time step; and These represent the outputs of the teacher model, respectively. The time step and the first SSI prediction values ​​at each time step; and These are the SSI prediction sequences output by the student model and the teacher model, respectively.

[0015] Preferably, in S4: the trained student model is converted into an edge-side inference format adapted to mobile terminals, and the RGB three-channel mean, RGB three-channel standard deviation, TVB-N mean, and TVB-N standard deviation are deployed to the mobile terminal, so that the mobile terminal can complete the inference in an offline state.

[0016] Preferably, the edge inference format is one or more of TensorFlow Lite, Core ML or ONNX Runtime Mobile formats; when converting to the edge inference format, the FP16 quantization strategy is used, and the model accuracy loss after quantization is less than 1%.

[0017] Therefore, the present invention employs the aforementioned lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, which has the following beneficial effects: (1) Knowledge distillation technology was introduced into the field of food quality time series prediction, realizing the structural distillation from BiLSTM to unidirectional LSTM. The student model's rolling prediction R on the independent test set... 2 ≥0.97, RMSE≤0.17, significantly outperforming a unidirectional LSTM model trained from scratch with the same parameter size (R 2 It improves performance by approximately 0.05 and reduces RMSE by over 30%, while completely eliminating the issue of future information leakage in online inference.

[0018] (2) A multi-level distillation strategy for time series prediction tasks is proposed. Based on standard soft distillation, hidden state alignment loss and trend consistency loss are introduced, which effectively solves the problem of trend lag in time series prediction caused by single soft label distillation. The student model has a similar ability to accurately capture the inflection point of the S-shaped growth curve as the teacher model. The maximum absolute error of the student model after distillation is only 58% of that of the model trained from scratch with the same parameters.

[0019] (3) A complete toolchain integration from model training, knowledge distillation, format conversion to edge inference has been achieved. The number of parameters in the student model is only 1 / 8 of that in the teacher model (reduced from about 85,000 parameters to about 10,000 parameters), and the time for a single inference is less than 150 milliseconds (on mainstream mid-range smartphone CPUs), meeting the real-time offline prediction needs in network-inaccessible environments such as cold chain transportation and retail sites.

[0020] (4) Provide hardware adaptation options. The student model size can be flexibly selected according to the computing power of different terminals, maximizing prediction accuracy while ensuring real-time performance, and improving the universality of the technical solution for heterogeneous terminals.

[0021] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0022] Figure 1 This is an overall flowchart of a lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals according to the present invention. Figure 2 This is a detailed flowchart of the multi-level knowledge distillation training method of the present invention; Figure 3 This is a flowchart illustrating the trend consistency loss calculation process of the present invention. Figure 4 This is a flowchart illustrating the mobile terminal offline inference system and its workflow of the present invention. Detailed Implementation

[0023] The following detailed description of embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.

[0024] Please see Figures 1-4 A lightweight time-series prediction method for meat freshness based on real-time inference on mobile terminals includes the following steps: S1. Using the standardized RGB time-series spectral feature matrix of multiple meat samples during the complete storage period as input and the real SSI of the corresponding time node as output label, train a double-layer stacked BiLSTM to generate a teacher model; SSI is the standardized spoilage index and BiLSTM is a bidirectional long short-term memory network. S11. Collect time-series RGB image data and corresponding TVB-N content data of meat products during the complete storage period of multiple meat samples, and divide them into training set, validation set and independent test set according to the proportion; TVB-N is volatile basic nitrogen; S12. For the RGB image time-series data in the training set, calculate the mean of the three RGB channels, generate the standard deviation of the three RGB channels through Z-score standardization, and obtain the standardized RGB time-series spectral feature matrix; for the meat TVB-N content data in the training set, calculate the TVB-N mean, generate the TVB-N standard deviation through Z-score standardization, and obtain the true SSI based on the TVB-N mean and TVB-N standard deviation. S13. Using the standardized RGB time-series spectral feature matrix as input and the true SSI as output, train a double-layer stacked BiLSTM. After training, a high-performance teacher model is obtained. The hidden layer dimension of the teacher model is 64-128, and each layer is followed by Dropout (ratio 0.2). The mean squared error (MSE) is used as the loss function, and the Adam optimizer (initial learning rate 1e) is used. -3 The early stop mechanism (patience=20) is used to perform training; S14. After training, the teacher model's full sequence fit R on the independent test set is... 2 ≥0.99.

[0025] S2. Input the standardized RGB time-series spectral feature matrix into the teacher model, obtain the SSI prediction value output by the teacher model at each time step, and use the temperature parameter... Gaussian kernel smoothing was applied to the temporal distribution of SSI predictions to generate soft-label sequences; temperature parameters The value range is generally 3 to 10. Higher temperatures result in smoother soft label distributions, providing richer temporal evolution features for student models. Gaussian kernel smoothing uses a Gaussian window centered on the current time step to perform a weighted average of the temporal predictions, with temperature parameters... The corresponding window width and standard deviation of the Gaussian kernel, The larger the value, the smoother the texture, and the richer the temporal contextual knowledge contained in the soft tag.

[0026] S3. Construct a lightweight unidirectional LSTM as the student model and perform joint training and multi-level knowledge distillation training; LSTM is a Long Short-Term Memory network. S31. Build a lightweight unidirectional LSTM as the student model: The hidden layer dimension of the student model is 1 / 4 to 1 / 2 of the hidden layer dimension of the teacher model. Generally, the hidden layer dimension of the student model is 32, and the number of layers is single or double stacked. The parameter scale of the student model does not exceed 1 / 4 of that of the teacher model. S32, Introduce a learnable linear mapping layer Learnable linear mapping layers The parameters of the learning model are trained synchronously with those of the student model, without the need for separate pre-training. The input dimension of the learning linear mapping layer is consistent with the hidden layer dimension of the student model, and the output dimension is consistent with the concatenation dimension of the bidirectional hidden states of the teacher model, which is twice the hidden layer dimension of the teacher model. At the same time, multi-level knowledge distillation training is performed on the lightweight unidirectional LSTM student model through the total loss function.

[0027] Total loss function The expression is: ; In the formula, Represents the hard loss term; Indicates the soft loss term; This represents the hidden state alignment loss term; This represents the trend consistency loss term; This represents the hard loss weight, with a value ranging from 0.1 to 0.3. This represents the soft loss weight, with a value ranging from 0.3 to 0.5. This represents the weight of the hidden state alignment loss, with a value ranging from 0.2 to 0.3. This represents the trend consistency loss weight, with a value ranging from 0.1 to 0.2, satisfying... Typical values ​​for each weight are: , , , The weights can be adjusted according to the actual needs of prediction accuracy and trend consistency. By jointly optimizing the four loss terms, the student model not only learns from the final prediction output of the teacher model, but also deeply aligns with the behavioral patterns of the teacher model from the intermediate representation layer and the prediction trend level.

[0028] The hard loss term is the mean squared error (MSE) between the SSI predictions output by the student model and the actual SSI. The soft loss term is the Kullback-Leibler divergence (KL divergence) between the SSI predictions output by the student model and the soft label sequence after normalizing them to probability distributions, with the temperature parameter remaining consistent with step S2. The hidden state alignment loss term is the mean squared error (MSE) between the unidirectional hidden state of the student model at the key time step, projected through the learnable linear mapping layer, and the concatenated bidirectional hidden state of the teacher model at the corresponding time step. The key time step is at least one of the terminal region of the predicted sequence or the region near the inflection point of the SSI change curve. The terminal region of the predicted sequence refers to the last 1 / 4 to 1 / 3 of the predicted sequence, corresponding to the saturation stage of putrefaction evolution. The region near the inflection point of the SSI change curve refers to 1 to 3 time steps before and after the point where the second difference of SSI changes from positive to negative, corresponding to the inflection point stage where the putrefaction rate changes from increasing to decreasing. The trend consistency loss term is used to penalize the number of steps in which the trends of the predicted sequences of the student model and the teacher model are inconsistent at adjacent time steps.

[0029] The specific calculation process for the trend consistency loss term is as follows: Step a, Input the student model prediction sequence Teacher model prediction sequence and predicted step size Step b: Perform initialization, let , Step c, if Then calculate , and will Add 1; Step d, judgment Whether it is true or not, if true, then... Increment by 1 and return to step c; if not true, return directly to step c; when At that time, through Calculate the trend consistency loss term and output the trend consistency loss value; where, This represents the common prediction step size of the student model and the teacher model; This is the index of the time step, with a value range of... ; This represents a sign function that returns 1 when the input value is greater than 0, -1 when it is less than 0, and 0 when it is equal to 0. If the return values ​​of the two sign functions are the same, they are considered to be of the same trend. and These represent the first output of the student model, respectively. The time step and the first SSI prediction values ​​at each time step; and These represent the outputs of the teacher model, respectively. The time step and the first SSI prediction values ​​at each time step; and The SSI prediction sequences output by the student model and the teacher model are respectively. The student model is represented in the first... The first to the second The change in SSI predicted value at each time step; The teacher model is represented in the first... The first to the second The change in SSI predicted value at each time step; This represents the total number of adjacent time steps in the entire prediction sequence where the trends of change in the student model and the teacher model are inconsistent.

[0030] S4 employs an FP16 quantization strategy to convert the trained student model into an edge-side inference format adapted for mobile terminals, such as TensorFlow Lite, Core ML, or ONNX Runtime Mobile. The RGB three-channel mean, RGB three-channel standard deviation, TVB-N mean, and TVB-N standard deviation are deployed to the mobile terminal, allowing inference to be performed offline. During application runtime, the model file and standardized parameters are loaded from the mobile terminal's local storage. After ROI extraction and feature calculation on video frames captured in real-time by the smartphone camera, Z-score standardization is performed using the standardized parameters. The standardized temporal feature sequence is then input into the loaded student model to perform forward inference, generating SSI prediction sequences for multiple future time steps. All computations are performed on the mobile terminal's CPU, GPU, or NPU, requiring no network connection or cloud support.

[0031] The hidden layer dimension of the student model can be adapted to the hardware performance of the target mobile terminal: a higher dimension (such as a hidden layer dimension of 64) is selected for devices with strong computing power (such as flagship mobile phones equipped with NPU), and a lower dimension (such as a hidden layer dimension of 16) is selected for devices with lower computing power, so as to achieve the optimal balance between inference latency and prediction accuracy.

[0032] A lightweight meat freshness time-series prediction method for real-time inference on mobile terminals is executed by a real-time offline meat freshness prediction system deployed on the mobile terminal. This system includes: a local storage unit for storing student model files and standardized parameters, including the RGB three-channel mean, RGB three-channel standard deviation, TVB-N mean, and TVB-N standard deviation; an image acquisition module for acquiring RGB images of meat products on the mobile terminal; a preprocessing module for performing ROI extraction and extracting temporal features from the acquired RGB images to obtain RGB image time-series data; a standardization module for calling local parameters and performing Z-score standardization on the RGB image time-series data to generate a standardized RGB time-series spectral feature matrix; a local inference module for loading and running the student model files locally, performing forward inference on the standardized RGB time-series spectral feature matrix, and outputting SSI prediction values ​​for multiple future steps, without requiring an external network connection during the inference process; and a result output module for outputting the SSI prediction results and presenting corresponding warning information to the user based on the freshness level corresponding to the SSI prediction value. Freshness grades are determined based on SSI (Self-Inspection Index) prediction values, with higher SSI values ​​indicating greater spoilage. The grades include at least four levels: Fresh, Nearly Fresh, Early Spoilage, and Spoilage. Grade thresholds can be adjusted adaptively based on meat type and storage temperature. Taking beef cold storage as an example, the grading rules are as follows: Premium freshness (green alert, safe to eat); Good grade, slightly fresh (yellow alert, recommended to consume as soon as possible); Early stage of spoilage (orange alert, not recommended for consumption); It is severely spoiled (red alert, do not consume).

[0033] Example 1 This embodiment uses standardized RGB time-series spectral characteristic data of beef longissimus dorsi muscle samples to fully illustrate the implementation process and effects of knowledge distillation and mobile deployment.

[0034] Step S1: Teacher model training.

[0035] Using the normalized RGB time-series spectral feature matrix of 60 beef samples over a complete 120-hour storage period (samples collected every 1.5 hours, for a total of 80 time points) as input and the true SSI of the corresponding time points as output labels, the samples were divided into a training set (30 samples), a validation set (20 samples), and an independent test set (10 samples) in a 3:2:1 ratio. The teacher model employed a two-layer stacked BiLSTM with a hidden layer dimension of 64 and a Dropout rate of 0.2. The MSE loss function and the Adam optimizer (initial learning rate 1e) were used. -3 Early stopping mechanism (patience=20). After training, the teacher model's full sequence fit R on the independent test set is... 2 The value reached 0.9926, the RMSE was 0.0809, and the MAE was 0.0600.

[0036] Step S2: Generating teacher soft tags.

[0037] The normalized RGB time-series spectral feature matrix of 30 samples in the training set is input into the trained teacher model to obtain the SSI prediction value output at each time step, using temperature parameters. The corresponding Gaussian kernel is used to smooth the SSI prediction sequence, generating a soft label sequence with temporal evolution characteristics, which is then saved for subsequent distillation training.

[0038] Step S3: Train the student model using multi-level knowledge distillation.

[0039] A lightweight unidirectional LSTM student model is constructed: the hidden layer dimension is 32 (half that of the teacher model), with a single-layer structure. The weights of the loss function for multi-level distillation are set to α=0.2, β=0.4, γ=0.25, δ=0.15, and the key time step selects the last 1 / 3 of the predicted sequence. The model is trained for 200 epochs using the same Adam optimizer and early stopping strategy as the teacher model.

[0040] Experimental Results: After distillation training, the student model's rolling prediction R on the independent test set... 2The performance achieved an accuracy of 0.9746, an RMSE of 0.1568, a MAE of 0.1183, and a maximum absolute error of 0.7243. This is significantly better than a unidirectional LSTM (Ri) trained from scratch with the same parameter size (32 hidden layer dimensions, single layer). 2 =0.9097, RMSE=0.2851), R 2 The improvement was 0.0649, and the RMSE decreased by 45.0%; the maximum absolute error of the student model was only 58% of that of the model trained from scratch.

[0041] Trend consistency verification: The student model's predicted slope direction near the corruption inflection point (SSI=1.5–2.0 interval) is 94.3% consistent with the teacher model, indicating that the trend consistency loss effectively suppresses trend lag.

[0042] Parameter size comparison: The teacher model has approximately 85,000 parameters; the student model has approximately 10,000 parameters, which is about 11.8% of the teacher model (about 1 / 8.5).

[0043] Step S4: Model format conversion and mobile deployment.

[0044] The trained student model was converted to TensorFlow Lite format, and 16-bit floating-point (FP16) quantization was performed using the official TensorFlow Lite tools, converting the model parameters from 32-bit floating-point numbers to 16-bit floating-point numbers. The final model file size was approximately 20KB, with an inference accuracy loss of less than 1%. The model, along with the standardized parameters, was packaged into a mobile application. Testing on a mid-range smartphone (equipped with a Kirin 710A processor) showed that a single inference run (inputting 32 time-step features, corresponding to 48 hours of historical observation data, and outputting 14-step predictions, corresponding to 21 hours) averaged 128ms, with a peak memory usage of approximately 15MB, meeting real-time requirements. The entire inference process was performed offline in airplane mode, running entirely on the terminal's local CPU without calling any cloud interfaces, verifying the usability of this invention in a completely offline environment.

[0045] Therefore, this invention employs the aforementioned lightweight meat freshness time-series prediction method for real-time reasoning on mobile terminals, introducing knowledge distillation technology into the field of food quality time-series prediction, and realizing the structural distillation from BiLSTM to unidirectional LSTM: the student model's rolling prediction R on independent test sets. 2 ≥0.97, RMSE≤0.17, significantly outperforming a unidirectional LSTM model trained from scratch with the same parameter size (R 2The system achieves an improvement of approximately 0.05 and a reduction in RMSE of over 30%, while completely eliminating the problem of future information leakage in online inference. A multi-level distillation strategy for time-series prediction tasks is proposed: based on standard soft distillation, hidden state alignment loss and trend consistency loss are introduced, effectively solving the trend lag problem that occurs in time-series prediction with single soft label distillation. The student model's ability to accurately capture the inflection point of the S-shaped growth curve is close to that of the teacher model, and the maximum absolute error of the distilled student model is only 58% of that of the model trained from scratch with the same parameters. A complete toolchain integration from model training, knowledge distillation, format conversion to edge inference is achieved: the student model's parameter scale is only 1 / 8 of the teacher model (reduced from approximately 85,000 parameters to approximately 10,000 parameters), and the single inference time is less than 150 milliseconds (on mainstream mid-range smartphone CPUs), meeting the real-time offline prediction needs of network-inaccessible environments such as cold chain transportation and retail sites. A hardware adaptation option is provided: the student model scale can be flexibly selected according to the computing power of different terminals, maximizing prediction accuracy while ensuring real-time performance, and improving the universality of the technical solution for heterogeneous terminals.

[0046] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.

Claims

1. A lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, characterized in that, Includes the following steps: S1. Using the standardized RGB time-series spectral feature matrix of multiple meat samples during the complete storage period as input and the real SSI of the corresponding time node as output label, train a double-layer stacked BiLSTM to generate a teacher model; SSI is the standardized spoilage index and BiLSTM is a bidirectional long short-term memory network. S2. Input the standardized RGB time-series spectral feature matrix into the teacher model, obtain the SSI prediction value output by the teacher model at each time step, and use the temperature parameter... Gaussian kernel smoothing is applied to the temporal distribution of SSI predictions to generate soft-label sequences. S3. Construct a lightweight unidirectional LSTM as the student model and perform joint training and multi-level knowledge distillation training; LSTM is a Long Short-Term Memory network. S4. Deploy the student model to a mobile terminal, where the mobile terminal performs inference and generates prediction results offline.

2. The lightweight meat freshness time-series prediction method for real-time inference on mobile terminals according to claim 1, characterized in that, The specific process in S1 is as follows: S11. Collect time-series RGB image data and corresponding TVB-N content data of meat products during the complete storage period of multiple meat samples, and divide them into training set, validation set and independent test set according to the proportion; TVB-N is volatile basic nitrogen; S12. For the RGB image time-series data in the training set, calculate the mean of the three RGB channels, generate the standard deviation of the three RGB channels through Z-score standardization, and obtain the standardized RGB time-series spectral feature matrix; for the meat TVB-N content data in the training set, calculate the TVB-N mean, generate the TVB-N standard deviation through Z-score standardization, and obtain the true SSI based on the TVB-N mean and TVB-N standard deviation. S13. Using the standardized RGB time-series spectral feature matrix as input and the real SSI as output, train the double-layer stacked BiLSTM. After training, the teacher model is obtained. S14. After training, the teacher model's full sequence fit R on the independent test set is... 2 ≥0.

99.

3. The lightweight meat freshness time-series prediction method for real-time inference on mobile terminals according to claim 2, characterized in that, In S2: Temperature parameters The value range is from 3 to 10.

4. The lightweight meat freshness time-series prediction method for real-time inference on mobile terminals according to claim 3, characterized in that, The specific process in S3 is as follows: S31. Construct a lightweight unidirectional LSTM as the student model: The hidden layer dimension of the student model is 1 / 4 to 1 / 2 of the hidden layer dimension of the teacher model, and the parameter size of the student model does not exceed 1 / 4 of that of the teacher model. S32, Introduce a learnable linear mapping layer By jointly training with the student model, a linear mapping layer can be learned to store the one-way hidden states of the student model. Mapped to the bidirectional hidden state concatenated with the teacher model Same dimension, express The forward hidden state at any given moment express The backward hidden state at time step; at the same time, multi-level knowledge distillation training is performed on the lightweight unidirectional LSTM student model through the total loss function.

5. A lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, as described in claim 4, characterized in that: Total loss function The expression is: ; In the formula, Represents the hard loss term; Indicates the soft loss term; This represents the hidden state alignment loss term; This represents the trend consistency loss term; This represents the hard loss weight, with a value ranging from 0.1 to 0.

3. This represents the soft loss weight, with a value ranging from 0.3 to 0.

5. This represents the weight of the hidden state alignment loss, with a value ranging from 0.2 to 0.

3. This represents the trend consistency loss weight, with a value ranging from 0.1 to 0.2, satisfying... .

6. A lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, as described in claim 5, characterized in that: The hard loss term is the mean squared error between the SSI predictions output by the student model and the actual SSI. The soft loss term is the Kullback-Leibler divergence between the SSI predictions output by the student model and the soft label sequence; The hidden state alignment loss term is the mean squared error between the unidirectional hidden state of the student model at the key time step, projected through the learnable linear mapping layer, and the concatenated bidirectional hidden state of the teacher model at the corresponding time step. The key time step is at least one of the following: the end region of the prediction sequence and the region near the inflection point of the SSI change curve. The end region of the prediction sequence refers to the last 1 / 4 to 1 / 3 of the time steps of the prediction sequence. The region near the inflection point of the SSI change curve refers to 1 to 3 time steps before and after the point when the second difference of SSI changes from positive to negative. If there are multiple inflection points in the prediction sequence, 1 to 3 time steps before and after each inflection point are selected as key time steps. The trend consistency loss term is used to penalize the number of steps in which the student model's predicted sequence and the teacher model's predicted sequence show inconsistent trends at adjacent time steps.

7. A lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, as described in claim 6, is characterized in that... The expression for the trend consistency loss term is: ; In the formula, This represents the common prediction step size of the student model and the teacher model; This is the index of the time step, with a value range of... ; This indicates an indicator function that takes the value 1 when the condition inside the parentheses is true, and 0 otherwise. This represents a sign function that returns 1 when the input value is greater than 0, -1 when it is less than 0, and 0 when it is equal to 0. If the return values ​​of the two sign functions are the same, they are considered to be of the same trend. and These represent the first output of the student model, respectively. The time step and the first SSI prediction values ​​at each time step; and These represent the outputs of the teacher model, respectively. The time step and the first SSI prediction values ​​at each time step; and These are the SSI prediction sequences output by the student model and the teacher model, respectively.

8. A lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, as described in claim 7, is characterized in that... In S4: The trained student model is converted into an edge inference format adapted to mobile terminals. The RGB three-channel mean, RGB three-channel standard deviation, TVB-N mean, and TVB-N standard deviation are deployed to the mobile terminal, and the mobile terminal completes the inference in offline mode.

9. A lightweight time-series prediction method for meat freshness based on real-time inference for mobile terminals, as described in claim 8, characterized in that: The edge inference format is one or more of TensorFlow Lite, Core ML or ONNX Runtime Mobile formats; when converting to the edge inference format, the FP16 quantization strategy is used, and the model accuracy loss after quantization is less than 1%.