Model training method, device, storage medium and electronic device
By combining the training data of target detection and classification images, and using the loss function and backpropagation mechanism of the deep neural network, the problem of insufficient accuracy in image category prediction of the deep neural network is solved, and more accurate image recognition and category object locations are achieved. Identify.
Patent Information
- Application Number
- CN201980100619.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-11-08
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2039-11-08
AI Technical Summary
In the existing technology, the accuracy of deep neural networks is insufficient in image category prediction. Especially when processing images containing multi-category labels, it is difficult to accurately identify the location and characteristics of category objects.
By combining the sample image collection of target detection images and classification images, deep neural networks are used for training, and the position information and category labels carried by the target detection images are used to jointly calculate the loss value and perform backpropagation, and update the network parameters to improve image recognition. The accuracy of the model.
The image recognition model improves the accuracy of image category prediction, can more accurately identify the location and characteristics of category objects in images, and enhances the ability to recognize multi-category images.
Smart Images

Figure CN114424253B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a model training method, device, storage medium and electronic device. Background Art
[0002] Image processing is a technology that uses computers to analyze images to achieve the desired results. In the field of image processing technology, image category prediction has become an important research topic. With the advancement of research on neural network models, the method of predicting the category of images through models to obtain the predicted category of images has gradually been widely recognized. Therefore, it is particularly important to improve the accuracy of subsequent image category prediction through model training. Summary of the invention
[0003] The embodiments of the present application provide a model training method, device, storage medium and electronic device, which can improve the accuracy of deep neural network prediction of image category.
[0004] In a first aspect, an embodiment of the present application provides a model training method, comprising:
[0005] Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0006] Inputting the sample images in the sample image set into a preset deep neural network for training;
[0007] If the sample image input into the deep neural network is the classified image, calculating the loss value based on the first loss function;
[0008] If the sample image input into the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function;
[0009] Back propagation is performed based on the calculated loss value to update the network parameters until convergence, and an image recognition model is obtained, which is used to identify the category of the input image and the location of the category object.
[0010] In a second aspect, an embodiment of the present application provides a model training device, comprising:
[0011] An image acquisition module, used to acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0012] An image input module, used for inputting sample images in the sample image set into a preset deep neural network for training;
[0013] A first calculation module, configured to calculate a loss value based on a first loss function if the sample image input into the deep neural network is the classified image;
[0014] A second calculation module, configured to calculate a loss value based on the first loss function and a second loss function if the sample image input into the deep neural network is the target detection image;
[0015] An iterative training module is used to perform back propagation based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
[0016] In a third aspect, an embodiment of the present application provides a storage medium having a computer program stored thereon, and when the computer program is run on a computer, the computer is caused to execute:
[0017] Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0018] Inputting the sample images in the sample image set into a preset deep neural network for training;
[0019] If the sample image input into the deep neural network is the classified image, calculating the loss value based on the first loss function;
[0020] If the sample image input into the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function;
[0021] Back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
[0022] In a fourth aspect, an embodiment of the present application provides an electronic device, including a processor and a memory, wherein the memory has a computer program, and the processor calls the computer program to execute:
[0023] Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0024] Inputting the sample images in the sample image set into a preset deep neural network for training;
[0025] If the sample image input into the deep neural network is the classified image, calculating the loss value based on the first loss function;
[0026] If the sample image input to the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function;
[0027] Back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
[0028] The solution provided by the embodiment of the present application is to obtain a sample image set including target detection images and classification images when training a deep neural network, and use the sample images in the sample image set to train a preset deep neural network for training. During the training process, when the sample image input to the deep neural network is a classification image, the loss value is calculated based on the first loss function, and when the sample image input to the deep neural network is a target detection image, the loss value is calculated based on the first loss function and the second loss function, and back propagation is performed based on the loss value to update the network parameters until convergence. In the above training scheme, the preset deep neural network is trained with the target detection image and the classification image. Since the target detection image carries the position information and the first category label, the position information indicates the specific position of the category object in the image, so that in the process of training the network, the network can more accurately extract the features of the category object, thereby improving the accuracy of the image recognition model obtained by the image recognition model training for image category prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0030] Figure 1 A first flow chart of the model training method provided in an embodiment of the present application.
[0031] Figure 2 A second flow chart of the model training method provided in an embodiment of the present application.
[0032] Figure 3 A schematic diagram of the structure of a model training device provided in an embodiment of the present application.
[0033] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0034] Figure 5 A schematic diagram of the structure of a model training circuit for an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0036] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0037] The present application embodiment provides a model training method, including:
[0038] Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0039] Inputting the sample images in the sample image set into a preset deep neural network for training;
[0040] If the sample image input into the deep neural network is the classified image, calculating the loss value based on the first loss function;
[0041] If the sample image input to the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function;
[0042] Back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
[0043] In some embodiments, the classification image carries a second category label, the target detection image carries position information and a first category label, and the first category labels carried by all target detection images constitute a first category label set;
[0044] Before calculating the loss value based on the first loss function, the method further includes:
[0045] If the sample image input into the deep neural network is the classified image, determining whether the second category label corresponding to the input classified image is included in the first category label set;
[0046] If yes, then calculating the loss value based on the first loss function;
[0047] If not, the loss value is calculated based on a third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function.
[0048] In some embodiments, the third loss function=k*first loss function, where k>1.
[0049] In some embodiments, the first loss function is m*f, and the third loss function is n*f, wherein f is a basic loss function, 0<m<1, n>1.
[0050] In some embodiments, the deep neural network is a convolutional neural network; the second category labels carried by all classified images constitute a second category label set, and the number of label types in the first category label set is less than the number of label types in the second category label set.
[0051] In some embodiments, the deep neural network is a convolutional neural network; the second category labels carried by all classified images constitute a second category label set, and the number of label types in the first category label set is less than the number of label types in the second category label set.
[0052] In some embodiments, the back propagation based on the calculated loss value to update the network parameters until convergence further includes:
[0053] Get the image to be classified;
[0054] Image recognition is performed on the image to be classified according to the image recognition model to determine the target category corresponding to the image to be classified and the position of the object belonging to the target category in the image to be classified.
[0055] The embodiment of the present application provides a model training method, and the execution subject of the model training method can be the model training device provided in the embodiment of the present application, or an electronic device integrating the model training device, wherein the model training device can be implemented in hardware or software. Among them, the electronic device can be a smart phone, a tablet computer, a PDA, a laptop computer, or a desktop computer.
[0056] Please refer to Figure 1 , Figure 1 This is a schematic diagram of the first process of the model training method provided in the embodiment of the present application. The specific process of the model training method provided in the embodiment of the present application can be as follows:
[0057] In 101, a sample image set is obtained, where the sample image set includes target detection images and classification images, wherein the target detection images carry position information and a first category label.
[0058] Image multi-classification based on target detection is strongly supervised and requires the location information of each category in the image. However, when the training sample size of such a classification model is large, labeling the location information is a huge labor cost. General image multi-classification is a weakly supervised image classification method. This classification method only needs to label the category name of the image, but this classification method cannot identify the location of the category in the image.
[0059] The model training scheme of the embodiment of the present application can be applied to an image classification and positioning model, which can not only identify the category of the image, but also identify the location of the category object in the image. For example, the location of the category object can be marked by a target box. Among them, the model can be constructed based on a deep neural network, for example, a BP (back propagation) neural network, a convolutional neural network, etc.
[0060] The present application adopts a mixture of two training samples to form a sample image set, wherein the two sample images include a target detection image and a classification image, and the target detection image carries both a category label and position information, and the position information indicates the position of the category object in the image. The classification image carries a category label. For the convenience of the following description, the category label carried by the target detection image is recorded as the first category label, and the category label carried by the classification image is recorded as the second category label. The first category labels carried by all target detection images constitute a first category label set; the second category labels carried by all classification images constitute a second category label set. In some embodiments, the label categories in the second category label set may partially overlap with the category labels in the first category label set.
[0061] In 102, sample images in the sample image set are input into a preset deep neural network for training.
[0062] The sample image training model is constructed by mixing two types of training samples, which is essentially a joint training of strong supervision algorithm and direct classification. During the training process, sample images in the sample image set mixed with target detection images and classification images are randomly input into the preset neural network for calculation. Different loss functions are used to calculate the loss value according to the different types of input sample images.
[0063] In 103, if the sample image input to the deep neural network is a classification image, a loss value is calculated based on a first loss function.
[0064] In 104, if the sample image input to the deep neural network is a target detection image, the loss value is calculated based on the first loss function and the second loss function.
[0065] When using classified images to train the network, the loss function in the network is composed of the first loss function, which is used to calculate the loss value generated when the image is classified. Since there is no target box in the training data at this time, only the network parameters related to the classification training part will be updated during the back propagation of the error information, while the network parameters related to the target detection part will not be updated. Since the training data carries the target box at this time, the network parameters related to the classification training part and the network parameters related to the target detection part will be updated during the back propagation of the error information, that is, all network parameters will be updated.
[0066] When the network is trained using target detection images, the loss function in the network is composed of a first loss function and a second loss function. The second loss function is used to calculate the loss value generated when performing target detection on the image, and the first loss function is used to calculate the loss value generated when classifying the image.
[0067] Therefore, the training process of this deep neural network involves two loss functions. The total loss function can be expressed as L = L p +L cls , where L cls is the first loss function, L p is the second loss function. If the sample image input to the deep neural network is a classification image, then L p =0.
[0068] In this embodiment, the loss function can be selected according to the deep neural network used. For example, the mean square error function or the cross entropy function can be used as the loss function.
[0069] In 105, back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
[0070] During the training of the network, the loss value is calculated based on the above loss function and calculation method, and back propagation is performed based on the calculated loss value to update the network parameters until the network converges. For example, until the number of iterative training reaches a preset value, or until the loss value reaches a minimum, or until the loss value is less than a preset value. After training to convergence, the network parameters are determined, and the deep neural network after the network parameters are determined is used as an image number recognition model.
[0071] Among them, during the training process of the network, since the target detection image carries position information, the position information indicates the specific position of the category object in the image, so that during the training process of the network, the network can more accurately extract the characteristics of the category object. In this way, when the sample image input to the network is a classification image, even if the classification image does not carry position information, the network's ability to identify the characteristics of the category object is enhanced due to the training of the target detection image, and it can also more accurately identify the characteristics of the category object in the classification image and determine the location of the category object with higher accuracy. It can be understood that the category object in this application refers to the object corresponding to the category label corresponding to the sample image.
[0072] For example, taking the preset deep neural network as a convolutional neural network, the cross entropy function is used as the loss function, the training data is input, the loss value is calculated according to the loss function, and backpropagation is performed based on the loss value to optimize the weights in each convolution kernel in each convolution layer of the network.
[0073] In specific implementation, the present application is not limited by the execution order of the various steps described. If no conflict occurs, some steps can be performed in other orders or simultaneously.
[0074] As can be seen from the above, the model training method proposed in the embodiment of the present application, when training a deep neural network, obtains a sample image set including a target detection image and a classification image, and uses the sample images in the sample image set to train a preset deep neural network for training. During the training process, when the sample image input to the deep neural network is a classification image, the loss value is calculated based on the first loss function, and when the sample image input to the deep neural network is a target detection image, the loss value is calculated based on the first loss function and the second loss function, and back propagation is performed based on the loss value to update the network parameters until convergence. In the above training scheme, the preset deep neural network is trained with the target detection image and the classification image. Since the target detection image carries position information and a first category label, the position information indicates the specific position of the category object in the image, so that in the process of training the network, the network can more accurately extract the features of the category object, thereby improving the accuracy of the image recognition model obtained by the image recognition model training for image category prediction.
[0075] The following will further describe the model training method of this application in detail based on the method described in the above embodiment. Figure 2 , Figure 2 : is a second flow chart of the model training method provided by an embodiment of the present invention. The method comprises:
[0076] In 201, a sample image set is obtained, wherein the sample image set includes target detection images and classification images, wherein the target detection images carry position information and first category labels, and the first category labels carried by all target detection images constitute a first category label set.
[0077] This embodiment uses a mixture of two training samples to form a sample image set, wherein the two sample images include a target detection image and a classification image, and the target detection image carries both a category label and position information, and the position information indicates the position of the category object in the image. The classification image carries a category label. For the convenience of the following description, the category label carried by the target detection image is recorded as the first category label, and the category label carried by the classification image is recorded as the second category label. The first category labels carried by all target detection images constitute a first category label set; the second category labels carried by all classification images constitute a second category label set. In some embodiments, the label categories in the second category label set may partially overlap with the category labels in the first category label set.
[0078] For example, the deep neural network is used for animal classification. The sample image is an animal image, in which the target detection image not only carries the category label of the animal, but also identifies the location of the category animal corresponding to the image in the form of a target frame in each image. However, the animal categories in the target detection image only have major animal categories, such as dogs, cats, deer, etc., but there is no finer category division, for example, dogs are not divided into golden retrievers, huskies, shepherd dogs, etc. At the same time, the classification image only carries the category label of the animal, and does not identify the specific location of the animal in the image, but the classification image has wider and deeper category labels. For example, the category of the classification image contains major categories that are not in the target detection image, for example, there is no elephant category in the target detection image, but there is this category in the classification image. The category of the classification image can also contain small categories that are not in the target detection image, for example, there are no small categories such as golden retrievers, huskies, shepherd dogs, etc. in the target detection image, but there are these categories in the classification image. That is to say, the number of category labels in the second category label set can be greater than the number of category labels in the first category label set.
[0079] Based on the solution of this embodiment, the above two sample images are mixed together as training samples, and the deep neural network is trained by joint training. The trained network can output highly accurate location information for small categories of dogs that have not appeared in the target detection image.
[0080] In 202, sample images in the sample image set are input into a preset deep neural network for training.
[0081] The sample image training model is constructed by mixing two types of training samples, which is essentially a joint training of strong supervision algorithm and direct classification. During the training process, sample images in the sample image set mixed with target detection images and classification images are randomly input into the preset neural network for calculation. Different loss functions are used to calculate the loss value according to the different types of input sample images.
[0082] In 203, if the sample image input to the deep neural network is a classified image, it is determined whether the second category label corresponding to the input classified image is included in the first category label set.
[0083] In 204 , if yes, a loss value is calculated based on the first loss function.
[0084] In 205 , if not, a loss value is calculated based on a third loss function, wherein when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function.
[0085] Based on the above example, although the deep neural network is trained by joint training, the trained network can output high-accuracy position information for small categories of dogs that have not appeared in the target detection image. However, during the training process, for large categories that appear in the classification image but are not in the target detection image, for example, the classification image contains elephant categories that are not in the target detection image, the accuracy of position detection will be poor. In this embodiment, a new loss value calculation method is used to solve this problem.
[0086] When the sample image input to the deep neural network is a classified image, first determine whether the second category label corresponding to the input classified image is included in the first category label set. If so, the loss value is calculated based on the first loss function. If not, the loss value is calculated based on the third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function. That is, when the category of the classified image contains a category that is not in the target detection image, in order to improve the accuracy of network target detection, at this time, a third loss function that is different from another situation (the situation where the category of the classified image is included in the category of the target detection image) is used to calculate the loss value, so that the calculated loss value is larger, making the network more sensitive to this category, and being able to more accurately learn the characteristics of this category of images, so as to optimize the model parameters, thereby improving the detection accuracy of categories and targets.
[0087] For example, in some implementations, the third loss function = k*first loss function, where k> 1. In this embodiment, a weight coefficient is multiplied by the formula of the first loss function to obtain the third loss function, and the weight coefficient is a constant greater than 1, for example, in some embodiments, k = 1 to 3; for another example, in some embodiments, k = 1 to 1.5; for another example, in some embodiments, k = 1.5 to 2.
[0088] For another example, in some embodiments, the first loss function is m*f, and the third loss function is n*f, where f is a basic loss function, 0<m<1, and n>1. For example, f is a cross entropy loss function, and the calculation formula of the first loss function is obtained by multiplying the calculation formula of the cross entropy loss function by a positive number less than 1, and the calculation formula of the second loss function is obtained by multiplying the calculation formula of the cross entropy loss function by a constant greater than 1.
[0089] In 206, if the sample image input to the deep neural network is a target detection image, a loss value is calculated based on the first loss function and the second loss function.
[0090] When the network is trained using target detection images, the loss function in the network is composed of a first loss function and a second loss function. The second loss function is used to calculate the loss value generated when performing target detection on the image, and the first loss function is used to calculate the loss value generated when classifying the image.
[0091] In 207, back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
[0092] In some embodiments, back propagation is performed based on the calculated loss value to update the network parameters until convergence, and the method also includes: obtaining an image to be classified; performing image recognition on the image to be classified according to the image recognition model to determine the target category corresponding to the image to be classified, and the position of the object belonging to the target category in the image to be classified.
[0093] In this embodiment, the trained image recognition model is used to identify the image category, and the image to be classified is input into the image recognition model for calculation to obtain the category label corresponding to the image to be classified and the position of the corresponding category object in the image.
[0094] From the above, it can be seen that the model training method proposed in the embodiment of the present invention, based on the joint training of classification data and target detection data, when the sample image input into the deep neural network is a classification image, if the category label corresponding to the classification image is not included in the category label of the target detection image, back propagation is performed with a larger loss value, thereby expanding the model's recognition ability for multiple categories and improving the accuracy of multiple classifications.
[0095] The present application also provides a model training device, including:
[0096] An image acquisition module, used to acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0097] An image input module, used for inputting sample images in the sample image set into a preset deep neural network for training;
[0098] A first calculation module, configured to calculate a loss value based on a first loss function if the sample image input into the deep neural network is the classified image;
[0099] A second calculation module, configured to calculate a loss value based on the first loss function and a second loss function if the sample image input into the deep neural network is the target detection image;
[0100] The iterative training module is used to perform back propagation based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, wherein the image recognition model is used to identify the category of the input image and the location of the category object.
[0101] In some embodiments, the classification image carries a second category label, and the first category labels carried by all target detection images constitute a first category label set; the apparatus further includes:
[0102] A label detection module, configured to determine whether a second category label corresponding to the input classification image is included in the first category label set if the sample image input into the deep neural network is the classification image;
[0103] The first calculation module is also used for:
[0104] If the second category label corresponding to the input classification image is included in the first category label set, calculating the loss value based on the first loss function;
[0105] If the second category label corresponding to the input classification image is not included in the first category label set, the loss value is calculated based on the third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function.
[0106] In some embodiments, the third loss function=k*first loss function, where k>1.
[0107] In some embodiments, the first loss function is m*f, and the third loss function is n*f, where f is a basic loss function, 0<m<1, n>1.
[0108] In some embodiments, the deep neural network is a convolutional neural network; the second category labels carried by all classified images constitute a second category label set, and the number of label types in the first category label set is less than the number of label types in the second category label set.
[0109] In some embodiments, the apparatus further comprises an image classification module, wherein the image classification module is configured to:
[0110] Get the image to be classified;
[0111] And, performing image recognition on the image to be classified according to the image recognition model to determine the target category corresponding to the image to be classified and the position of the object belonging to the target category in the image to be classified.
[0112] In one embodiment, a model training device is also provided. Figure 3 , Figure 3 A schematic diagram of the structure of a model training device 300 provided in an embodiment of the present application. The model training device 300 is applied to an electronic device, and the model training device 300 includes an image acquisition module 301, an image input module 302, a first calculation module 303, a second calculation module 304, and an iterative training module 305, as follows:
[0113] An image acquisition module 301 is used to acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0114] An image input module 302, used to input sample images in the sample image set into a preset deep neural network for training;
[0115] A first calculation module 303, configured to calculate a loss value based on a first loss function if the sample image input into the deep neural network is the classified image;
[0116] A second calculation module 304 is configured to calculate a loss value based on the first loss function and the second loss function if the sample image input to the deep neural network is the target detection image;
[0117] The iterative training module 305 is used to perform back propagation based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, wherein the image recognition model is used to recognize the category of the input image and the location of the category object.
[0118] In some embodiments, the classification image carries a second category label, the target detection image carries position information and a first category label, and the first category labels carried by all target detection images constitute a first category label set;
[0119] The model training device 300 also includes a label detection module, which is used to determine whether the second category label corresponding to the input classification image is included in the first category label set if the sample image input to the deep neural network is the classification image;
[0120] The first calculation module 303 is further used to: if the second category label corresponding to the input classification image is included in the first category label set, calculate the loss value based on the first loss function;
[0121] Furthermore, if the second category label corresponding to the input classified image is not included in the first category label set, the loss value is calculated based on the third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function.
[0122] In some embodiments, the third loss function=k*first loss function, where k>1.
[0123] In some embodiments, the first loss function is m*f, and the third loss function is n*f, wherein f is a basic loss function, 0<m<1, n>1.
[0124] In some embodiments, the deep neural network is a convolutional neural network; the second category labels carried by all classified images constitute a second category label set, and the number of label types in the first category label set is less than the number of label types in the second category label set.
[0125] In some embodiments, the model training device 300 also includes an image classification module, which is used to: obtain an image to be classified; perform image recognition on the image to be classified according to the image recognition model to determine the target category corresponding to the image to be classified, and the position of the object belonging to the target category in the image to be classified.
[0126] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above modules can be found in the previous method embodiments, which will not be repeated here.
[0127] It should be noted that the model training device provided in the embodiment of the present application belongs to the same concept as the model training method in the above embodiment. Any method provided in the model training method embodiment can be run on the model training device. The specific implementation process is detailed in the model training method embodiment and will not be repeated here.
[0128] As can be seen from the above, the model training device proposed in the embodiment of the present application obtains a sample image set including target detection images and classification images when training a deep neural network, and uses the sample images in the sample image set to train a preset deep neural network for training. During the training process, when the sample image input to the deep neural network is a classification image, the loss value is calculated based on the first loss function, and when the sample image input to the deep neural network is a target detection image, the loss value is calculated based on the first loss function and the second loss function, and back propagation is performed based on the loss value to update the network parameters until convergence. In the above training scheme, the preset deep neural network is trained with the target detection image and the classification image. Since the target detection image carries position information and a first category label, the position information indicates the specific position of the category object in the image, so that in the process of training the network, the network can more accurately extract the characteristics of the category object, thereby improving the accuracy of the image recognition model obtained by the image recognition model training for image category prediction.
[0129] The present application also provides an electronic device, which may be a mobile terminal such as a tablet computer or a smart phone. Figure 4 , Figure 4 The electronic device 800 may include a camera module 801, a memory 802, a processor 803, a touch screen 804, a speaker 805, a microphone 806 and other components.
[0130] The camera module 801 may include a model training circuit, which may be implemented using hardware and / or software components, and may include various processing units that define an image signal processing pipeline. The model training circuit may include at least: a camera, an image signal processor (ISP processor), a control logic, an image memory, and a display, etc. The camera may include at least one or more lenses and an image sensor. The image sensor may include a color filter array (such as a Bayer filter). The image sensor may obtain light intensity and wavelength information captured by each imaging pixel of the image sensor, and provide a set of raw image data that can be processed by an image signal processor.
[0131] The image signal processor can process the raw image data pixel by pixel in a variety of formats. For example, each image pixel can have a bit depth of 8, 10, 12 or 14 bits, and the image signal processor can perform one or more model training operations on the raw image data and collect statistical information about the image data. Among them, the model training operation can be performed with the same or different bit depth accuracy. The raw image data can be stored in the image memory after being processed by the image signal processor. The image signal processor can also receive image data from the image memory.
[0132] The image memory may be a part of a memory device, a storage device, or an independent dedicated memory within the electronic device, and may include a DMA (Direct Memory Access) feature.
[0133] When receiving image data from the image memory, the image signal processor may perform one or more model training operations, such as time domain filtering. The processed image data may be sent to the image memory for additional processing before being displayed. The image signal processor may also receive processed data from the image memory and process the processed data in the original domain and in the RGB and YCbCr color spaces. The processed image data may be output to a display for viewing by a user and / or further processed by a graphics engine or GPU (Graphics Processing Unit). In addition, the output of the image signal processor may also be sent to the image memory, and the display may read the image data from the image memory. In one embodiment, the image memory may be configured to implement one or more frame buffers.
[0134] The statistical data determined by the image signal processor can be sent to the control logic. For example, the statistical data can include statistical information of the image sensor such as automatic exposure, automatic white balance, automatic focus, flicker detection, black level compensation, lens shading correction, etc.
[0135] The control logic may include a processor and / or microcontroller that executes one or more routines (e.g., firmware). The one or more routines may determine control parameters of the camera and ISP control parameters based on the received statistical data. For example, the control parameters of the camera may include camera flash control parameters, lens control parameters (e.g., focal length for focus or zoom), or a combination of these parameters. The ISP control parameters may include gain levels and color correction matrices for automatic white balance and color adjustment (e.g., during RGB processing), etc.
[0136] See also Figure 5 , Figure 5 Schematic diagram of the structure of the model training circuit in this embodiment. For ease of description, only various aspects of the model training technology related to the embodiment of the present invention are shown.
[0137] For example, the model training circuit may include: a camera, an image signal processor, a control logic, an image memory, and a display. The camera may include one or more lenses and an image sensor. In some embodiments, the camera may be a telephoto camera or a wide-angle camera.
[0138] The image captured by the camera is transmitted to the image signal processor for processing. After the image signal processor processes the image, the statistical data of the image (such as the brightness of the image, the contrast value of the image, the color of the image, etc.) can be sent to the control logic. The control logic can determine the control parameters of the camera based on the statistical data, so that the camera can perform operations such as autofocus and auto exposure according to the control parameters. After the image is processed by the image signal processor, the image can be stored in the image memory. The image signal processor can also read the image stored in the image memory for processing. In addition, after the image is processed by the image signal processor, it can be directly sent to the display for display. The display can also read the image in the image memory for display.
[0139] In addition, the electronic device may further include a CPU and a power supply module, which are not shown in the figure. The CPU is connected to the logic controller, the image signal processor, the image memory and the display, and the CPU is used to achieve global control. The power supply module is used to supply power to each module.
[0140] The application programs stored in the memory 802 include executable codes. The application programs may be composed of various functional modules. The processor 803 executes various functional applications and data processing by running the application programs stored in the memory 802.
[0141] The processor 803 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or executing applications stored in the memory 802 and calling data stored in the memory 802, thereby monitoring the electronic device as a whole.
[0142] The touch display screen 804 can be used to receive a user's touch control operation on the electronic device. The speaker 805 can play sound signals. The microphone 806 can be used to pick up sound signals.
[0143] In this embodiment, the processor 803 in the electronic device will load the executable code corresponding to the process of one or more application programs into the memory 802 according to the following instructions, and the processor 803 will run the application program stored in the memory 802 to execute:
[0144] Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label;
[0145] Inputting the sample images in the sample image set into a preset deep neural network for training;
[0146] If the sample image input into the deep neural network is the classified image, calculating the loss value based on the first loss function;
[0147] If the sample image input into the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function;
[0148] Back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
[0149] In some embodiments, the classification image carries a second category label, the target detection image carries position information and a first category label, and the first category labels carried by all target detection images constitute a first category label set; the processor 803 further executes:
[0150] If the sample image input into the deep neural network is the classified image, determining whether the second category label corresponding to the input classified image is included in the first category label set;
[0151] If yes, then calculating the loss value based on the first loss function;
[0152] If not, the loss value is calculated based on a third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function.
[0153] In some embodiments, the processor 803 further executes:
[0154] Acquire an image to be classified; and perform image recognition on the image to be classified according to the image recognition model to determine a target category corresponding to the image to be classified and a position of an object belonging to the target category in the image to be classified.
[0155] As can be seen from the above, an embodiment of the present application provides an electronic device, which, when training a deep neural network, obtains a sample image set including a target detection image and a classification image, and uses the sample images in the sample image set to train a preset deep neural network for training. During the training process, when the sample image input to the deep neural network is a classification image, a loss value is calculated based on a first loss function, and when the sample image input to the deep neural network is a target detection image, a loss value is calculated based on the first loss function and the second loss function, and back propagation is performed based on the loss value to update the network parameters until convergence. In the above training scheme, the preset deep neural network is trained with the target detection image and the classification image. Since the target detection image carries position information and a first category label, the position information indicates the specific position of the category object in the image, so that during the network training process, the network can more accurately extract the features of the category object, thereby improving the accuracy of the image recognition model obtained by training the image recognition model for image category prediction.
[0156] An embodiment of the present application further provides a storage medium, in which a computer program is stored. When the computer program runs on a computer, the computer executes the model training method described in any of the above embodiments.
[0157] It should be noted that, a person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the storage medium can include but is not limited to: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0158] In addition, the terms "first", "second", and "third" in this application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or device that includes a series of steps or modules is not limited to the listed steps or modules, but some embodiments also include steps or modules that are not listed, or some embodiments also include other steps or modules inherent to these processes, methods, products, or devices.
[0159] The above is a detailed introduction to the model training method, device, storage medium and electronic device provided in the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A model training method, characterized in that: include: Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label, the first category labels carried by all target detection images constitute a first category label set, and the classification image carries a second category label; Inputting the sample images in the sample image set into a preset deep neural network for training; If the sample image input into the deep neural network is the classified image, determining whether the second category label corresponding to the input classified image is included in the first category label set; if so, calculating the loss value based on the first loss function; if not, calculating the loss value based on the third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function; If the sample image input into the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function; Back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
2. The model training method according to claim 1, characterized in that: The third loss function=k*first loss function, wherein k>1.
3. The model training method according to claim 1, characterized in that: The first loss function is m*f, and the third loss function is n*f, wherein f is a basic loss function, 0<m<1, n>1.
4. The model training method according to claim 1, characterized in that: The deep neural network is a convolutional neural network; the second category labels carried by all classified images constitute a second category label set, and the number of label types in the first category label set is less than the number of label types in the second category label set.
5. The model training method according to claim 1, characterized in that: The back propagation based on the calculated loss value to update the network parameters until convergence also includes: Get the image to be classified; Image recognition is performed on the image to be classified according to the image recognition model to determine the target category corresponding to the image to be classified and the position of the object belonging to the target category in the image to be classified.
6. A model training device, characterized in that: include: An image acquisition module is used to acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label, the first category labels carried by all target detection images constitute a first category label set, and the classification image carries a second category label; An image input module, used for inputting sample images in the sample image set into a preset deep neural network for training; A label detection module, configured to determine whether a second category label corresponding to the input classification image is included in the first category label set if the sample image input into the deep neural network is the classification image; A first calculation module, configured to calculate a loss value based on a first loss function if the sample image input into the deep neural network is the classified image and the second category label corresponding to the classified image is included in the first category label set; and to calculate a loss value based on a third loss function if the second category label corresponding to the input classified image is not included in the first category label set, wherein when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function; A second calculation module, configured to calculate a loss value based on the first loss function and a second loss function if the sample image input into the deep neural network is the target detection image; The iterative training module is used to perform back propagation based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, wherein the image recognition model is used to identify the category of the input image and the location of the category object.
7. The model training device according to claim 6, characterized in that: The third loss function=k*first loss function, wherein k>1.
8. The model training device according to claim 6, characterized in that: The first loss function is m*f, and the third loss function is n*f, wherein f is a basic loss function, 0<m<1, n>1.
9. The model training device according to claim 6, characterized in that: The deep neural network is a convolutional neural network; the second category labels carried by all classified images constitute a second category label set, and the number of label types in the first category label set is less than the number of label types in the second category label set.
10. The model training device according to claim 6, characterized in that: The apparatus further comprises an image classification module, wherein the image classification module is configured to: Get the image to be classified; And, performing image recognition on the image to be classified according to the image recognition model to determine the target category corresponding to the image to be classified and the position of the object belonging to the target category in the image to be classified.
11. A storage medium having a computer program stored thereon, characterized in that: When the computer program is run on a computer, it causes the computer to execute: Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label, the first category labels carried by all target detection images constitute a first category label set, and the classification image carries a second category label; Inputting the sample images in the sample image set into a preset deep neural network for training; If the sample image input into the deep neural network is the classified image, determining whether the second category label corresponding to the input classified image is included in the first category label set; if so, calculating the loss value based on the first loss function; if not, calculating the loss value based on the third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function; If the sample image input into the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function; Back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
12. An electronic device comprising a processor and a memory, wherein the memory stores a computer program, characterized in that: The processor, by calling the computer program, is configured to execute: Acquire a sample image set, wherein the sample image set includes a target detection image and a classification image, wherein the target detection image carries position information and a first category label, the first category labels carried by all target detection images constitute a first category label set, and the classification image carries a second category label; Inputting the sample images in the sample image set into a preset deep neural network for training; If the sample image input into the deep neural network is the classified image, determining whether the second category label corresponding to the input classified image is included in the first category label set; if so, calculating the loss value based on the first loss function; if not, calculating the loss value based on the third loss function, wherein, when the input sample images are the same, the loss value calculated by the first loss function is less than the loss value calculated by the third loss function; If the sample image input into the deep neural network is the target detection image, calculating the loss value based on the first loss function and the second loss function; Back propagation is performed based on the calculated loss value to update the network parameters until convergence, thereby obtaining an image recognition model, which is used to identify the category of the input image and the location of the category object.
13. The electronic device according to claim 12, characterized in that: The third loss function=k*first loss function, wherein k>1.
14. The electronic device according to claim 12, characterized in that: The first loss function is m*f, and the third loss function is n*f, wherein f is a basic loss function, 0<m<1, n>1.
15. The electronic device according to claim 12, characterized in that: The deep neural network is a convolutional neural network; the second category labels carried by all classified images constitute a second category label set, and the number of label types in the first category label set is less than the number of label types in the second category label set.
16. The electronic device according to claim 12, characterized in that: The processor may also call the computer program to execute: Get the image to be classified; Image recognition is performed on the image to be classified according to the image recognition model to determine the target category corresponding to the image to be classified and the position of the object belonging to the target category in the image to be classified.
