CROSS-REFERENCE TO RELATED APPLICATION

This application claims the priority benefit of Chinese Patent Application No. 201910088005.7 filed on Jan. 29, 2019, the entire contents of which are hereby incorporated by reference.

FIELD OF TECHNOLOGY

The following relates to the field of image processing, and in particular, to a method, a device and a terminal for generating training data.

BACKGROUND

With the development of artificial intelligence technology, intelligent container systems capable of automatically identifying goods have emerged. The intelligent container system captures images of goods in its container through one or more cameras provided in the container, and transmits the captured images of the goods to a server end. The identification algorithm of the server end identifies and calculates the types and quantities of the goods in the container in real time.

The automatic identification of goods is realized by visual identification technology based on deep learning. The accurate identification based on deep learning technology requires a large amount of training data sets to be included for support, wherein the more the data for training is contained in the training data set, the more accurate the training results would be. At present, the data sets for goods identification are usually obtained by taking photos manually, for example, by taking pictures including the container and the items, after manually adjusting the position and angle of items on the container. Due to the large variety and the unlimited number of items, the angles for positioning items and the occlusion among items, it is very difficult to manually collect sample images, and the amount of sample data collected is limited. In order to solve the problem of insufficient sample data in the training data set, data synthetization is adopted for obtaining the sample data, that is, the sample data is generated by machine.

The inventor found that at least the following problems exist in conventional art: while forming the training data set by synthesized sample data greatly increases the number of sample data in the training data set, the synthesized sample data is often quite different from the sample data collected in real, thus a model trained with the synthesized sample data is inaccurate, thereby reducing the item identification capability.

SUMMARY

An aspect relates to a method, a device and a terminal for generating training data and a terminal, enabling a small difference between the generated training data and a target image, thus enhancing accuracy of the training model obtained with the training data.

To solve the above technical problem, an embodiment of the present disclosure provides a method for generating training data, including: obtaining an original image; determining a transferred image according to an image style transfer model and the original image, the image style transfer model being obtained by minimizing a loss function, the loss function being determined according to an original loss function, a background loss function, and a foreground loss function; and determining the training data according to the transferred image; wherein, the original loss function is configured to indicate a degree of difference between the transferred image and a target image, and the background loss function is configured to indicate a degree of difference between a background image in the transferred image and a background image in the target image, the foreground loss function is configured to indicate a degree of difference between a foreground image in the transferred image and a foreground image in the target image.

An embodiment of the present disclosure further provides a device for generating training data, including: an obtaining module, a first determining module, and a second determining module; wherein the obtaining module is configured to obtain an original image; the first determining module is configured to determine a transferred image according to an image style transfer model and an original image, the image style transfer model is obtained by minimizing a loss function, and the loss function is determined according to an original loss function, a background loss function, and a foreground loss function; the second determining module is configured to determine the training data according to the transferred image; wherein, the original loss function is configured to indicate a degree of difference between the transferred image and a target image, the background loss function is configured to indicate a degree of difference between a background image in the transferred image and a background image in the target image, and the foreground loss function is configured to indicate a degree of difference between a foreground image in the transferred image and a foreground image in the target image.

An embodiment of the invention further proposes a terminal, including: at least one processor; and a memory communicatively connected with the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and when being executed by the at least one processor, the instructions enable the at least one processor to execute the method for generating training data described above.

Compared with conventional art, in the embodiments of the present disclosure, the image style transfer model is determined by minimizing the loss function, that is, the more accurate the determined loss function is, the closer the transferred image determined by the image style transfer model is to the target image. Generally, an image includes the foreground image and the background image, and if the items in the foreground image or the background image are in a jumble, an inaccurate loss function is often obtained when determining the loss function. In this embodiment, the foreground loss function and background loss function are determined respectively, and the loss function is determined collectively by the foreground loss function, the background loss function and the original loss function, thus avoiding influence of the foreground image to the background image or influence of the background image to the foreground image, thereby greatly improving accuracy of the determined loss function. Since the difference between the target image and the transferred image determined from the image style transfer model and the original image is small, the accuracy of the training data determined based on the transfer data is improved, and thus the accuracy of the training model obtained with the training data is improved.

Further, the method for generating training data further includes performing the following step before obtaining the original image: obtaining a first image set and a second image set, wherein first images in the first image set have the same image style as that of the original image, and second images in the second image set have the same image style as that of the transferred image; determining the original loss function, the background loss function and the foreground loss function respectively according to the first image set and the second image set; and minimizing the loss function determined by the original loss function, the background loss function and the foreground loss function, so as to construct the image style transfer model. Before obtaining the original image, training is performed by using a large number of the first images and the second images to determine the original loss function, background loss function and foreground loss function, thereby constructing an accurate image style transfer model.

Furthermore, the step of determining the original loss function, the background loss function, and the foreground loss function respectively according to the first image set and the second image set includes: segmenting each of the first images in the first image set into a first foreground image and a first background image, and segmenting each of the second images in the second image set into a second foreground image and a second background image; determining the original loss function according to each of the first images and each of the second images; determining the foreground loss function according to each of the first foreground images and each of the second foreground images; and determining the background loss function according to each of the first background images and each of the second background images. By segmenting each of the first images and each of the second images, the foreground loss function and the background loss function may be determined quickly and accurately.

Further, after obtaining the original image and before determining the transferred image, the method for generating training data further includes: converting the original image into an image composed based on hue, saturation, and value, if it is determined that the original image is not an image composed based on hue, saturation, and value. The image based on hue, saturation and value has low sensitivity to colors, and image transferring is an operation for transferring the image style, which requires to ensure that the colors are unchanged or changed little, thus it may greatly improve the accuracy of transferring images by converting the original image into an image based on hue, saturation, and value.

Further, the step of determining the foreground loss function according to each of the first foreground images and each of the second foreground images specifically includes: according to each of the first foreground images and each of the second foreground images, calculating a first expectation function for converting an image style to which the first foreground image belongs into an image style to which the second foreground image belongs, and calculating a second expectation function for converting the image style to which the second foreground image belongs into the image style to which the first foreground image belongs; and taking a sum of the first expectation function and the second expectation function as the foreground loss function. The foreground loss function is determined according to the first expectation function and the second expectation function, such that a flexible conversion between the image style to which the first foreground image belongs and the image style to which the second foreground image belongs is achieved by the foreground loss function.

Further, the step of determining the background loss function according to each of the first background images and each of the second background images includes: according to each of the first background images and each of the second background images, calculating a third expectation function for converting an image style to which the first background image belongs into an image style to which the second background image belongs, and calculating a fourth expectation function for converting the image style to which the second background image belongs into the image style to which the first background image belongs; and taking a sum of the third expectation function and the fourth expectation function as the background loss function. The background loss function is determined according to the third expectation function and the fourth expectation function, such that a flexible conversion between the image style to which the first background image belongs and the image style to which the second background image belongs is achieved by the background loss function.

Furthermore, the step of determining the training data according to the transferred image specifically includes: converting the transferred image based on hue, saturation, and value back to an image based on three primary colors; and taking the transferred image obtained after the conversion as the training data. This ensures the stability of colors in the transferred image.

