Official PyTorch implementation of the paper: “Deep Single Image Manipulation”.
Image manipulation has attracted much research over the years due to the popularity and commercial importance of the task. In recent years, deep neural network methods have been proposed for many image manipulation tasks. A major issue with deep methods is the need to train on large amounts of data from the same distribution as the target image, whereas collecting datasets encompassing the entire long-tail of images is impossible. In this paper, we demonstrate that simply training a conditional adversarial generator on the single target image is sufficient for performing complex image manipulations. We find that the key for enabling single image training is extensive augmentation of the input image and provide a novel augmentation method. Our network learns to map between a primitive representation of the image (e.g. edges) to the image itself. At manipulation time, our generator allows for making general image changes by modifying the primitive input representation and mapping it through the network. We extensively evaluate our method and find that it provides remarkable performance.READ FULL TEXT VIEW PDF
In this paper, we present DeepSIM, a generative model for conditional im...
We present AugurOne, a novel approach for training single image generati...
Recently, there is a vast interest in developing image feature learning
Single image generative models perform synthesis and manipulation tasks ...
Recent advances in image synthesis enables one to translate images by
We propose a new neural network architecture for solving single-image
A few methods have been proposed to estimate the CRF from a single image...
Official PyTorch implementation of the paper: “Deep Single Image Manipulation”.
Images capture a scene at a specific point in time. Viewers of images often wish the scene had been different e.g. that objects were arranged differently. Due to the popularity of this task, it has been the focus of much research and also of many companies and products e.g. Instagram and Photoshop. Deep learning methods have significantly boosted performance of image manipulation methods for which large training datasets can be obtained e.g. super-resolution or facial inpainting. User-captured photographs follow a long tailed distribution. Some classes of photographs are very common e.g. faces or cars. On the other hand a large proportion of photographs capture a rare object class or configuration. Training deep learning methods that capture the entire long tail of images can be very hard, particularly for generative models that are slow and tricky to train. Training models on just the target image is emerging as an alternative to training deep models on large image datasets. Although this is counter-intuitive as deep learning methods typically require many training samples, single-image methods have recently demonstrated some promising results.
In this paper, we introduce a novel method for training deep conditional generative models from a single image. The training image is first represented with a primitive representation, which can be unsupervised (an edge map, unsupervised segmentation), supervised (segmentation map, landmarks) or a combination of both. We use a standard adversarial conditional image mapping network to learn to map between the primitive representation and the image. In order to extend the training set (which simply consists of a single image), we perform extensive augmentations. The choice of augmentation method makes a significant difference to the method’s performance. We introduce a novel augmentation method based on thin-plate-spline (TPS) and show that it is key to the success of our method. After training, we are able to perform challenging image manipulation tasks by modifying the primitive representation. Our method is evaluated extensively and displays remarkable results.
Our contributions in this paper:
A general purpose approach for training conditional generators from a single image.
Proposing a TPS-based augmentation for conditional image generation, and demonstrating its importance for single image training.
A novel primitive representation allowing concurrent low and high-level image editing.
Extensive evaluations showing remarkable visual performance, and the introduction of a novel protocol enabling quantitative evaluation.
Classical image manipulation methods: Image manipulation has attracted research for decades from the image processing, computational photography and graphics communities. It would not be possible to survey the scope of this corpus of work in this paper. We refer the reader to the book by Szeliski Szeliski (2010) for an extensive survey, and to the Photoshop software for a practical collection of image processing methods. A few notable image manipulation techniques include: Poisson Image Editing Pérez et al. (2003), Seam Carving Avidan and Shamir (2007) and ShiftMap Pritch et al. (2007). Learning a high-resolution parametric function between a primitive image representation and a photo-realistic image was very challenging for pre-deep learning methods.
Deep conditional generative models:Image-to-image translation is the task of mapping an image from a source domain to a target domain, while preserving the semantic and geometric content of the input image. Over the last decade, with the advent of deep neural network models and increasing dataset sizes, significant progress was made in this field. Currently, the most popular methods for training image-to-image translation models use Generative Adversarial Networks (GANs) Goodfellow et al. (2014) and are currently used in two main scenarios: i) unsupervised image translation between domains Zhu et al. (2017a) Kim et al. (2017) Liu et al. (2017) Choi et al. (2018)
ii) serving as a perceptual image loss functionIsola et al. (2017) Wang et al. (2017) Zhu et al. (2017b). Existing state-of-the-art methods for image-to-image translation require a significant number of labeled image pairs.
Single image generators: Limited work has been done on training image generators from a single-image due to the difficulty of the task. Deep Image Prior Ulyanov et al. (2018), retargeting Shocher et al. (2018a) and super-resolution Shocher et al. (2018b) from a single image. Deep image prior is mainly applicable to image restoration tasks rather than novel image manipulations, and also requires training a deep network for every new manipulation. The seminal work of Shaham et al. Shaham et al. (2019), presented a more general approach for single image generative model training, which can be used for unconditional and some conditional image generation tasks. SinGAN is typically more successful on texture images rather than larger objects.
We propose a conditional generative adversarial network (cGAN) for learning to map from a primitive image representation (e.g. edges, segmentation) to the image. The approach has several objectives: i) single image training ii) fidelity - the output should reflect the primitive image representation iii) appearance - the output image should appear to come from the same distribution as the training image. In this section, we present a novel augmentation method that allows standard cGAN architectures to achieve these objectives. The particular type of augmentations used is critical as they provide a prior over the data. Having a good prior is important in this case as the training set consists of merely a single image.
Our model design follows standard practice for cGAN models (particularly pix2pixHD Wang et al. (2017)). Let us denote our training image pair where is the input image and is the corresponding image primitive. We learn a mapping network , which takes in the input image primitive
and outputs the estimated image. We use the VGG perceptual loss Johnson et al. (2016) which extracts features from the predicted and actual images and computes the difference between them.
Conditional GAN loss: Following standard practice, we add an adversarial loss which measures the ability of a discriminator to differentiate between the (input, generated image) pair and the (input, true image) pair . The discriminator
is implemented using a deep classifier and is trained adversarially to the mapping network. The loss of the discriminator is:
The combined loss of the mapping network is the sum of the reconstruction and adversarial mapping loss, weighted by a constant :
Although the formulation above works well for image translation if trained on large datasets, it overfits on a single image. This has the negative consequence of not being able to generalize to a new primitive image input. In order to generalize to new primitive images, the size of the training dataset needs to be artificially increased so as to cover the range of expected primitives (please see Sec. 5
for more analysis). Conditional generative models typically use simple crop and shift augmentations. This simple augmentation strategy however will not generalize to primitive images with non-trivial changes (even simple rotations). Instead, we propose a novel augmentation strategy. We model the image as a grid and shift each grid point by a uniformly distributed random distance. This forms the shifted grid. We use a thin-plate-spline (TPS) to smooth the transformation into a more realistic warp . The TPS optimization problem is given by:
Where are grid-cell locations, denote the second order partial derivatives of . is a regularization constant determining the smoothness of the warp. This optimization can be performed very efficiently e.g. Donato and Belongie Donato and Belongie (2002). The resulting transformation is then used to transform the original image , for a particular training iteration. A different, randomly sampled TPS warp is used for every training iteration. We additionally use random rotations, to further increase the range of image primitives seen in training.
In order to be able to edit the image, we condition our generator on a representation of the image that we call the image primitive. The required properties of the image primitives are being able to precisely specify the required output image and the ease of manipulation by image editor. These two objectives are in conflict, although the most precise representation of the edited image is the edited image itself, this level of manipulation is impossible to achieve by a human editor, in fact simplifying this representation is the very motivation for this work. Two standard image primitives used by previous conditional generators are the edge representation of the image and the semantic instance/segmentation map of the image. Segmentation maps are easier to manipulate and provide information on the high-level properties of the image, but give less guidance on the fine-details. Edge maps provide the opposite trade-off. To achieve the best of both worlds, we propose a novel primitive, which includes both the edge and segmentation maps combined together (we dub this representation - "super primitive"). The advantages of this primitive representation will be shown in Sec. 5
We implemented the conditional GAN using the pix2pixHD architecture. We kept the same hyperparameters as in the official repository except changing the number of iterations to. For each iteration, we randomly sample a new TPS warp and transform both the input primitive and output images. We also augment both images with a random rotation. We then proceed to train the network in the usual way.
In this section, we evaluate our method both qualitatively and quantitatively.
Example results by our method are displayed in Fig. 1. Our method is able to generate very high resolution images from single image training. In the top row we are able to perform fine changes to the facial images from edge primitives e.g. raising the nose and flipping the eyebrows. In the second row, we show complex shape transformations by using segmentation primitives. Our method was able to add a third wheel to the car and convert its shape into a sports car. This shows the power of the segmentation primitive, enabling major changes to the shape using simple operations. On the bottom row, we show that our method can perform free-form changes, completely changing the shape of an image while preserving fine texture.
In Fig. 4, we present edges-to-image translation results on two different shoes. We can see that pix2pixHD trained on the entire edge2shoes dataset is unable to capture the correct identity of the shoes as there are multiple possibilities for the appearance of the shoe given the edge image. BicycleGAN is able to take as input both the edge map and guidance for the appearance (style) of the required shoe. Although it is able to capture the general colors of the required shoe, it is unable to capture the fine details of the shoes (e.g. shoe laces and buckles). We believe that the loss of information is a general disadvantage of training on large datasets, a general mapping function becomes less specialized and therefore less accurate on individual images.
In Fig. 5, we present results on a paint-to-image task. Our method was trained to map from a rough paint image to an image of a tree, while SinGAN was trained using the authors’ best practice. We can see that SinGAN outputs an image which is more similar to the paint than a photorealistic image. Our method is able to change the shape of the tree to correspond to the paint while keeping the appearance of the tree and background as in the training image.
We evaluate our method quantitatively using reference-based and reference-free metrics. As single image generators have mostly operated on unconditional generation, there are not currently established datasets and metrics to conduct such an evaluation.
We propose a novel evaluation procedure for conditional single image evaluation. Our method utilizes video to provide ground truth for computing the metrics. We introduce a new evaluation dataset spanning different scenes and primitives. A single frame from each video is designated for training, where the network is trained to map the primitive image to the designated training frame. The trained network is then used to map from primitive to image for all the other frames in the video. The difference between the generated and the ground-truth frames is computed using LPIPS Zhang et al. (2018), a standard high-quality deep perceptual metric. We use all video segments from the Cityscapes dataset Cordts et al. (2016) provided by the code in vid2vid Wang et al. (2018) and Few-shot-vid2vid Wang et al. (2019). These sequences are labelled aachen-000000 to aachen-000015 leftImg8bit. For each sequence, we train on frame 000000 and test using frames 000001 to 000029. We use the segmentation maps provided as image primitives. We also use the first videos in the public release of the Oxford-BBC Lip Reading Sentences 2 (LRS2) dataset containing videos of different people speaking. We extract their edges using a Canny edge detectorCanny (1986). In total, our evaluation set contains Cityscapes frames and LRS2 frames.
A visual evaluation of our method on a few frames from the Cityscapes dataset can be seen in Fig. 6. We compare our method to the results of pix2pixHD model that was trained on a single image without using the TPS augmentation (it still uses the standard augmentations used by generative models i.e. random cropping and horizontal flips). We can observe that our method is able to synthesize very different scene setups from those seen in training, including different numbers and positions of people. We can see that our method performs significantly better in terms of fidelity and quality than single-image pix2pixHD indicating that our proposed TPS augmentation is critical for single image conditional generation.
A quantitative evaluation of the Cityscapes dataset is provided in Tab. 1 and of the LRS2 dataset is provided in Tab. 2. We present LPIPS and also SIFID, a reference-free method that measures the perceptual similarity of the distribution of patches between the source and target images. Results are presented for each of the LRS2 sequences and also for the average of Cityscapes videos (for space reasons). We can observe that our method significantly outperforms single-image pix2pixHD in all comparisons.
In this section, we analyse the remarkable results of our method.
TPS improves generalization: Let us consider the train and test edge-image pairs presented in Fig. 7
. We input each edge map through an ImageNet-trained ResNet50 network and computed the activations at the end of the third residual block. For each pixel in the activation grid of the test image, we computed the nearest-neighbor (1NN) distance to the most similar activation of the train image. We then performedTPS augmentations to the training image, and repeated the 1NN computation with the training set now containing the activations of the original training image and its 50 augmentation. Let us compare the 1NN distances presented in Fig. 7 with and without TPS augmentations. Naturally, the 1NN distance decreased for the TPS-augmented training set due to its larger size. More interestingly, we can see that several face regions which prior to the augmentations did not have similar patches in the input, now have much lower distance (while more significant changes might not be possible to describe by TPS). In Fig. 7, we present the results of our method when trained on the training edge-image pair (shown in the leftmost column) and evaluated on the test edge. We can see that the prediction error ( difference between ResNet50 activations of the predicted and the true test image) appears to be strongly related to the 1NN distance with TPS-augmentations. This gives some evidence to the hypothesis that the network recalls input-output pairs seen in training. It also gives an explanation for the effectiveness of TPS training, namely increasing the range of input-output pairs thus generalizing to novel images.
The significance of image primitives: The choice of input primitive images is important for the performance of our method. The standard primitives typically used by conditional image generators are edge and segmentation maps. Segmentation maps capture high-level aspects of the image while edge maps capture the low-level of the image better. To obtain the best of both worlds, we proposed a new primitive which we denote the "super primitive" (SP) representation. SP contains the edge map overlaid on the segmentation map. It provides both low and high-level details of the scene. Fig. 2 evaluates the settings where the target bird is represented using edges, segmentation and SP. We can observe that the edge representation is unable to capture the eye, presumably as it cannot capture its semantic meaning. The segmentation is unable to capture the details in the new background regions creating a smearing effect. SP is able to capture the eye as well as the low-level textures of the background region, showing its strong representational power. In Fig. 3 we present more manipulation results using SP. In the center column, we present image reorganization results, where the positions of the rightmost cars were switched. As the objects were not of the same size, some empty image regions were filled using small changes to the edges. A more extreme result can be seen in the rightmost column, the car on the left was removed. This created a large empty image region. By filling in the missing details using edges, our method was able to successfully complete the background. We believe this results fully illustrates the power of our method and new primitive image representation.
Interpolating empty regions: In Fig. 8 we stress test our method’s ability to handle regions with little guidance. In this example, the nose of the cat was shifted progressively downwards, forcing the network to interpolate the missing space. We observe the network generates attractive synthetic images for moderate empty regions, however, as the empty region gets larger, the network looks for similar regions to fill the newly created void. These regions will often be areas which exhibit low amounts of detail in the primitive representation. In our case we can notice that for larger shifts, the empty space becomes greener until eventually it inpaints a background patch. We conclude that at a certain point, the network fails to learn the spatial relationship among objects in the image (i.e. that the background can not be placed on the cat’s face) and satisfies the given constraint using neighboring information (as was analysed above).
We proposed a novel method for training conditional generators from a single training image based on thin-plate-spline augmentations. We demonstrated that our method is able to perform complex image manipulation at high-resolution. Single image methods have significant potential, they preserve image fine-details to a level not typically achieved by previous methods trained on large datasets. One limitation of single-image methods (including ours) is the requirement for training a separate network for every image, which can be expensive over a large dataset. Speeding up training of single-image generators is an important and promising direction for future work.
The cityscapes dataset for semantic urban scene understanding. In , pp. 3213–3223. Cited by: §4.2.
Image-to-image translation with conditional adversarial networks. In CVPR, Cited by: §2.
The unreasonable effectiveness of deep features as a perceptual metric. arXiv preprint arXiv:1801.03924. Cited by: §4.2.