Fruit and vegetable identification model and training method thereof
By combining ArcFaceLoss and CircleLoss loss functions, and using knowledge distillation and feature distillation losses, the problem of poor recognition effect and limited computing power of fruit and vegetable recognition models in the existing technology in the untrained category is solved. It realizes efficient identification of models under different categories and improves the recognition rate of small models.
Patent Information
- Application Number
- CN202411566960.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2025-02-18
AI Technical Summary
The existing fruit and vegetable recognition models are trained through cross-entropy loss functions, resulting in poor recognition results in untrained categories, and due to the computing power of the terminal equipment, large models cannot be used for inference.
Using a training method combining ArcFaceLoss loss and CircleLoss loss, the neural network model is trained by minimizing mixed losses, improving the recognition effect of the model under different categories, and through knowledge distillation and feature distillation losses, the parameters are trained to be small but Models with high recognition rate.
The recognition effect of the model under different categories has been improved, so that it has zero sample learning ability, and through feature distillation loss, the recognition rate of small models has been improved, reaching a 5%-10% increase.
Smart Images

Figure CN119478925A_ABST
Abstract
Description
Technical Field
[0001] The present invention mainly relates to the technical field of artificial intelligence models, and in particular to a fruit and vegetable recognition model and a training method thereof. Background Art
[0002] In the scenario of weighing fruits and vegetables, it is necessary to identify the categories of fruits and vegetables. The principle of fruit and vegetable recognition based on artificial intelligence models is to treat the fruit and vegetable recognition problem as a classification problem. In order to accurately classify, a good loss function is particularly needed to separate different features. The existing fruit and vegetable recognition model training method uses the cross entropy loss function for training. The obtained fruit and vegetable recognition model works well on trained categories, but not well on untrained categories. At the same time, due to the limited computing power of the terminal equipment, only a small model can be used for reasoning, which further affects the accuracy of the fruit and vegetable recognition model. Summary of the invention
[0003] The technical problem to be solved by the present invention is to provide a fruit and vegetable recognition model and a training method thereof, so as to solve the problem that the model recognition effect obtained by training with the existing loss function is not good.
[0004] To solve the above technical problems, the present invention provides a training method for a fruit and vegetable recognition model, comprising: obtaining a data set, the data set comprising fruit and vegetable images and their corresponding labeled categories; inputting the data set into a neural network model, the neural network model performing feature extraction on the fruit and vegetable images to obtain fruit and vegetable image features; calculating ArcFaceLoss loss and CircleLoss loss respectively according to the fruit and vegetable image features and the labeled categories; combining the ArcFaceLoss loss and CircleLoss loss to obtain a first-stage mixed loss; minimizing the first-stage mixed loss and updating the hyperparameters of the neural network model to obtain a trained first fruit and vegetable recognition model.
[0005] Optionally, calculating the ArcFaceLoss loss according to the fruit and vegetable image features and the labeled category includes: obtaining a category center vector corresponding to the labeled category, recorded as a first category center vector, and calculating a first angle according to the fruit and vegetable image features and the first category center vector; obtaining category center vectors of categories other than the labeled category, recorded as second category center vectors, and calculating a second angle according to the fruit and vegetable image features and the second category center vector; and calculating the ArcFaceLoss loss according to the first angle and the second angle.
[0006] Optionally, the ArcFaceLoss loss is calculated by the following formula:
[0007]
[0008] Among them, L arcface is the ArcFaceLoss loss, is the first angle, θ j is the second angle, s and m are both hyperparameters, representing the strictness of similarity of similar features, and N is the total category of fruits and vegetables.
[0009] Optionally, calculating the CircleLoss loss according to the fruit and vegetable image features and the labeled category includes: calculating a first Euclidean distance between the fruit and vegetable image features and features of the same category as the labeled category; calculating a second Euclidean distance between the fruit and vegetable image features and features of a different category from the labeled category; and calculating the CircleLoss loss according to the first Euclidean distance and the second Euclidean distance.
[0010] Optionally, the CircleLoss loss is calculated by the following formula:
[0011] L circle =max(distance(A,P)-distance(A,N)+margin,0)
[0012] Among them, L circle is the CircleLoss loss, distance(A, P) is the first Euclidean distance, distance(A, N) is the second Euclidean distance, A and P are of the same category, A and N are of different categories, and margin represents the degree of strictness.
[0013] Optionally, the first stage mixing loss is:
[0014] L total1 =α·L arcface +L circle
[0015] Among them, L total1 is the first stage mixing loss, L arcface is the ArcFaceLoss loss, L circle is the CircleLoss loss, α is the first weight coefficient and its value range is 0 to 1.
[0016] Optionally, as the number of training rounds increases, the first weight coefficient α increases from 0 to 1.
[0017] Optionally, the first weight coefficient α is calculated by the following formula:
[0018]
[0019] Among them, n cur is the current training round number, n total is the total number of training rounds.
[0020] Optionally, the method further includes: migrating the recognition capability of the first fruit and vegetable recognition model based on knowledge distillation to obtain a second fruit and vegetable recognition model; training the second fruit and vegetable recognition model using a second-stage mixed loss to obtain a trained second fruit and vegetable recognition model, wherein the parameter amount of the second fruit and vegetable recognition model is smaller than that of the first fruit and vegetable recognition model.
[0021] Optionally, the second-stage mixed loss includes ArcFaceLoss loss, CircleLoss loss and feature distillation loss.
[0022] Optionally, the characteristic distillation loss is calculated by the following formula:
[0023] L distill =1-cos(F teacher , F student )
[0024] Among them, L distill is the characteristic distillation loss, F teacher is the feature output by the first fruit and vegetable recognition model, F student It is the feature output by the second fruit and vegetable recognition model.
[0025] Optionally, the second stage mixing loss is:
[0026] L total2 =α·L arcface +L circle +βL distill
[0027] Among them, L total2 is the second stage mixing loss, L arcface is the ArcFaceLoss loss, L circle is the CircleLoss loss, α is the first weight coefficient and its value range is 0 to 1, and β is the second weight coefficient.
[0028] In order to solve the above technical problems, the present invention provides a fruit and vegetable recognition model for classifying vegetables or fruits, which is trained by the above-mentioned fruit and vegetable recognition model training method.
[0029] Compared with the prior art, the present invention has the following advantages:
[0030] The training method of the fruit and vegetable recognition model of the present invention combines ArcFaceLoss loss and CircleLoss loss to obtain a first-stage mixed loss. The first-stage mixed loss is used to train the model, so that the model can have the ability of zero-sample learning. Even if the corresponding category has not been seen, it can still be distinguished by features, thereby improving the recognition effect of the model under different categories; secondly, the training method of the fruit and vegetable recognition model of the present invention proposes to first train a large model and then use the large model to perform feature distillation on a small model. When training the small model, feature distillation loss is additionally introduced, which can improve the recognition effect of the small model. Compared with not adding model distillation, the recognition rate of the small model can be improved by 5%-10%. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] The accompanying drawings are included to provide a further understanding of the present application. They are included and constitute a part of the present application. The accompanying drawings illustrate embodiments of the present application and together with the present specification serve to explain the principles of the present application. In the accompanying drawings:
[0032] Figure 1 4 is a flow chart of a method for training a fruit and vegetable recognition model according to an embodiment of the present invention.
[0033] Figure 2 is a flowchart of calculating ArcFaceLoss loss according to an embodiment of the present invention.
[0034] Figure 3 is a flowchart of calculating CircleLoss loss according to an embodiment of the present invention.
[0035] Figure 4 4 is a flow chart of a method for training a fruit and vegetable recognition model according to another embodiment of the present invention. DETAILED DESCRIPTION
[0036] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for the description of the embodiments. Obviously, the drawings described below are only some examples or embodiments of the present application. For ordinary technicians in this field, the present application can also be applied to other similar scenarios based on these drawings without creative work. Unless it is obvious from the language environment or otherwise explained, the same reference numerals in the figures represent the same structure or operation.
[0037] The principle of the training method of the fruit and vegetable recognition model of the present application is to convert the fruit and vegetable recognition problem into a metric learning problem. Metric learning is a field in machine learning and deep learning, and its goal is to map data points to a new space by learning a mapping function, so that in this space, similar data points are closer, and dissimilar data points are farther away. The fruit and vegetable recognition model of the present application maps fruit and vegetable images to a feature space through metric learning, so that the distance between the features of fruit and vegetable images of the same category is closer, and the distance between the features of fruit and vegetable images of different categories is farther. Different fruits and vegetables are distinguished by learning the differences in feature vectors between different fruits and vegetables.
[0038] Figure 1 FIG. 1 is a flow chart of a method for training a fruit and vegetable recognition model according to an embodiment of the present invention. Figure 1 As shown, the training method 100 of the fruit and vegetable recognition model includes:
[0039] Step S1: Obtain a data set, which includes fruit and vegetable images and their corresponding labeled categories.
[0040] For example, the labeled categories of the data set include fruits and vegetables such as apples, bananas, tomatoes, and potatoes. The images labeled as apples include apple images from different perspectives, and the images labeled as tomatoes include tomato images from different perspectives.
[0041] Step S2: input the data set into the neural network model, and the neural network model extracts features of the fruit and vegetable images to obtain fruit and vegetable image features.
[0042] The neural network model is the basic model of the fruit and vegetable recognition model. The neural network model is used to extract features from fruit and vegetable images. The neural network model includes but is not limited to the classic VGG model and ResNet model of the Convolutional Neural Network (CNN). Taking the ResNet model as the basic model of the fruit and vegetable recognition model as an example, the apple image is input into the ResNet model to obtain the apple feature, and the banana image is input into the ResNet model to obtain the banana feature.
[0043] Step S3: Calculate ArcFaceLoss loss and CircleLoss loss respectively according to the fruit and vegetable image features and labeled categories.
[0044] Additive Angular Margin Loss (ArcFaceLoss loss for short) is a loss function commonly used in face recognition tasks. ArcFaceLoss loss directly maximizes the classification boundary in the angle space θ.
[0045] Figure 2 is a flowchart of calculating ArcFaceLoss loss according to an embodiment of the present invention. Figure 2 As shown in the figure, the ArcFaceLoss loss is calculated based on the fruit and vegetable image features and labeled categories:
[0046] Step S311: obtaining a category center vector corresponding to the marked category, recorded as a first category center vector, and calculating a first angle according to the fruit and vegetable image features and the first category center vector.
[0047] For each category, a category center vector is maintained. For example, for apples, an apple center vector is maintained, and for bananas, a banana center vector is maintained. Assuming that the input to the neural network model is an apple image, the angle between the extracted apple feature and the apple center vector is calculated and recorded as the first angle
[0048] Step S312: obtaining the category center vectors of other categories other than the marked category, recorded as the second category center vector, and calculating the second angle according to the fruit and vegetable image features and the second category center vector.
[0049] Continuing with the apple feature as an example, calculate the angle between the apple feature and the center vector of other categories. For example, calculate the angle between the apple feature and the center vector of the banana, the angle between the apple feature and the center vector of the tomato, etc., and record it as the second angle θ j .
[0050] Step S313: Calculate ArcFaceLoss loss according to the first angle and the second angle.
[0051] Optionally, the ArcFaceLoss loss is calculated by the following formula:
[0052]
[0053] Among them, L arcface is the ArcFaceLoss loss, is the first angle, θ j is the second angle, s and m are both hyperparameters, representing the strictness of similar features, and N is the total category of fruits and vegetables.
[0054] Represents the angle between the feature vector of the current sample and the category center vector of the sample label, θ jRepresents the angle between the current sample and the center vector of other categories. According to the characteristics of the cosine function, the closer the angle is to 0 (the more similar), cosθ approaches 1, so the loss is smaller, and vice versa. In short, the smaller the ArcFaceLoss loss of the same category of fruit and vegetable image features, the greater the ArcFaceLoss loss of different categories of fruit and vegetable image features.
[0055] s and m represent the strictness of similar features. The larger the value, the stricter it is. However, the larger the value, the more likely it is that the training will not converge. Therefore, in this example, the value range of s is 30-40; the value range of m is 0.1-0.3.
[0056] CircleLoss loss is a new loss function whose core idea is to improve traditional binary and multi-category classification tasks by constructing a circular decision boundary with distance penalty. Compared with the traditional cross entropy loss, CircleLoss loss can better handle the problem of category imbalance, making the model more advantageous in distinguishing similar categories.
[0057] Figure 3 FIG. 1 is a flowchart of calculating CircleLoss loss according to an embodiment of the present invention. Figure 3 As shown in the figure, the CircleLoss loss is calculated based on the fruit and vegetable image features and labeled categories:
[0058] Step S321: Calculate the first Euclidean distance between the fruit and vegetable image features and the features of the same category as the labeled category.
[0059] Each time, three samples are selected, namely A, P and N, where the sample labels of A and P are the same class, and the labels of N are different from A and P. For example, A is a random apple picture, P is another random apple picture, and N is a random banana picture. Calculate distance(A,P). For CircleLoss loss, distance represents the distance calculation function. In this example, Euclidean distance is used to calculate the Euclidean distance between the features of different apple images as the first Euclidean distance.
[0060] Step S322: Calculate the second Euclidean distance between the features of the fruit and vegetable image and the features of different marked categories.
[0061] Calculate distance(A,N), where distance represents the distance calculation function. In this example, the Euclidean distance is used. The labels of A and N are different. For example, the Euclidean distance between the features of the apple image and the banana image is calculated as the second Euclidean distance.
[0062] Step S323: Calculate the CircleLoss loss according to the first Euclidean distance and the second Euclidean distance.
[0063] Optionally, the CircleLoss loss is calculated using the following formula:
[0064] L circle =max(distance(A,P)-distance(A,N)+margin,0)
[0065] Among them, L circle is the CircleLoss loss, distance(A, P) is the first Euclidean distance, distance(A, N) is the second Euclidean distance, A and P are in the same category, A and N are in different categories, and margin represents the degree of strictness.
[0066] In this embodiment, margin is set to 0.2. CircleLoss hopes that the distance between A and P is as small as possible, and the distance between A and N is as large as possible.
[0067] Step S4: Combine ArcFaceLoss loss and CircleLoss loss to get the first stage mixed loss.
[0068] ArcFaceLoss loss and CircleLoss loss have their own characteristics. ArcFaceLoss needs to construct a category center vector and calculate the distance between different samples and category centers, hoping that samples are more likely to be close to their respective category centers. In the task of fruit and vegetable recognition, ArcFaceLoss may cause convergence difficulties. CircleLoss is calculated based on the relationship between samples, and has smaller constraints on features than ArcFaceLoss. As long as the distance conditions are met, the loss can be reduced, so it is easy to converge, but the effect is affected by the sample sampling method. Therefore. In this application, these two loss functions are combined, and the combined loss function is called the first-stage hybrid loss.
[0069] Optionally, the first stage mixing loss is obtained using the following formula:
[0070] L total1 =α·L arcface +L circle
[0071] Among them, L total1 is the first stage mixing loss, L arcface is the ArcFaceLoss loss, L circle is the CircleLoss loss, α is the first weight coefficient and its value range is 0 to 1.
[0072] In the early stage of training, the first stage mixed loss is mainly CircleLoss, which is easy to converge, and the features of the same sample have a certain gathering effect. As the training progresses, the weight of ArcFaceLoss gradually increases, and the features of the same sample have an obvious gathering effect. In other words, as the number of training rounds increases, the first weight coefficient α increases from 0 to 1.
[0073] Optionally, the first weight coefficient α is calculated by the following formula:
[0074]
[0075] Among them, n cur is the current training round number, n total is the total number of training rounds.
[0076] Step S5: Minimize the first stage mixed loss and update the hyperparameters of the neural network model to obtain the trained first fruit and vegetable recognition model
[0077] The training method of the fruit and vegetable recognition model of the present invention adopts the first-stage mixed loss, which can improve the recognition effect of the model under different categories and enable the model to have the ability of zero-sample learning. Even if the corresponding category has not been seen, it can still be distinguished by features.
[0078] In some embodiments, in order to further improve the recognition effect of the model in the case of plastic bags and close categories (such as various apples), during data processing, this part of the data is labeled with large category labels, such as bagged, unbagged, and all kinds of apples are labeled as apples. In each round of training data sampling, according to the number of training rounds, random sampling is performed at the beginning, and then different categories are sampled according to the large category labels, so that the model pays more attention to the differentiated features within the large category. Specifically, taking the apple and banana categories as an example, when sampling data, A selects a random apple picture, P is other random apple pictures, and N is a random banana picture. When the data sampling rule takes effect, A selects unbagged apples, P is bagged apples, and N is bananas. After the above training, the fruit and vegetable recognition model of the present application can, on the one hand, identify the categories of fruits and vegetables packed in plastic bags, and avoid the influence of plastic bags on the classification of fruits and vegetables. On the other hand, it can improve the recognition effect under different categories of the same large category. For example, in addition to being able to identify apple pictures as apples, it can also be further identified as ordinary apples, red apples, Cannes apples and other small categories.
[0079] The first fruit and vegetable recognition model is a model with large amount of calculation and parameters. Due to the limited computing power of terminal devices (such as supermarket electronic scales), if the first fruit and vegetable recognition model is directly deployed on the terminal device, it may not be applicable. In response to the above problems, this application proposes to first train a large model and then use the large model to perform feature distillation on the small model, and deploy the small model on the terminal device, which improves the recognition ability of the fruit and vegetable recognition model without increasing the computing power.
[0080] Figure 4 FIG. 1 is a flow chart of a method for training a fruit and vegetable recognition model according to another embodiment of the present invention. Figure 4 As shown, compared with the training method 100 for the fruit and vegetable recognition model, the training method 200 for the fruit and vegetable recognition model further includes:
[0081] Step S6: Based on knowledge distillation, the recognition capability of the first fruit and vegetable recognition model is transferred to obtain a second fruit and vegetable recognition model.
[0082] Knowledge distillation is a method of model compression. Different from pruning and quantization in model compression, knowledge distillation is to build a lightweight small model and use the supervision information of a large model with better performance to train the small model in order to achieve better performance and accuracy. The large model is called Teacher and the small model is called Student. The supervision information output from the Teacher model is called knowledge, and the process of Student learning to transfer the supervision information from the Teacher is called Distillation.
[0083] The process of knowledge distillation is divided into two stages: training the Teacher model (training the first fruit and vegetable recognition model) and training the Student model (training the second fruit and vegetable recognition model).
[0084] Step S7: The second stage mixed loss is used to train the second fruit and vegetable recognition model to obtain a trained second fruit and vegetable recognition model, wherein the parameter amount of the second fruit and vegetable recognition model is smaller than that of the first fruit and vegetable recognition model.
[0085] The present application introduces additional feature distillation loss when training the second fruit and vegetable recognition model. Specifically, the second fruit and vegetable recognition model is trained using the second stage mixed loss. Optionally, the second stage mixed loss includes ArcFaceLoss loss, CircleLoss loss and feature distillation loss.
[0086] Optionally, the second stage mixing loss is:
[0087] L total2 =α·Larcface +L circle +βL distill
[0088] Among them, L total2 is the second stage mixing loss, L arcface is the ArcFaceLoss loss, L circle is the CircleLoss loss, α is the first weight coefficient and its value range is 0 to 1, and β is the second weight coefficient. Optionally, in this embodiment, β has a value range of 10 to 30.
[0089] Optionally, the characteristic distillation loss is calculated by the following formula:
[0090] L distill =1-cos(F teacher , F student )
[0091] Among them, L distill is the characteristic distillation loss, F teacher is the feature output by the first fruit and vegetable recognition model, F student It is the feature output by the second fruit and vegetable recognition model.
[0092] Then, the second-stage mixed loss is minimized, and the hyperparameters of the second fruit and vegetable recognition model are updated by backpropagation to obtain the trained second fruit and vegetable recognition model.
[0093] The training method of the fruit and vegetable recognition model of this embodiment proposes to first train a large model and then use the large model to perform feature distillation on a small model. When training the small model, an additional feature distillation loss is introduced to improve the recognition effect of the small model. Compared with not adding model distillation, the recognition rate of the small model can be improved by 5%-10%.
[0094] Flowcharts are used in the present application to illustrate the operations performed by the system according to the embodiments of the present application. It should be understood that the preceding or following operations are not necessarily performed accurately in order. On the contrary, various steps may be processed in reverse order or simultaneously. At the same time, other operations may be added to these processes, or one or more operations may be removed from these processes.
[0095] As shown in this application, unless the context clearly indicates an exception, the words "a", "an", "a kind" and / or "the" do not refer to the singular, but also include the plural. Generally speaking, the terms "include" and "comprise" only indicate the inclusion of the steps and elements that have been clearly identified, and these steps and elements do not constitute an exclusive list. The method or device may also include other steps or elements.
[0096] Unless otherwise specifically stated, the relative arrangement, numerical expressions and numerical values of the parts and steps set forth in these embodiments do not limit the scope of the application. Meanwhile, it should be understood that, for ease of description, the sizes of the various parts shown in the accompanying drawings are not drawn according to actual proportional relationships. The technology, methods and equipment known to those of ordinary skill in the relevant art may not be discussed in detail, but in appropriate cases, the technology, methods and equipment should be considered as a part of the specification. In all examples shown and discussed here, any specific value should be interpreted as being merely exemplary, rather than as a limitation. Therefore, other examples of exemplary embodiments may have different values. It should be noted that similar reference numerals and letters represent similar items in the following drawings, and therefore, once a certain item is defined in an accompanying drawing, it does not need to be further discussed in subsequent drawings.
[0097] In addition, it should be noted that the use of words such as "first" and "second" to define components is only for the convenience of distinguishing the corresponding components. If not otherwise stated, the above words have no special meaning and cannot be understood as limiting the scope of protection of this application. In addition, although the terms used in this application are selected from well-known and commonly used terms, some terms mentioned in the specification of this application may be selected by the applicant at his or her discretion, and their detailed meanings are explained in the relevant parts of the description of this article. In addition, it is required to understand this application not only by the actual terms used, but also by the meaning implied by each term.
[0098] The basic concepts have been described above. Obviously, for those skilled in the art, the above invention disclosure is only used as an example and does not constitute a limitation of the present application. Although not explicitly stated herein, those skilled in the art may make various modifications, improvements and amendments to the present application. Such modifications, improvements and amendments are suggested in the present application, so such modifications, improvements and amendments still belong to the spirit and scope of the exemplary embodiments of the present application.
[0099] At the same time, the present application uses specific words to describe the embodiments of the present application. For example, "one embodiment", "an embodiment", and / or "some embodiments" refer to a certain feature, structure or characteristic related to at least one embodiment of the present application. Therefore, it should be emphasized and noted that "one embodiment" or "an embodiment" or "an alternative embodiment" mentioned twice or more in different positions in this specification does not necessarily refer to the same embodiment. In addition, some features, structures or characteristics in one or more embodiments of the present application can be appropriately combined.
[0100] Some aspects of the present application may be performed entirely by hardware, entirely by software (including firmware, resident software, microcode, etc.), or by a combination of hardware and software. The above hardware or software may be referred to as "data blocks", "modules", "engines", "units", "components" or "systems". The processor may be one or more application specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DAPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), processors, controllers, microcontrollers, microprocessors, or combinations thereof. In addition, various aspects of the present application may be expressed as computer products located in one or more computer-readable media, which include computer-readable program codes. For example, computer-readable media may include, but are not limited to, magnetic storage devices (e.g., hard disks, floppy disks, tapes ...), optical disks (e.g., compact disks CDs, digital versatile disks DVDs ...), smart cards, and flash memory devices (e.g., cards, sticks, key drives ...).
[0101] A computer-readable medium may include a propagated data signal containing computer program code, such as in baseband or as part of a carrier wave. The propagated signal may have a variety of manifestations, including electromagnetic, optical, etc., or a suitable combination. A computer-readable medium may be any computer-readable medium other than a computer-readable storage medium, which may be connected to an instruction execution system, device or apparatus to communicate, propagate or transmit a program for use. The program code on the computer-readable medium may be propagated via any suitable medium, including radio, cable, fiber optic cable, radio frequency signal, or similar medium, or any combination of the above mediums.
[0102] Similarly, it should be noted that in order to simplify the description of the disclosure of this application and thus help understand one or more embodiments of the invention, in the above description of the embodiments of the present application, multiple features are sometimes combined into one embodiment, figure or description thereof. However, this disclosure method does not mean that the subject of the present application requires more features than the features mentioned. In fact, the features of the embodiment are less than all the features of the single embodiment disclosed above.
[0103] In some embodiments, numbers describing the number of components and attributes are used. It should be understood that such numbers used in the description of the embodiments are modified by the modifiers "about", "approximately" or "substantially" in some examples. Unless otherwise specified, "about", "approximately" or "substantially" indicate that the numbers are allowed to vary by ±20%. Accordingly, in some embodiments, the numerical parameters used in the specification are approximate values, which may change according to the required features of individual embodiments. In some embodiments, the numerical parameters should take into account the specified significant digits and adopt the general method of retaining the digits. Although the numerical domains and parameters used to confirm the breadth of the range in some embodiments of the present application are approximate values, in specific embodiments, the setting of such numerical values is as accurate as possible within the feasible range.
[0104] Although the present application has been described with reference to the current specific embodiments, ordinary technicians in this technical field should recognize that the above embodiments are only used to illustrate the present application, and various equivalent changes or substitutions may be made without departing from the spirit of the present application. Therefore, as long as the changes and modifications to the above embodiments are within the essential spirit of the present application, they will fall within the scope of the present application.
Claims
1. A training method for a fruit and vegetable recognition model, characterized in that: include: Acquire a data set, the data set including fruit and vegetable images and their corresponding labeled categories; The data set is input into a neural network model, and the neural network model extracts features of the fruit and vegetable images to obtain features of the fruit and vegetable images; Calculating ArcFaceLoss loss and CircleLoss loss respectively according to the fruit and vegetable image features and the labeled categories; The ArcFaceLoss loss and CircleLoss loss are combined to obtain the first stage mixed loss; The first stage mixed loss is minimized and the hyperparameters of the neural network model are updated to obtain a trained first fruit and vegetable recognition model.
2. The method for training a fruit and vegetable recognition model according to claim 1, characterized in that: Calculating the ArcFaceLoss loss according to the fruit and vegetable image features and the labeled categories includes: Obtaining a category center vector corresponding to the marked category, recorded as a first category center vector, and calculating a first angle according to the fruit and vegetable image features and the first category center vector; Obtaining a category center vector of another category other than the marked category, recorded as a second category center vector, and calculating a second angle according to the fruit and vegetable image feature and the second category center vector; The ArcFaceLoss loss is calculated according to the first angle and the second angle.
3. The training method for the fruit and vegetable recognition model according to claim 2, characterized in that: The ArcFaceLoss loss is calculated by the following formula: Among them, L arcface is the ArcFaceLoss loss, θ yi is the first angle, θ j is the second angle, s and m are both hyperparameters, representing the strictness of similarity of similar features, and N is the total category of fruits and vegetables.
4. The method for training a fruit and vegetable recognition model according to claim 1, characterized in that: Calculating the CircleLoss loss according to the fruit and vegetable image features and the labeled categories includes: Calculating the first Euclidean distance between the fruit and vegetable image feature and the feature of the same category as the labeled category; Calculating the second Euclidean distance between the features of the fruit and vegetable image and the features of different categories of the labeled categories; The CircleLoss loss is calculated according to the first Euclidean distance and the second Euclidean distance.
5. The method for training a fruit and vegetable recognition model according to claim 4, characterized in that: The CircleLoss loss is calculated by the following formula: L circle =max(distance(A,P)-distance(A,N)+margin,0) Among them, L circle is the CircleLoss loss, distance(A, P) is the first Euclidean distance, distance(A, N) is the second Euclidean distance, A and P are of the same category, A and N are of different categories, and margin represents the degree of strictness.
6. The training method for a fruit and vegetable recognition model according to claim 1, characterized in that: The first stage mixing loss is: L total1 =α·L arcface +L circle Among them, L total1 is the first stage mixing loss, L arcface is the ArcFaceLoss loss, L circle is the CircleLoss loss, α is the first weight coefficient and its value range is 0 to 1.
7. The method for training a fruit and vegetable recognition model according to claim 6, characterized in that: As the number of training rounds increases, the first weight coefficient α increases from 0 to 1.
8. The method for training a fruit and vegetable recognition model according to claim 6, characterized in that: The first weight coefficient α is calculated by the following formula: Among them, n cur is the current training round number, n total is the total number of training rounds.
9. The method for training a fruit and vegetable recognition model according to claim 1, characterized in that: Also includes: Based on knowledge distillation, the recognition capability of the first fruit and vegetable recognition model is transferred to obtain a second fruit and vegetable recognition model; The second fruit and vegetable recognition model is trained by using the second stage mixed loss to obtain a trained second fruit and vegetable recognition model, wherein the parameter amount of the second fruit and vegetable recognition model is smaller than that of the first fruit and vegetable recognition model.
10. The method for training a fruit and vegetable recognition model according to claim 9, characterized in that: The second stage mixed loss includes ArcFaceLoss loss, CircleLoss loss and feature distillation loss.
11. The method for training a fruit and vegetable recognition model according to claim 10, characterized in that: The characteristic distillation loss is calculated by the following formula: L distill =1-cos(F teacher ,F student ) Among them, L distill is the characteristic distillation loss, F teacher is the feature output by the first fruit and vegetable recognition model, F student It is the feature output by the second fruit and vegetable recognition model.
12. The method for training a fruit and vegetable recognition model according to claim 10, characterized in that: The second stage mixing loss is: L total2 =α·L arcface +L circle +βL distill Among them, L total2 is the second stage mixing loss, L arcface is the ArcFaceLoss loss, L circle is the CircleLoss loss, α is the first weight coefficient and its value range is 0 to 1, and β is the second weight coefficient.
13. A fruit and vegetable recognition model for classifying vegetables or fruits, characterized in that: The fruit and vegetable recognition model is obtained by training using the fruit and vegetable recognition model training method according to any one of claims 1 to 12.