Pix2Pix

image of drawing converted to the Pokemon character, Pikachu using Pix2Pix

Image: Image of drawing converted to the Pokemon character, Pikachu using Pix2Pix trained on Pikachu images. Trained by Yining Shi;

Description

Image-to-image translation with conditional adversarial nets, or pix2pix, is a machine learning technique developed by Isola et al that learns how to map input images to output images.

The pix2pix model works by training on pairs of images such as building facade labels to building facades, and then attempts to generate the corresponding output image from any input image you give it. Source

The original pix2pix TensorFlow implementation was made by affinelayer. This version is heavily based on Christopher Hesse TensorFlow.js implementation

Quickstart

  1. // Create a pix2pix model using a pre trained network
  2. const pix2pix = ml5.pix2pix('models/customModel.pict', modelLoaded);
  3. // When the model is loaded
  4. function modelLoaded() {
  5. console.log('Model Loaded!');
  6. }
  7. // Transfer using a canvas
  8. pix2pix.transfer(canvas, (err, result) => {
  9. console.log(result);
  10. });

Usage

Initialize

  1. const styleTransfer = ml5.pix2pix(model, ?callback);

Parameters

  • model: REQUIRED. The path for a valid model.
  • callback: OPTIONAL. A function to run once the model has been loaded. If no callback is provided, it will return a promise that will be resolved once the model has loaded.

Properties


.ready

Boolean to check if the model has loaded


Methods


.transfer()

Given an canvas element, applies image-to-image translation using the provided model. Returns an image.

  1. styleTransfer.transfer(canvas, ?callback);

📥 Inputs

  • canvas: Required. A HTML canvas element.
  • callback: Optional. A function to run once the model has made the transfer. If no callback is provided, it will return a promise that will be resolved once the model has made the transfer.

📤 Outputs

  • Image: returns an HTMLImageObject

Examples

p5.js

p5 web editor

plain javascript

Demo

No demos yet - contribute one today!

Tutorials

No tutorials yet - contribute one today!

Acknowledgements

Contributors:

  • Yining Shi

Credits:

  • Paper Reference | Website URL | Github Repo | Book reference | etc

Source Code

/src/Pix2pix