CROSS REFERENCE TO RELATED APPLICATIONS

This application claims priority and benefits to Chinese Application No. 202010484916.4, filed on Jun. 1, 2020, the entire content of which is incorporated herein by reference.

TECHNICAL FIELD

The disclosure relates to a field of image processing technology, particularly to a field of deep learning and image processing technology, and particularly to a method and apparatus for translating an image, and a method and an apparatus for training an image translation model.

BACKGROUND

A type of image may be directly translated into another type of image without changing the image content via an image translation network, which has been widely applied to fields of image generation, scene segmentation, image stylization and the like.

SUMMARY

Embodiments of the disclosure provide a method for translating an image, executed by an electronic device. The method includes:

obtaining an image translation request, in which the image translation request carries an original image;

down sampling the original image to generate a down-sampled image corresponding to the original image;

generating a pre-translated image corresponding to the original image, a mask image and deformation parameters corresponding to each pixel of the original image based on the down-sampled image, in which a size of the pre-translated image and a size of the mask image are the same as a size of the original image;

deforming the original image based on the deformation parameters to generate a deformed image; and

fusing the deformed image, the pre-translated image and the mask image to generate a target translation image.

Embodiments of the disclosure further provide a method for training an image translation model. The method includes:

obtaining a set of training samples, in which the set of training samples includes a set of first images belonging to a first domain and a set of second images belonging to a second domain;

down sampling the set of first images respectively to generate a set of first down-sampled images;

processing the set of first down-sampled images respectively with a first initial generator to generate a set of first pre-translated images, a set of first mask images, and a set of first deformation parameters, in which each first deformation parameter in the set of first deformation parameters corresponds to a respective pixel of the first image in the set of first images respectively;

deforming the set of first images respectively based on the set of first deformation parameters to obtain a set of first deformed images;

fusing each first deformed image in the set of first deformed images, each first pre-translated image in the set of first pre-translated images, and each first mask image in the set of first mask images to obtain a set of third images;

inputting the set of third images to a first initial discriminator to obtain a set of first probabilities that each third image is a real image;

inputting the set of second images to the first initial discriminator, to obtain a set of second probabilities that each second image is a real image; and

correcting the first initial generator and the first initial discriminator based on the set of first probabilities and the set of second probabilities, to generate a first target generator belonging to the first domain, in which the first target generator belonging to the first domain is configured to translate an image in the first domain into an image in the second domain.

Embodiments of the disclosure further provide an electronic device. The electronic device includes at least one processor and a memory communicatively coupled to the at least one processor. The memory is configured to store instructions executable by the at least one processor. When the instructions are executed by the at least one processor, the at least one processor is configured to execute the above-mentioned method for translating an image and the above-mentioned method for training an image translation model.

Embodiments of the disclosure further provide a non-transitory computer-readable storage medium, having computer instructions stored thereon. The computer instructions are configured to cause a computer to execute the above-mentioned method for translating an image and the above-mentioned method for training an image translation model.

It should be understood that the content described in this section is neither intended to identify key or important features of the embodiments of the present disclosure, nor intended to limit the scope of the present disclosure. Other features of the present disclosure will be easily understood by the following description.

