A dish recognition optimization method based on parameter offset
By introducing adversarial training methods and lightweight model design, combined with the adjustment of parameter offsets, the problems of identification deviation and error adjustment in dish recognition are solved, and more efficient and accurate dish recognition is achieved.
Patent Information
- Application Number
- CN202411878504.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-04-04
- Estimated Expiration
- 2044-12-19
AI Technical Summary
Existing dish recognition methods are prone to identification deviations when dealing with interference in complex environments, and lack effective adjustments to the deviation results, resulting in the inability to resolve errors in a timely manner.
The dish recognition optimization method based on parameter offset is adopted, and the CNN model is optimized by introducing an adversarial training method, and a lightweight small models A and B are built, respectively, used to train correct and bias samples, calculate parameter offsets and adjust model parameters, and periodically train the model to optimize recognition performance.
It significantly improves the ability of the dish recognition model to identify biased samples, reduces the complexity of the model, improves the training and reasoning speed, and ensures high-precision recognition of the correct samples.
Smart Images

Figure CN119323717B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information recognition technology, and in particular to a dish recognition optimization method based on parameter offset. Background Art
[0002] With the improvement of living standards and the emphasis on food culture, the catering industry has developed rapidly, and the application of dish recognition systems based on computer vision technology has become more and more extensive. These systems can help catering companies achieve intelligent management, automated settlement and optimize user experience, which can effectively improve operational efficiency and reduce labor costs. However, existing dish recognition methods face multiple challenges. The appearance, color and shape of different dishes are significantly different, and the similarity of similar dishes increases the difficulty of model recognition. Secondly, there are often problems such as noise, illumination changes and adversarial samples in dish image data, which makes the recognition model prone to bias and reduces the accuracy of recognition. The increase in the number of large-scale dishes also requires the recognition system to have higher processing speed and lower resource consumption. Although traditional convolutional neural networks perform well in image recognition, they are prone to overfitting or recognition bias in dish recognition tasks and cannot meet high-precision requirements. In addition, training models requires a large amount of labeled data, while high-quality dish image data is difficult to obtain. There are often noise and biased samples in the data set, which increases the difficulty of model training and lacks adjustments to biased recognition results.
[0003] A Chinese patent application, with publication number CN114613469A, is entitled: Method for generating a dish recognition model and method for identifying a dish. The method includes: collecting training image information of multiple dishes; marking the dish information in the training image information, and generating a dish recognition model. The dish information includes ingredient information and / or dish name information of each dish. By training and generating a dish recognition model, the model can be conveniently applied to recognize all the dish information contained in the image at one time, which can not only improve the recognition efficiency, but also facilitate the aggregation of information, so that users can quickly understand the dining situation by taking an image containing all the dishes, simplifying the input operation, and there is no need to repeatedly run the model, which helps to reduce the operating load. However, this method does not take into account the situation where the recognition of dishes is inaccurate due to overlapping coverage or other reasons.
[0004] A Chinese patent application, with publication number CN118038444A, is entitled: A method for dish recognition based on a cascade feature fusion network, the method comprising: obtaining dish images; labeling dish images to obtain dish image information; training a cascade convolutional neural network model based on dish image information to obtain a target cascade convolutional neural network model; obtaining dish images to be recognized and dish image information to be recognized based on two-dimensional camera calibration technology; outputting the dish images to be recognized and dish image information to be recognized through a target cascade convolutional neural network model to obtain dish recognition information. The invention can more accurately obtain information about dish images to be recognized, improve the acquisition quality of dish images, avoid the impact of dish image quality acquisition on dish recognition, and improve the accuracy of dish recognition by subsequent cascade convolutional neural network models. However, this method does not take into account the correction and improvement of inaccurate dish recognition. Summary of the invention
[0005] The main technical problem solved by the present invention is to provide a dish recognition optimization method based on parameter offset, which can solve the problem that the dish recognition results are biased and cannot be adjusted in time, thereby causing the error to remain unresolved.
[0006] In order to solve the above technical problems, a technical solution adopted by the present invention is to provide a dish recognition optimization method based on parameter offset, the method comprising:
[0007] S100: Collect image datasets of different dishes and perform preprocessing operations;
[0008] S200: construct a CNN (Convolutional Neural Network) model, introduce an adversarial training method to optimize the CNN model, and obtain a dish recognition model;
[0009] S300: using the dish recognition model to perform recognition analysis on the image data set, obtaining recognition results, judging the correctness of the recognition results, and storing the image data set into two new data sets;
[0010] S400: Based on the architecture of the dish recognition model, lightweight small models A and B are constructed respectively, and the two new data sets are used for training;
[0011] S500: extracting parameter values of the lightweight small models A and B respectively and calculating parameter offsets;
[0012] S600: adjusting and updating the parameters of the dish recognition model according to the parameter offset;
[0013] S700: Periodically training the dish recognition model to obtain and save the trained and optimized model for subsequent dish recognition processes;
[0014] The preprocessing operation includes: data cleaning, data enhancement, denoising, Gaussian filtering algorithm, and normalization processing;
[0015] The correctness judgment refers to judging the recognition result of the image data set. If the recognition result of the image data set is correct, the image data set with the correct recognition will be stored in the correct data set. If the recognition result of the image data set is deviated, the image data set with the deviated recognition will be stored in the deviated data set.
[0016] The two new data sets are respectively a correct data set and a deviation data set;
[0017] The model structure of the lightweight small models A and B is the same as that of the dish recognition model, and the parameter magnitude of the lightweight small models A and B is smaller than that of the dish recognition model.
[0018] Furthermore, the step S200 includes:
[0019] S210: Build a CNN model, including multiple convolutional layers, pooling layers, fully connected layers, and add batch normalization layers to prevent overfitting;
[0020] S220: Initialize model parameters and use the cross entropy loss function as the loss metric for the dish recognition problem;
[0021] S230: Input the image data set into the CNN model, perform forward propagation layer by layer for calculation, and apply a ReLU (Rectified Linear Unit) activation function in the convolution layer;
[0022] S240: Calculate the gradient of each parameter in the CNN using a back propagation algorithm, and update the parameters of the CNN model using a gradient descent method;
[0023] S250: Generate adversarial training data as adversarial samples using a fast gradient symbol adversarial training method for the original samples, and train the model using the original samples and the generated adversarial samples;
[0024] S260: Calculate the loss of the original sample and the adversarial sample to define a loss function of adversarial training;
[0025] S270: According to the loss function of the adversarial training, the parameters of the CNN model are updated again using a gradient descent algorithm to obtain a dish recognition model;
[0026] S280: Repeat steps S240 to S270 until both the training loss and the validation loss are stable and the model converges. Save the trained model for subsequent calls:
[0027] The cross entropy loss function is calculated as follows:
[0028] ;
[0029] in, refers to the value of the cross entropy loss function, is the original sample size, Refers to the number of dish categories. is the index of the original number of samples, Refers to the index of the dish category. refers to the true label of the original sample in the dish category, It refers to the probability that the CNN model predicts that the original sample belongs to the dish category;
[0030] The dish category refers to the dish category label in the public dataset specifically used for dish identification;
[0031] The updating formula for updating the parameters of the CNN model is:
[0032] ;
[0033] in, refers to the updated model parameters, refers to the current model parameters, is the learning rate, refers to the gradient of the cross entropy loss function with respect to the model parameters, It refers to the number of times;
[0034] The original sample refers to the image data set after preprocessing operation;
[0035] The generation formula of the adversarial training data is:
[0036] ;
[0037] in, refers to adversarial samples, refers to the original sample, is a hyperparameter of the perturbation size, Refers to the sign function, which means adjusting the perturbation direction according to the sign of the gradient. It refers to the gradient of the cross entropy loss function with respect to the input original sample. refers to the true label of the original sample;
[0038] The loss function of the adversarial training is expressed as:
[0039] ;
[0040] in, refers to the loss function of adversarial training, is the loss of the original sample, refers to the loss of adversarial samples, refers to the hyperparameter that controls the loss weight of adversarial samples, refers to the total number of all original samples and generated adversarial samples, Refers to the index of the total number of all original samples and generated adversarial samples;
[0041] The update again is expressed as:
[0042] ;
[0043] in, refers to the updated model parameters, refers to the current model parameters, is the learning rate, refers to the gradient of the adversarial training loss function with respect to the model parameters, It refers to the number of times.
[0044] Furthermore, the S400 includes:
[0045] S410: Based on the architecture of the dish recognition model, reduce the number of convolutional layers and fully connected layers, and construct lightweight small models A and B;
[0046] S420: First, use the correct data set to train the small model A;
[0047] S430: After the training of the small model A is completed, the small model B is trained using the deviation data set;
[0048] The cross entropy loss function of the small model A is expressed as:
[0049] ;
[0050] in, refers to the cross entropy loss function of the small model A, refers to the number of correctly classified samples, Refers to the number of dish categories. is the index of the number of correctly classified samples, Refers to the index of the dish category. refers to the true label of the correctly classified sample in the dish category, It refers to the probability that the small model A predicts that the correctly classified sample belongs to the dish category;
[0051] The cross entropy loss function of the small model B is expressed as:
[0052] ;
[0053] in, refers to the cross entropy loss function of the small model B, refers to the number of bias classification samples, Refers to the number of dish categories. is the index of the number of biased classification samples, Refers to the index of the dish category. It refers to the true label of the deviation classification sample in the dish category. is the probability that the small model B predicts that the biased classification sample belongs to the dish category.
[0054] Further, the extracting the parameter values of the two lightweight small models A and B respectively and calculating the parameter offset means extracting the parameter values of the small model A and the small model B respectively, and calculating the deviation between the parameter values of the small model A and the small model B to obtain the parameter offset;
[0055] The parameter value of the small model A is expressed as ;
[0056] The parameter value of the small model B is expressed as ;
[0057] The parameter offset is calculated as follows:
[0058] ;
[0059] in, refers to the parameter offset between the small model A and the small model B, refers to the parameter value of the small model A, Refers to the parameter value of the small model B.
[0060] Further, adjusting and updating the parameters of the dish recognition model according to the parameter offset refers to calculating the parameter update amount according to the parameter offset and the adjustment step of the dish recognition model, and adjusting the parameters of the dish recognition model using the parameter update amount with the goal of achieving the best effect of the dish recognition model in recognizing the deviation samples;
[0061] The adjustment step size refers to a hyperparameter that controls the update amplitude of the parameters when updating the model parameters, and is expressed as: ;
[0062] The parameter update amount is calculated as follows:
[0063] ;
[0064] in, It refers to the parameter update amount calculated from the parameter deviation of the two small models. Refers to the adjustment step size, which is used to control the parameter update amplitude. It refers to the parameter offset between small model A and small model B;
[0065] The parameter adjustment is expressed as:
[0066] ;
[0067] in, refers to the updated dish recognition model parameters, refers to the current parameters of the dish recognition model, It refers to the parameter update amount calculated from the parameter deviation of the two small models.
[0068] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are:
[0069] 1. The present invention provides a dish recognition optimization method based on parameter offset. By introducing an adversarial training method, the model can better cope with interference in a complex environment, and introduces a lightweight small model design, which reduces the complexity of the model and improves the speed of training and reasoning.
[0070] 2. The present invention provides a method for optimizing dish recognition based on parameter offset, which effectively improves the model's ability to distinguish between correct samples and deviation samples by classifying correct and deviation samples into two different data sets, and then training small models A and B respectively. The dish recognition model is adjusted in a targeted manner by calculating the parameter offset, so that the model can significantly improve the recognition ability of deviation samples while maintaining high accuracy in recognizing correct samples. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] Figure 1 It is a flow chart of a dish recognition optimization method based on parameter offset provided by the present invention.
[0072] Figure 2 It is a training flow chart for constructing a dish recognition model for a dish recognition optimization method based on parameter offset provided by the present invention.
[0073] Figure 3 It is a lightweight small model construction training flow chart of a dish recognition optimization method based on parameter offset provided by the present invention. DETAILED DESCRIPTION
[0074] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby making a clearer and more definite definition of the protection scope of the present invention.
[0075] See also Figure 1 , Figure 2 and Figure 3 , the embodiment of the present invention includes:
[0076] like Figure 1 As shown, a flow chart of a method for optimizing dish recognition based on parameter offset includes:
[0077] S100: Collect image datasets of different dishes and perform preprocessing operations.
[0078] Furthermore, the preprocessing operation includes: data cleaning, data enhancement, denoising, Gaussian filtering algorithm, and normalization processing.
[0079] S200: Build a CNN model, introduce an adversarial training method to optimize the CNN model, and obtain a dish recognition model.
[0080] Furthermore, if Figure 2 As shown, a dish recognition model construction training flow chart of a dish recognition optimization method based on parameter offset, said S200, comprises:
[0081] S210: Build a CNN model, including multiple convolutional layers, pooling layers, fully connected layers, and add batch normalization layers to prevent overfitting;
[0082] S220: Initialize model parameters and use the cross entropy loss function as the loss metric for the dish recognition problem;
[0083] S230: Input the image data set into the CNN model, perform forward propagation layer by layer for calculation, and apply the ReLU activation function in the convolution layer;
[0084] S240: Calculate the gradient of each parameter in the CNN using a back propagation algorithm, and update the parameters of the CNN model using a gradient descent method;
[0085] S250: Generate adversarial training data as adversarial samples using a fast gradient symbol adversarial training method for the original samples, and train the model using the original samples and the generated adversarial samples;
[0086] S260: Calculate the loss of the original sample and the adversarial sample to define a loss function of adversarial training;
[0087] S270: According to the loss function of the adversarial training, the parameters of the CNN model are updated again using a gradient descent algorithm to obtain a dish recognition model;
[0088] S280: Repeat steps S240 to S270 until the training loss and the validation loss are both stable and the model converges, and save the trained model for subsequent calls;
[0089] The cross entropy loss function is calculated as follows:
[0090] ;
[0091] in, refers to the value of the cross entropy loss function, is the original sample size, Refers to the number of dish categories. is the index of the original number of samples, Refers to the index of the dish category. refers to the true label of the original sample in the dish category, It refers to the probability that the CNN model predicts that the original sample belongs to the dish category;
[0092] The dish category refers to the dish category label in the public dataset specifically used for dish identification;
[0093] The updating formula for updating the parameters of the CNN model is:
[0094] ;
[0095] in, refers to the updated model parameters, refers to the current model parameters, is the learning rate, refers to the gradient of the cross entropy loss function with respect to the model parameters, It refers to the number of times;
[0096] The original sample refers to the image data set after preprocessing operation;
[0097] The generation formula of the adversarial training data is:
[0098] ;
[0099] in, refers to adversarial samples, refers to the original sample, is a hyperparameter of the perturbation size, Refers to the sign function, which means adjusting the perturbation direction according to the sign of the gradient. It refers to the gradient of the cross entropy loss function with respect to the input original sample. refers to the true label of the original sample;
[0100] The loss function of the adversarial training is expressed as:
[0101] ;
[0102] in, refers to the loss function of adversarial training, is the loss of the original sample, refers to the loss of adversarial samples, refers to the hyperparameter that controls the loss weight of adversarial samples, refers to the total number of all original samples and generated adversarial samples, Refers to the index of the total number of all original samples and generated adversarial samples;
[0103] The update again is expressed as:
[0104] ;
[0105] in, refers to the updated model parameters, refers to the current model parameters, is the learning rate, refers to the gradient of the adversarial training loss function with respect to the model parameters, It refers to the number of times.
[0106] S300: using the dish recognition model to perform recognition analysis on the image data set, obtaining recognition results, judging the correctness of the recognition results, and storing the image data set into two new data sets.
[0107] Furthermore, the correctness judgment refers to judging the recognition result of the image data set. If the recognition result of the image data set is correct, the image data set with the correct recognition is stored in the correct data set. If the recognition result of the image data set is deviated, the image data set with the deviated recognition is stored in the deviated data set.
[0108] The two new data sets are respectively a correct data set and a deviation data set.
[0109] S400: Based on the architecture of the dish recognition model, lightweight small models A and B are constructed respectively, and the two new data sets are used for training.
[0110] Furthermore, the model structure of the lightweight small models A and B is the same as that of the dish recognition model, and the parameter magnitude of the lightweight small models A and B is smaller than that of the dish recognition model.
[0111] Furthermore, if Figure 3 As shown, a lightweight small model construction training flow chart of a dish recognition optimization method based on parameter offset, said S400, comprises:
[0112] S410: Based on the architecture of the dish recognition model, reduce the number of convolutional layers and fully connected layers, and construct lightweight small models A and B;
[0113] S420: First, use the correct data set to train the small model A;
[0114] S430: After the training of the small model A is completed, the small model B is trained using the deviation data set;
[0115] The cross entropy loss function of the small model A is expressed as:
[0116] ;
[0117] in, refers to the cross entropy loss function of the small model A, refers to the number of correctly classified samples, Refers to the number of dish categories. is the index of the number of correctly classified samples, Refers to the index of the dish category. refers to the true label of the correctly classified sample in the dish category, It refers to the probability that the small model A predicts that the correctly classified sample belongs to the dish category;
[0118] The cross entropy loss function of the small model B is expressed as:
[0119] ;
[0120] in, refers to the cross entropy loss function of the small model B, refers to the number of bias classification samples, Refers to the number of dish categories. is the index of the number of biased classification samples, Refers to the index of the dish category. It refers to the true label of the deviation classification sample in the dish category. is the probability that the small model B predicts that the biased classification sample belongs to the dish category.
[0121] S500: extracting parameter values of the two lightweight small models A and B respectively and calculating parameter offsets.
[0122] Further, respectively extracting the parameter values of the two lightweight small models A and B and calculating the parameter offset means respectively extracting the parameter values of the small model A and the small model B, and calculating the deviation between the parameter values of the small model A and the small model B to obtain the parameter offset;
[0123] The parameter value of the small model A is expressed as ;
[0124] The parameter value of the small model B is expressed as ;
[0125] The parameter offset is calculated as follows:
[0126] ;
[0127] in, refers to the parameter offset between the small model A and the small model B, refers to the parameter value of the small model A, Refers to the parameter value of the small model B.
[0128] S600: Adjust and update the parameters of the dish recognition model according to the parameter offset.
[0129] Further, adjusting and updating the parameters of the dish recognition model according to the parameter offset refers to calculating the parameter update amount according to the parameter offset and the adjustment step of the dish recognition model, and adjusting the parameters of the dish recognition model using the parameter update amount with the goal of achieving the best effect of the dish recognition model in recognizing the deviation samples;
[0130] The adjustment step size refers to a hyperparameter that controls the update amplitude of the parameters when updating the model parameters, and is expressed as: ;
[0131] The parameter update amount is calculated as follows:
[0132] ;
[0133] in, It refers to the parameter update amount calculated from the parameter deviation of the two small models. Refers to the adjustment step size, which is used to control the parameter update amplitude. It refers to the parameter offset between small model A and small model B;
[0134] The parameter adjustment is expressed as:
[0135] ;
[0136] in, refers to the updated dish recognition model parameters, refers to the current parameters of the dish recognition model, It refers to the parameter update amount calculated from the parameter deviation of the two small models.
[0137] S700: Periodically train the dish recognition model to obtain and save the trained and optimized model for subsequent dish recognition processes.
[0138] In another embodiment of the present invention, a university cafeteria needs to launch an automatic settlement system that can quickly identify the dishes on the students' plates and calculate the total price. The cafeteria provides 40 common dishes with a variety of ingredients. The initial dish recognition system performed poorly in the test, especially similar dishes (such as "Fish-flavored Shredded Pork" and "Mushu Pork") were easily confused, affecting the actual settlement. To this end, an optimization method based on parameter offset is used to improve the recognition performance.
[0139] Use the camera installed at the canteen checkout window to take 10,000 photos of dishes, covering 40 categories of dishes (such as "braised pork" and "Mapo tofu", etc.). The pictures taken include scenes with different lighting, angles, and combinations of dishes, and the pictures taken are stored as training data sets.
[0140] Blurred or highly reflective images were deleted, leaving 9,000 high-quality images. Each image was then rotated, cropped, and brightness adjusted to generate 36,000 enhanced data. Background noise was then removed to make the outline of the dish clearer. Finally, the pixel values were normalized to the [0,1] range to improve the stability of model training.
[0141] The CNN model was built using the TensorFlow framework, which includes 4 convolutional layers, 2 pooling layers, and 1 fully connected layer. Batch normalization was added to each layer, and ReLU was selected as the activation function. The parameters were initialized and cross entropy was used as the loss function. Taking "Kung Pao Chicken" as an example, a small perturbation was applied to the original sample to generate an adversarial sample that was difficult to distinguish. The adversarial sample and the original sample were input into the model together to calculate the total loss function. Then the parameters were updated through backpropagation and gradient descent, and the training was repeated until the model converged. Finally, an optimized model that can recognize 40 dishes was obtained. The optimized model was used to test the training data set, and the images were divided into two categories according to the recognition results. For example, "braised pork" was correctly identified and stored in the correct data set (8,000 images), and "fish-flavored pork shreds" were misidentified as "mu shu meat" and stored in the deviation data set (1,000 images).
[0142] Based on the CNN model architecture, reduce the number of convolutional layers and fully connected layers, build small model A, use the "correct data set" (8,000 images) to train small model A, and build small model B based on the CNN model architecture. Use the "biased data set" (1,000 images) to train small model B, focusing on optimizing easily confused samples. Extract parameter values from the trained small models A and B, calculate the parameter offset of the two, calculate the parameter update amount based on the calculated parameter offset and adjustment step size, use the parameter update amount to adjust the parameters of the dish recognition model, use the optimized dish recognition model for the cafeteria automatic settlement system, collect new data every month, and retrain the model according to the above process.
[0143] The above descriptions are merely embodiments of the present invention and are not intended to limit the scope of the present invention. Any equivalent structures or equivalent process changes made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the protection scope of the present invention.
Claims
1. A method for optimizing dish recognition based on parameter offset, characterized in that: include: S100: Collect image datasets of different dishes and perform preprocessing operations; S2 00: Build a CNN model, introduce adversarial training method to optimize the CNN model, and obtain a dish recognition model; S300: using the dish recognition model to perform recognition analysis on the image data set, obtaining recognition results, judging the correctness of the recognition results, and storing the image data set into two new data sets; S400: Based on the architecture of the dish recognition model, lightweight small models A and B are constructed respectively, and the two new data sets are used for training; S5 00: extract the parameter values of the lightweight small models A and B respectively and calculate the parameter offset; S600: adjusting and updating the parameters of the dish recognition model according to the parameter offset; S700: Periodically training the dish recognition model to obtain and save the trained and optimized model for subsequent dish recognition processes; The preprocessing operation includes: data cleaning, data enhancement, denoising, Gaussian filtering algorithm, and normalization processing; The correctness judgment refers to judging the recognition result of the image data set. If the recognition result of the image data set is correct, the image data set with the correct recognition will be stored in the correct data set. If the recognition result of the image data set is deviated, the image data set with the deviated recognition will be stored in the deviated data set. The two new data sets are respectively a correct data set and a deviation data set; The model structure of the lightweight small models A and B is the same as that of the dish recognition model, and the parameter magnitude of the lightweight small models A and B is smaller than that of the dish recognition model; The S400 includes: S410: Based on the architecture of the dish recognition model, reduce the number of convolutional layers and fully connected layers, and construct lightweight small models A and B; S420: First, use the correct data set to train the small model A; S430: After the training of the small model A is completed, the small model B is trained using the deviation data set.
2. A method for optimizing dish recognition based on parameter shift according to claim 1, characterized in that: The S200 includes: S210: Build a CNN model, including multiple convolutional layers, pooling layers, fully connected layers, and add batch normalization layers to prevent overfitting; S220: Initialize model parameters and use the cross entropy loss function as the loss metric for the dish recognition problem; S230: Input the image data set into the CNN model, perform forward propagation layer by layer for calculation, and apply the ReLU activation function in the convolution layer; S240: Calculate the gradient of each parameter in the CNN using a back propagation algorithm, and update the parameters of the CNN model using a gradient descent method; S250: Generate adversarial training data as adversarial samples using a fast gradient symbol adversarial training method for the original samples, and train the model using the original samples and the generated adversarial samples; S260: Calculate the loss of the original sample and the adversarial sample to define a loss function of adversarial training; S270: According to the loss function of the adversarial training, the parameters of the CNN model are updated again using a gradient descent algorithm to obtain a dish recognition model; S280: Repeat steps S240 to S270 until the training loss and the validation loss are both stable and the model converges, and save the trained model for subsequent calls; The cross entropy loss function is calculated as follows: ; in, refers to the value of the cross entropy loss function, is the original sample size, Refers to the number of dish categories. is the index of the original number of samples, Refers to the index of the dish category. refers to the true label of the original sample in the dish category, It refers to the probability that the CNN model predicts that the original sample belongs to the dish category; The dish category refers to the dish category label in the public dataset specifically used for dish identification; The updating formula for updating the parameters of the CNN model is: ; in, refers to the updated model parameters, refers to the current model parameters, is the learning rate, refers to the gradient of the cross entropy loss function with respect to the model parameters, It refers to the number of times; The original sample refers to the image data set after preprocessing operation; The generation formula of the adversarial training data is: ; in, refers to adversarial samples, refers to the original sample, is a hyperparameter of the perturbation size, Refers to the sign function, which means adjusting the perturbation direction according to the sign of the gradient. It refers to the gradient of the cross entropy loss function with respect to the input original sample. refers to the true label of the original sample; The loss function of the adversarial training is expressed as: ; in, refers to the loss function of adversarial training, is the loss of the original sample, refers to the loss of adversarial samples, refers to the hyperparameter that controls the loss weight of adversarial samples, refers to the total number of all original samples and generated adversarial samples, Refers to the index of the total number of all original samples and generated adversarial samples; The update again is expressed as: ; in, refers to the updated model parameters, refers to the current model parameters, is the learning rate, refers to the gradient of the adversarial training loss function with respect to the model parameters, It refers to the number of times.
3. The method for optimizing dish recognition based on parameter shift according to claim 1, characterized in that: The cross entropy loss function of the small model A is expressed as: ; in, refers to the cross entropy loss function of the small model A, refers to the number of correctly classified samples, Refers to the number of dish categories. is the index of the number of correctly classified samples, Refers to the index of the dish category. refers to the true label of the correctly classified sample in the dish category, It refers to the probability that the small model A predicts that the correctly classified sample belongs to the dish category; The cross entropy loss function of the small model B is expressed as: ; in, refers to the cross entropy loss function of the small model B, refers to the number of bias classification samples, Refers to the number of dish categories. is the index of the number of biased classification samples, Refers to the index of the dish category. It refers to the true label of the deviation classification sample in the dish category. is the probability that the small model B predicts that the biased classification sample belongs to the dish category.
4. The method for optimizing dish recognition based on parameter shift according to claim 1, characterized in that: The extracting the parameter values of the two lightweight small models A and B respectively and calculating the parameter offset refers to extracting the parameter values of the small model A and the small model B respectively, and calculating the deviation between the parameter values of the small model A and the small model B to obtain the parameter offset; The parameter value of the small model A is expressed as ; The parameter value of the small model B is expressed as ; The parameter offset is calculated as follows: ; in, refers to the parameter offset between the small model A and the small model B, refers to the parameter value of the small model A, Refers to the parameter value of the small model B.
5. The method for optimizing dish recognition based on parameter shift according to claim 1, characterized in that: The adjusting and updating of the parameters of the dish recognition model according to the parameter offset refers to calculating the parameter update amount according to the parameter offset and the adjustment step of the dish recognition model, and adjusting the parameters of the dish recognition model using the parameter update amount with the goal of achieving the best effect of the dish recognition model in recognizing the deviation samples; The adjustment step size refers to a hyperparameter that controls the update amplitude of the parameters when updating the model parameters, and is expressed as: ; The parameter update amount is calculated as follows: ; in, It refers to the parameter update amount calculated from the parameter deviation of the two small models. Refers to the adjustment step size, which is used to control the parameter update amplitude. It refers to the parameter offset between small model A and small model B; The parameter adjustment is expressed as: ; in, refers to the updated dish recognition model parameters, refers to the current parameters of the dish recognition model, It refers to the parameter update amount calculated from the parameter deviation of the two small models.
Citation Information
Patent Citations
Dish identification model generation method and dish identification method
CN114613469A
Dish identification method based on cascade feature fusion network
CN118038444A
Dynamic aggregation federated learning system based on pruning and bidirectional quantization
CN118863015A