A crash course in #deepdream’n

Tom McKenzie
4 min readJul 7, 2015

--

In June, Google posted about Inceptionism: Going Deeper into Neural Networks with the images below, and the general consensus is “this is some cool shit”. Recently they released the instructions to the world, so now we watch computers dream ourselves!

Let’s use this source image and feed it into the software.

Just me rolling a smoke in a van.

Introduction to Layers

Look, I’m not a neural network scientist but the jist is this: lower level networks look for basic form and edges, higher level networks look for complex forms and dog-faces. I think the first thing this neural network saw as a baby was a dog face, and now it sees them everywhere.

inception_3a/output

inception_3a/output

This is our original image run through “layer 3a’s output”. It mostly detects circular swirls and edges.

inception_4c/output

inception_4c/output

This is our image run through “layer 4c’s output”. It detects more complex shapes such as eyes, bits of faces, and patterns. It’s also kind of scary.

inception_5b/output

inception_5b/output

This is “layer 5b’s output”. It’s beginning to imagine things which aren’t there, such as the complex pattern under the arm, and can comprehend many details ‘glossed over’ in 3a’s output such as nuances of the roof.

Copy and paste

You can run the code we used to make these images yourself hosted on my website. If you’d like to edit it, it’s a good idea to Make a Copy (under the File menu) first, since someone may overwrite your changes otherwise.

Run, Stop, Restart
  • Shift+Enter runs a code cell or moves through text. Do this to run the first three code cells, until the image appears.
  • Click the “play” button in the toolbar or press Ctrl+Enter to re-run the current cell. Good for when you’re tweaking and re-running.
  • We can only run one code cell at a time. To stop the current one, hit “stop” or go to the Kernel menu and select Interrupt. Now you can edit your cell, and re-run.
Same layer, different parameters.
  • A good place to start is edit the parameters for end (name of layer), octave_n (number of octaves), octave_scale (size of octave), and step_size. You can get a list of all layers by running the net.blobs.keys() code cell. Try everything!
  • If things get really bad or stuck, turn it off and on again: Kernel menu → select Restart. It’ll lose it’s memory, so you’ll have to go back to the top, and run (Shift+Enter) those first three code cells again.
  • If you’ve edited it too much and it’s all fucked, select the File menu → select Revert to checkpoint → select the latest one. This will reset all the code to when it was working, but you’ll lose your changes.

Feeding dreams into dreams

More dramatic results can be obtained by feeding the resulting images back into the deepdream, recursively. You’ll see lower levels exaggerate the lines and forms, while higher levels will imagine objects, dog-faces, fish, and all kinds of things.

You can run this with the code under Recursive runs. It dreams in a loop, applying a little zoom (which creates the best effect). You can optionally save each frame to a file to combine them into a movie later (download all your frames using the file-utils workbook).

Python and Notebook

You don’t have to be a programmer to play with Google’s deepdream notebook, but in case you’re curious or want to flex, you can learn some Python basics. Notebook lets you run Python code bit-by-bit, perfect for experimenting with deepdream.

--

--