• Home
  • Projects
  • Art
  • Blog
  • CV
Menu

Riley Wong

  • Home
  • Projects
  • Art
  • Blog
  • CV
n02111889_1020_real_A.png
n02111889_1020_fake_B.png

samoyed2bernese: Using CycleGAN for Image-to-Image Translation between Samoyeds and Bernese Mountain Dogs

April 19, 2019

Dogs!!! More dogs this week!!! Is it possible I picked this project because I was in the mood for dog pictures? Absolutely.

This week, I used the CycleGAN image-to-image translation model to translate between images of Samoyeds and Bernese mountain dogs, two of my favorite dogs. If you’re not familiar with these breeds, you’re in luck, because here are some dog pictures for your reference. (Such good dogs!!)

 
One very good Samoyed

One very good Samoyed

Two very good Bernese mountain dogs

Two very good Bernese mountain dogs

 

Model Overview

CycleGAN builds off of the pix2pix network, a conditional generative adversarial network (or cGAN) that can map paired input and output images. Unlike pix2pix, CycleGAN is able to train on unpaired sets of images. For more on pix2pix and CycleGAN, see my previous blog post here.

The CycleGAN implementation used to train and generate dog pictures uses PyTorch and can be found on Github here. (This repo also contains a pix2pix implementation, which I had used previously to generate circuit cities.)

A major strength of CycleGAN over pix2pix is that your datasets can be unpaired. For pix2pix, you may have to really dig, curate, or create your own dataset of 1-to-1 paired images. For example, if you wanted to translate daytime photos to nighttime photos with pix2pix, you would need a pair of daytime and nighttime photos of the same location. With CycleGan, you can just have a set of daytime photos of any location and a set of nighttime photos of any location and call it a day (no pun intended).

Another strength of CycleGAN over, say, neural style transfer, is that the translations can be localized. In the following examples, you’ll see that the translation applies only to the dog. Object recognition is implied, and the non-dog portions of the images are not really affected. With neural style transfer, you’re applying a style transformation to the entire image.

As an aside, I originally ran CycleGAN on a set of images of forests, and a set of images of forest paintings. While the results did turn out as expected, I realized this kind of task is really best suited for neural style transfer. (Which inspired me to implement it from scratch! See previous blog post on implementing neural style transfer from scratch in PyTorch.)

Training Data

To train the model, I used 218 images of Samoyeds and 218 images of Bernese mountain dogs from one of my favorite datasets currently on the internet: the Stanford Dogs Dataset. So many good dogs!! My heart!!

GPU training time took a couple of hours on an NVIDIA GeForce GTX 1080 Ti, and generating results only took a few minutes.

Results

In the following examples, on the left is the input, a real photo of a Samoyed. On the right is the CycleGAN output, a generated image translated from the input into a Bernese mountain dog.

 
n02111889_10059_real_A.png
n02111889_10059_fake_B.png
n02111889_1020_real_A.png
n02111889_1020_fake_B.png
n02111889_10084_real_A.png
n02111889_10084_fake_B.png
n02111889_1019_real_A.png
n02111889_1019_fake_B.png
n02111889_10734_real_A.png
n02111889_10734_fake_B.png
n02111889_1145_real_A.png
n02111889_1145_fake_B.png
n02111889_11502_real_A.png
n02111889_11502_fake_B.png
n02111889_12171_real_A.png
n02111889_12171_fake_B.png
n02111889_1314_real_A.png
n02111889_1314_fake_B.png
 

Notes

Note that, since this is a blog post and not a scientific paper, I’ve only included the more effective results in this post. For example, bernese2samoyed doesn’t look quite as good — it just looks like white-out was applied to the dog lol.

 
n02111889_1020_real_B.png
n02111889_1020_fake_A.png
 

I would add that a major strength of cycleGAN is that the changes are applied locally, and not to the entire image. The network is able to identify the boundaries of dog and not-dog.

Another note is that this approach seems to work best when translating between inputs with similar shapes. In these results, mainly the coloring was transferred, and not so much the dog shape. I would posit that breeds that are similar in shape would yield more effective results, e.g. translating between golden and chocolate labs, or between tabby cats and tortoise shell cats.

