Code Monkey home page Code Monkey logo

pix2pix's Introduction

pix2pix - Image to Image Translation Using Generative Adversarial Networks

circecli codecov

This repository contains MATLAB code to implement the pix2pix image to image translation method described in the paper by Isola et al. Image-to-Image Translation with Conditional Adversarial Nets.

Before you begin

Make sure you have the minimum following requirements:

  • MATLAB R2019b or greater
  • Deep Learning Toolbox

Getting started

Installation

First off clone or download the repository to get a copy of the code. Then run the function install.m to ensure that all required files are added to the MATLAB path.

install();

Training a model

To train a model you need many pairs of images of "before" and "after". The classic example is the facades dataset which contains label images of the fronts of buildings, and the corresponding original photo.

Use the helper function p2p.util.downloadFacades to download and prepare the dataset for model training. Once that's ready you will have two folders 'A' the input labels, and 'B' the desired output images.

To train the model we need to provide the locations of the A and B images, as well as any training options. The model will then try and learn to convert A images into B images!

[labelFolder, targetFolder] = p2p.util.downloadFacades();

We will just use the default options which approximately reproduce the setttings from the original pix2pix paper.

options = p2p.trainingOptions();
p2pModel = p2p.train(labelFolder, targetFolder, options);

Note that with the default options training the model will take several hours on a GPU and requires around 6GB of memory.

Generating images

Once the model is trained we can use the generator to make generate a new image.

exampleInput = imread("docs/labels.png");

We can then use the p2p.translate function to convert the input image using trained model. (Note that the generator we have used expects an input image with pixel dimensions divisible by 256)

exampleOutput = p2p.translate(p2pModel, exampleInput);
imshowpair(exampleInput, exampleOutput, "montage");

For an example you can directly run in MATLAB see the Getting Started live script.

Any problems?

If you have any trouble using this code, report any bugs, or want to request a feature please use the GitHub issues.

Finally

This repository uses some images from the facades dataset used under the CC BY-SA licence

Copyright 2020 The MathWorks, Inc.

pix2pix's People

Contributors

justinpinkney 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.