Giter Club home page Giter Club logo

wespe-keras's Introduction

Wespe-Keras

This repository contains an unofficial implementation of WESPE paper in Keras. There are some modifications such as the use of the Identity loss which is not used in WESPE but used in CycleGAN and the use of InstaceNormalisation layer which improved the stability of the training.

This repository is an unofficial implementation of the WESPE GAN in Keras (https://arxiv.org/pdf/1709.01118.pdf). The paper achieves unsupervised/weakly supervised smartphone image enhancement by mapping images from the domain of phone images to the domain of DSLR images (denoted as domain A and B respectively) using an architecture inspired by the CycleGAN (https://arxiv.org/pdf/1703.10593.pdf). The architecture of Wespe is shown below.

The training image x is mapped from domain A --> domain B using the Forward Generator G. The image G(x) is input to two discriminators Dc and Dt (Dc decides whether the image is a real domain B or an enhanced domain A based on its color distribution, while Dt decides based on its texture). Finally, the generated image G(x) is mapped back to domain A by the backward generator F. 4 different losses are used: 2 Adversarial (Lcolor and Ltexture), a total variation (Ltv) loss on the enhanced image G(x) and a cycle-consistency loss (Lcontent) on the reconstructed image F(G(x)) (some norm of x-F(G(x) is minimised, the paper defines the content loss on the VGG19 feature space).

I have modified the model proposed by the paper because some crucial training details were not provided which made it very difficult to find the right combination of all training parameters for stable GAN training. The main modifications are:

  • G generator has greater capacity than the backward Generator F. My intuition for this change was the fact that G learns a more complex mapping (LR --> HR), while F learns a less complex mapping (HR --> LR).

  • Different Discriminator architecture. I have used the PatchGAN discriminator used in the CycleGAN and CINCGAN models. The difference between a PatchGAN and regular GAN discriminator is that the regular discriminator maps a MxM image to a single scalar output, which signifies "real" or "fake", whereas the PatchGAN maps an M x M image to an N x N array of scalar outputs Xij, where each Xij signifies whether the patch ij in the image is real or fake. What is the patch ij in the input image? The output Xij is just a neuron in a CNN, thus we can trace back its receptive field to find the input image pixels that it is sensitive to. In the CycleGAN architecture, the receptive fields of the discriminator turn out to be 70x70 overlapping patches in the input image. In our case, the receptive field of each overlapping patch is smaller. My intuitive explanation of why this approach performs better is that there are regions in the enhanced image G(x) which are closer to target domain statistics than other regions of the image. Therefore, the fact that the PatchGAN classifies many overlapping patches of the image as real or fake gives more feedback to the Generator.

  • A cycle reconstruction loss in both domain A and B. I have discovered that imposing a cycle reconstruction loss in both domain A and B significantly improved the performance of the network compared to using a cycle reconstruction loss only in domain A.

Image enhancement is achieved by mapping images from the domain of phone images to the domain of DSLR images (denoted as domain A and B respectively in the code).

Getting Started

Steps to run the training:

  • Put the training and test data of domains A and B under the folders data/trainA, data/trainB, data/testA and data/testB

  • run the model.py file (you can change the patch size, epochs, batch_size and other parameters in the main)

  • run the modelwithVGGloss.py file (I have tuned the hyperparameters based on preliminary testing on the DPED dataset. You will probably have to tune the hyperparameters of the model for different domain A and B datasets)

Requirements

  • keras (tensorflow backend)
  • scipy
  • Pillow
  • scikit-image

Preliminary experiments/results

Visual results after 1 and 2 epochs (about 1.5h of training time in GTX 2080-ti) are saved in the folder "sample images"

Qualitative & quantitative results of the full training and the trained model will be released soon

The model was trained for 7 epochs on 1.5% of the training DPED data.

The evolution of the average SSIM value on the test data of the DPED dataset:

Visual results after 4 epochs. Image 14 Image 27 Image 13 Image 1 Image 20 Image 26 Image 16 Image 15 Image 22 Image 23 Image 5

wespe-keras's People

Contributors

gbatzolis avatar gbatzolis1 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.