Tags neural networks, neural network, cycleGAN, generative adversarial networks, dogs, machine learning, GANs, images, image processing, image-to-image translation
← Implementing char-RNN from Scratch in PyTorch, and Generating Fake Book Titlesjoke2punchline, punchline2joke: Using a Seq2Seq Neural Network to "Translate" Between Jokes and Punchlines →
  • 2024
    • Nov 18, 2024 [Talk] Applications of MP-FHE for Vulnerable Communities Nov 18, 2024
    • Jun 11, 2024 [Resource] Community Models for Music Venues and Platforms Jun 11, 2024
    • Jun 11, 2024 [Resource] Interfaces for Data Consent Jun 11, 2024
    • May 7, 2024 Cooperative Leaders and Scholars, Community Venues and Cultural Land Trusts May 7, 2024
    • Mar 27, 2024 [Talk] Governable Spaces | Collective Governance: Governance Archaeology Mar 27, 2024
    • Mar 7, 2024 [Essay] Privacy-Preserving Data Governance, Ash Center Occasional Papers Series Mar 7, 2024
    • Jan 20, 2024 [Talk] Privacy-Preserving Data Governance, Second Interdisciplinary Workshop on Reimagining Democracy, Harvard Kennedy School Ash Center Jan 20, 2024
  • 2022
    • Nov 2, 2022 decentralized networks for community care, dweb reflections, general updates Nov 2, 2022
    • Nov 2, 2022 dm-uy 1133 creative coding guest lecture: creative applications of generative machine learning Nov 2, 2022
    • Mar 10, 2022 coops and governance: mood board Mar 10, 2022
  • 2021
    • Nov 4, 2021 coops and governance Nov 4, 2021
    • Nov 1, 2021 hypnopompia -- published fiction story w/ kernel mag Nov 1, 2021
    • Jul 28, 2021 sleep, dreams, and brain waves Jul 28, 2021
  • 2019
    • Jun 3, 2019 pokemon2pokemon: Using Neural Networks to Generate Pokemon as Different Elemental Types Jun 3, 2019
    • May 16, 2019 Localhost Talk: creative applications of deep learning, aka, neural networks for fun and not profit :-) May 16, 2019
    • Apr 24, 2019 Implementing char-RNN from Scratch in PyTorch, and Generating Fake Book Titles Apr 24, 2019
    • Apr 19, 2019 samoyed2bernese: Using CycleGAN for Image-to-Image Translation between Samoyeds and Bernese Mountain Dogs Apr 19, 2019
    • Apr 12, 2019 joke2punchline, punchline2joke: Using a Seq2Seq Neural Network to "Translate" Between Jokes and Punchlines Apr 12, 2019
    • Apr 4, 2019 Implementing a Seq2Seq Neural Network with Attention for Machine Translation from Scratch using PyTorch Apr 4, 2019
    • Apr 3, 2019 AACR June L. Biedler Prize for Cancer Journalism, SABEW Best in Business Honorable Mention Apr 3, 2019
    • Mar 19, 2019 Implementing Neural Style Transfer from Scratch using PyTorch Mar 19, 2019
    • Mar 6, 2019 Circuit Cities with Pix2Pix: Using Image-to-Image Translation with Generative Adversarial Networks to Create Buildings, Maps, and Satellite Images from Circuit Boards Mar 6, 2019
    • Mar 5, 2019 Dogspotting: Using Machine Learning to Draw Bounding Boxes around Dogs in Pictures Mar 5, 2019
    • Feb 28, 2019 Text Generation with GPT-2, OpenAI's Recently Released Language Model Feb 28, 2019
    • Feb 25, 2019 Generating Jazz Music with an LSTM Recurrent Neural Network Feb 25, 2019
  • 2018
    • Sep 25, 2018 Black Patients Miss Out On Promising Cancer Drugs Sep 25, 2018
    • May 23, 2018 Predicting Readmission Risk after Orthopedic Surgery May 23, 2018
    • May 3, 2018 Machine Learning for Healthcare May 3, 2018
    • Jan 3, 2018 Music and Mood: Assessing the Predictive Value of Audio Features on Lyrical Sentiment Jan 3, 2018
  • 2016
    • Jun 8, 2016 Algorithmic Bias Jun 8, 2016
    • May 26, 2016 Computational Creativity May 26, 2016
  • 2015
    • Mar 12, 2015 penn play promotional profile pictures Mar 12, 2015
    • Jan 21, 2015 fnar 247: environmental animation master post Jan 21, 2015
  • 2014
    • Dec 26, 2014 photographs 01 Dec 26, 2014
    • Aug 21, 2014 Morton Salt Girl 3D Model Aug 21, 2014
    • May 11, 2014 rotary telephone May 11, 2014
    • May 6, 2014 project dump May 6, 2014

Riley Wong © 2014 · contact