Draw Me an Electric Sheep

Libre AI
Libre AI
Nov 18, 2018 · 5 min read

with AI/ML
by Dr. Ernesto Diaz-Aviles

“If you please — draw me a sheep!”
— From “The Little Prince” by Antoine de Saint-Exupéry

Image for post
Image for post

Do you remember The Little Prince asking the pilot to draw him a sheep? After many attempts; however, the child was not satisfied with the drawings. Being over it, the pilot drew a box and told the prince to imagine the sheep in it. With his creativity, the Little Prince can see it lying down sleeping. It seems that drawing a sheep is not as easy as one might think :)

What if we want to teach a machine to draw an electric sheep?

The alleged sheep contained an oat-tropic circuit; at the sight of such cereals it would scramble up convincingly and amble over.
— “From Do Androids Dream of Electric Sheep?” by Philip K. Dick.

How to teach a machine to draw (electric) sheep?

For instance, the program would have methods to sketch its main characteristics: head, face, hears, coat of fleece on its body, four legs, a tiny tail, its color, etc. Although possible, this program will probably be cumbersome to write and the results will most likely not be approved by critics like the Little Prince.

Image for post
Image for post
Figure 1. Sheep drawings made by real people in The Quick, Draw! experiment.

But most importantly, we humans are imperfectly ingenious sketching sheep, remember The Sheep Market project? or have a look to some of the tens of thousands sheep doodles made by real people in The Quick, Draw! experiment (see Figure 1).

All such variants and diversity humans express when sketching a sheep would be extremely difficult to capture in a program written in Python, Java, or C++. We probably would be better off writing a program that draws a box and claims that the sheep is in it :)

AI/ML to the rescue

If you want to teach the machine to draw a sheep using AI/ML, you won’t tell it to draw the head, then the body with fleece, the face, and eyes. You will simply show it thousands and thousands of drawings of sheep, and eventually the machine will learn and work things out. If it keeps failing, you don’t rewrite the code. You just keep training it.

For this exercise, we will focus on a AI/ML algorithm named Generative Adversarial Networks (GAN). GANs are implemented by a system of two deep neural networks contesting with each other in a zero-sum game framework. The two players in the game are called Generator and Discriminator.

The Generator, as its name implies, generates candidates and the Discriminator evaluates them. The generative network’s training goal is to produce novel synthesized instances that appear to have come from the set of real instances, whereas for the discriminator, its goal is differentiating between true and generated instances.

You can think of an art analogy of an apprentice-master relationship, where from an empty canvas, the apprentice (Generator) will produce paintings that the master (Discriminator) will judge based on her experience and previous knowledge as real pieces of art or not.

The apprentice will get better and better based on the master’s feedback, until reaching a level where the master will not be able to discriminate between her apprentice’s work and a good piece of art.

GANs have shown very impressive results, for example, generating photo-realistic images as the ones shown in Figure 2.

Image for post
Image for post
Figure 2. Example of Images generated using the CelebA-HQ dataset. The figure corresponds to Figure 5 as reported in the paper “Progressive Growing of GANs for Improved Quality, Stability, and Variation” by
T. Karras, et al. 2018. https://arxiv.org/abs/1710.10196

Drawing Electric Sheep with GANs

“That doesn’t matter. Draw me a sheep…”
— From “The Little Prince” by Antoine de Saint-Exupéry

Very well, coming back to our task at hand, our goal is to train a GAN to produce human-level sheep drawings. The following figure illustrates our approach:

Image for post
Image for post
Figure 3. Drawing Electric Sheep with a DCGAN.

In a nutshell:

  • Architecture. We use a Deep Convolutional Generative Adversarial Networks or DCGAN to implement our approach.
  • Deep Learning Tools. We use Keras with TensorFlow backend for the model implementation and JupyterLab for prototyping.
  • Models. After the Generator and Discriminator models are trained, we save them independently.
  • From random noise to sheep. We then use the Generator to produce sheep drawings from random noise. The results are as good (or as bad and sketchy) as the ones produced by humans ;)
Image for post
Image for post
Figure 4. Sheep dreamed by AI/ML. Aren’t they cute? ❤

“Do androids dream?”
― Philip K. Dick, Do Androids Dream of Electric Sheep?

Figure 4 shows a sample of the sheep our AI/ML model generates — an android dream?

They do not look like the celebrities in Figure 2, but, aren’t they cute ❤ ?
One of my favorites is in row 0, column 2 (zero-based indexing), yes that one facing right with the black face :) … What’s yours?

~ Fin ~

About the author
Dr. Ernesto Diaz-Aviles is the Co-Founder and CEO at Libre AI. Ernesto used some of the ideas in this post to teach his daughter about AI/ML and to draw her as many electric sheep as she demanded, without using the sheep-in-the-box trick. She likes some of them.

Notes

  • Our model uses pixel-level information for the images for training and for generating new instances. In order to improve the image quality, we convert the output bitmaps into vector graphics (SVG) using Potrace.

Libre AI

Our mission is to widely disseminate the benefits of…

Libre AI

Written by

Libre AI

Our mission is to widely disseminate the benefits of Artificial Intelligence and Machine Learning and make them accessible to the world.

Libre AI

Libre AI

Our mission is to widely disseminate the benefits of Artificial Intelligence (AI) and Machine Learning (ML) and make them accessible to the world.

Libre AI

Written by

Libre AI

Our mission is to widely disseminate the benefits of Artificial Intelligence and Machine Learning and make them accessible to the world.

Libre AI

Libre AI

Our mission is to widely disseminate the benefits of Artificial Intelligence (AI) and Machine Learning (ML) and make them accessible to the world.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store