If you’ve been on the geeky parts of the Internet lately, you may have noticed some very strange images popping up, connected somehow to Google.
They look a little like someone took a lighter to the film stock of time and space. Or like playing “Where’s Waldo” on acid. Or maybe like someone turned John Carpenter’s The Thing Get Smart: Watch the Best Futuristic Action Movies Get Smart: Watch the Best Futuristic Action Movies There are a number of movies that combine hard-hitting action with deep concepts. These are smart, thought-provoking films that offer a most welcome form of intelligent entertainment. Read More loose in a pet store.
Regardless, they’re pretty trippy.
These images are the output of Google’s DeepDream neural network. The network, originally used to classify images, has now been re-purposed to create them. The network identifies features in images — perhaps that crease looks a little like an eye, or that silhouette looks like a bird. It then emphasizes the elements it recognizes, over and over again, slowly transforming the resulting image into a vivid and surreal dreamscape.
The network, due to quirks of its training data, has a fixation with dogs, eyes, and tendrils, leading to a unique visual style that almost looks like art.
Recently, Google released DeepDream to the public. It’s a research tool, so setup is a little complicated, but it’s perfectly doable for anyone — even if you have no programming knowledge.
Today, I’m going to talk you through how to install it and use it to generate crazy pictures of your own. Let’s get started.
The Tools You’ll Need
First off, this tutorial is for Windows only. Linux users without access to a Windows machine are welcome to try this tutorial, which people seem to like but I haven’t personally tried.
To get started, you’ll need to download and install the following tools before you do anything else. The rest of the tutorial won’t work without these components installed.
- Vagrant — Vagrant is a tool for setting up standardized development environments. It’ll greatly simplify setup.
- Virtualbox — Virtualbox allows you to run other operating systems from within Windows How to Use VirtualBox: User's Guide How to Use VirtualBox: User's Guide With VirtualBox you can easily install and test multiple operating systems. We'll show you how to set up Windows 10 and Ubuntu Linux as a virtual machine. Read More . In this case, we’ll be simulating a Linux machine.
- OpenSSH — OpenSSH is a tool for connecting via command line to specific Linux machines 4 Easy Ways to Use SSH In Windows 4 Easy Ways to Use SSH In Windows SSH is the de facto solution for securely accessing remote terminals on Linux and other UNIX-like systems. If you have a remote SSH server you want to access, you'll have to download an SSH client.... Read More . In this case, we’ll be using it to talk to our virtual Linux machine.
Note that OpenSSH will throw a big, scary warning during installation that you must set up the passwd file or else hell and brimstone will rain down around your ears.
Ignore this. Vagrant will take care of it for you.
Installing the Dreamer
Now that we’ve got the setup out of the way, let’s get down to brass tacks. Download the image-dreamer module from GitHub as a zip file, and extract it into your Vagrant setup at “C:\HashiCorp\Vagrant\bin\
“.
That’s pretty much it in terms of setup. Now we just have to turn the thing on.
Open Windows PowerShell (you can find it by typing “powershell” into the start menu). It’s a much-need replacement for the old Windows command prompt 6 Basic PowerShell Commands to Get More out of Windows 6 Basic PowerShell Commands to Get More out of Windows PowerShell is what you get when you give steroids to the Windows Command Prompt. It grants you control of nearly every aspect of the Windows system. We help you leap up its learning curve. Read More , and it’ll serve us well here.
When PowerShell opens, type “cd C:\HashiCorp\Vagrant\bin\image-dreamer
“. That puts you into the same directory you just unzipped the module into. Now it’s time to activate our Vagrant install. Type “vagrant up
” and hit enter.
At this point, the system will start to do a bunch of first time setup. At this point, you might want to tab over to Netflix for a bit, because this step could take over an hour, depending on the speed of your machine.
If you get an error saying that the virtual machine failed to boot, you might have the same problem I initially had, which is that virtual machines are disabled by default in your BIOS. You’ll need to reboot your computer, go into the BIOS setup, and see if you can find an option to “Disable virtualization“. Check under the security settings. If you do find it, turn it off and try the powershell again.
Once the install is finished, type vagrant ssh
into the command line. It’ll prompt you for a passphrase. Hit Enter without typing anything. It’ll then prompt you for the password. Type “vagrant
” and hit Enter. At this point, it’ll give you a terminal to the virtual Linux machine, and we’re ready to use DeepDream.
Type “cd /vagrant
“, then “ls
” (the linux command to list the contents of the directory). You should see the files in the image-dreamer directory. You can now interact with those files as though you were using a Linux machine.
At this point, you’re going to need to take all the images you want to convert, make sure they’re in .jpg format, and dump them into “C:/HashiCorp/Vagrant/bin/image-dreamer/
“. If you type “ls
” again, you should see them.
Using DeepDream
The most basic use of DeepDream is to apply the default analysis by typing
python dreamify.py yourfilename.jpg dream_yourfilename.jpg
Obviously, you’ll need to substitute the name of your file for “yourfilename”. This will apply the default analysis option (‘inception_4c/output’) to whatever output name you specify. This is how most images are generated. This function basically turns this:
Into this:
Be patient while it’s running! Large images can take a VERY long time, even on relatively fast hardware. Downscale your images when possible. If you get a crash because you’re out of memory, edit the “vagrantfile” file through the powershell linux command line, and increase v.memory to something reasonable like 10000. If you get an effect that’s less dramatic than you hoped, try running the program again on the output image. This should lead to a stronger distortion.
This is already very cool. However, just using the software this way is missing out on some extremely cool command line options that can alter the behavior of the software. For example, to use only the feature detector for lines, you just need to type:
python dreamify.py yourfilename.jpg dream_yourfilename.jpg “conv2/3×3”
This produces output that looks like this:
To use the feature detector for eyes, you just type:
python dreamify.py yourfilename.jpg dream_yourfilename.jpg “inception_4a/output”
There are a bunch of these command line options you can play with — way too many for me to go into here. You can find a more comprehensive rundown here and here.
There are plenty of options here. You can also get compelling results by stacking these options. For example, here are some images I generated by running the default filter, followed by the line filter.
This is Cool, Right?
Once you install DeepDream, take some time and play with it. There’s already a thriving Reddit community forming around creating these images. See what you can create! Post your most interesting results in the comments.
Image Credits: Van Gogh Portrait, Van Gogh Landscape, Dali – Persistence of Memory, Beetle, Chameleon, Fractal Broccoli,
I'm getting right to the end and then I get the error message:
"F0409 07:45:50.050493 10124 syncedmem.hpp:25] Check failed: *ptr host allocation of size 125052928 failed
*** Check failure stack trace: ***
Aborted"
What should I do?
How it's possible to convert multiple files at once
Did you find a solution to this?
if i want to dreamify a picture i get the message file "dreamify.py", line 5, in import PIL.image importerror: no moduel named pil.image
has anybody the same error
Wow thanks for the fantastic tutorial! I'm actually working on an HD demo of an animated fractal ... my ole machine is working overtime! If you're interested I'll find a way of getting a copy your way :)
Note : it's a small animation with 400 frames; DeepDream shoots them out ... 11 minutes each; frames are 1920x1080. So far it's amazing :) I'm thinking of using different processing techniques and daisy chaining the results ... hopefully get the thing to a minute or so ... O yeah, at this size, the virtual machine requires 8192 Mo to process (my machine has 12GO so I'm all good)
Anyway ... I have a question. On another page I read you can change the reference image used by DeepDream; is this possible? Or am I getting the concept wrong? The user was using the "Docker" version of DeepDream and in his example, buildings looked like churches after being dreamt ...
On another note I read all the comments here; many said the input had to be .JPG ... THIS IS NOT TRUE! While DeepDream can read .JPG, it will read and output .PNG by default (even if you give your file a .JPG extension!). I suggest you work in .PNG format anyways; it's lossless and you get the best out of your source material ... Even if the video compressor will mangle it for you in the end LOL ... edit dreamify.py and see it with your own eyes ... fmt='png' ...
after i entered the 'vagrant up' command it gave me an error so i went into the bios and disabled virtualization, then then when i re-entered 'Vagrant up' it did its thing and then gave me this error The guest machine entered an invalid state while waiting for it
to boot. Valid states are 'starting, running'. The machine is in the
'poweroff' state. Please verify everything is configured
properly and try again.
If the provider you're using has a GUI that comes with it,
it is often helpful to open that and watch the machine, since the
GUI often has more helpful error messages than Vagrant can retrieve.
For example, if you're using VirtualBox, run `vagrant up` while the
VirtualBox GUI is open. i alreadt opened up VMware but it doesnt help
I see simmilar thitg in appstore dreem filter or deepdream, something like this.
You should probably mention that on the page of the Hawaii set of examples of different filters, the person who wrote down the filters used the incorrect slash (the backslash rather than the correct forward slash). It is "inception_5b/1x1" and not, as the page says, "inception_5b\1x1." The latter only generates an error and no picture— you hafta get the slashes (and underscores) in the exact right place and in the correct form for these filters to work!! I can't find a way to reach the person who made the mistake. Also: you indicate above that the images we want to work with should be moved to the C:\HashiCorp\Vagrant\bin\image-dreamer directory. I am getting a directory of C:\HashiCorp\Vagrant\bin\image-dreamer-master instead, as the former was not generated and does not appear to exist (?). So much success hinges on details like these!! That is all.
Just a quick question: I've set it up to test and it's working on an image, but how long do you think it'd take to process a 1920x1080 image? I was able to do that initial install in about 10 minutes because my rig is relatively fast. I think it looks like I've got 10 parts for 0, 1, and 2, but I didn't know at what number it stops.
nevermind, I was do files too large. New question, how in the hell do I write the bash script? I'm doing this on windows so I have little experience writing a bash from the terminal. not sure how to approach it.
Uses "nano" to create the file and fill it in with the desired commands. Make sure it ends in '.sh'. Then save it, and make it executable using chmod +x scriptname.sh
Then, just type ./scriptname.sh
That should run it.
I actually figured it out using vim. I'm kinda brute forcing my way through this haha. Thank you for the guide and response though.
I do have one question I can't figure out do to lack of linux coding knowledge. How would I organize the code if I wanted to have it run one image through all the various layers once? Like, take one image in a folder, run it as dreamify.py x.jpg y.jpg "conv1/7x7_s2", ouput it, then do "pool1/3x3_s2" and output it , etc etc?
I'm not sure of the correct commands, but I think it'd be
#!/bin/bash
for file in *.jpg
do
python dreamify.py $file “dream_”$file” "layers"
frame = *.jpg
save("frames/%04d.jpg"%frame_i)
frame_i += 1
done
No idea if that code makes sense.
Hello,
I'm not sure what I'm doing wrong. I've followed the directions perfectly (or so I thought), but once I type cd C:\HashiCorp\Vagrant\bin\image-dreamer> vagrant up into PowerShell, I get an error that says "A positional parameter cannot be found that accepts argument 'vagrant'." I've never done anything like this before, so it might be an easy fix that I'm not seeing.
My only guess is maybe the pre-requisite programs didn't install properly. Go back and reinstall vagrant and the other two.
Hi, I have done the tutorial; when i type "vagrant ssh" works, and then "vagrant" works, but when i type "cd /Vagrant" it say that "Set-location : Cannot find path 'C:\vagrant' because its does not exist." and I can't continue... :( what i did wrong?
Make sure you aren't capitalizing the 'v' in "cd /vagrant".
If that doesn't work, type 'ls' and tell me what you see.
when I type "ls"
Directory C:\hashicorp\vagrant\bin\image-dreamer-master
Mode LastWriteTime Lenght Name
d---- .vagrant
-a--- 1.jpg
----- dreamify.py
------ README.md
------ Vagrant file
Looks like you're already in the correct folder! Try the 'python dreamify.py etc. etc.' command.
It says
"The term 'python' is not recofnized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was includes, verify that the path is correct and try again.
At line:1 char:7
+python <<<< dreamify.py 1.jpg dream_1.jpg
+ CategoryInfo : ObjectNotFound: CommandNotFoundExeption
FullyQualifiedErrorID : CommandNotFoundException
:(
Huh. Weird. What does your prompt look like?
Processor 2.1 GHz
Ram 8,00 gb (7.87 usable)
64-bit Operating system
Maybe this is the problem: When i type "vagrant ssh" this is the answer.
"‘ssh’ executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try to stalling Cygwin, MinGW or Git, all of which contain SSH client. Or use your favorite SSH client with the following authentication information show below:"
What do you recomend?
Hello.
After typing 'vagrant up' in how do you know when it's done?
You said it's gonna take a while, since my computer is fairly old I typed 'vagrant up' and went to sleep.
I guess it downloaded some files and stuff related to VirtualBox
In the morning I found some writing in red so I restarted powershell,
now when I change directory to deepdream folder and type in 'vagrant up' It writes some codes and stuff which I have no idea what they are.
'PS C:\HashiCorp\Vagrant\bin> cd C:\HashiCorp\Vagrant\bin\image-dreamer
PS C:\HashiCorp\Vagrant\bin\image-dreamer> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'data-science-toolbox/dst' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 => 2200 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
PS C:\HashiCorp\Vagrant\bin\image-dreamer> vagrant up'
I've waited more than an hour and nothing.
How do I know when it's done? what message will I get after all of this?
(Sorry for my bad English skills)
Oh and btw, after all the messages above
I enter vagrant ssh and this is what I get
PS C:\HashiCorp\Vagrant\bin\image-dreamer> vagrant ssh
VM must be running to open SSH connection. Run `vagrant up`
to start the virtual machine.
Hmm. Sounds like vagrant up might be failing. Open virtualbox and make sure there aren't any errors?
Hey Qanea.
You know it's done when it returns you to a prompt where you can actually enter text. Like the prompt where you originally typed 'vagrant up.' Something like C:\HashiCorp\Vagrant\bin\image-dreamer> [your cursor here]
Hopefully that helps!
Thanks for the instructions - was fun.
I found inception 5a worked best for me :)
Here are my results.
http://www.marcfairhurst.com/Deep-Dream
If I have e.g. five images called file1.jpg, file2.jpg, file3.jpg, file4.jpg and file5.jpg, is there any command I could use to process them all in one go? Thanks
No single command, but you can write a bash script to do it pretty easily.
Here's a bash script I wrote that will process all of the images in a folder
#!/bin/bash
for file in *.jpg
do
python dreamify.py $file "dream_"$file"
done
You can google online for how to create and execute a bash script from the command line.
Hey Andre,
That worked a treat. I've very little experience with bash so thanks for the challenge. Couldn't get it working for a while until I ran it in one line i.e.
for file in *.jpg; do python dreamify.py $file “dream_”$file”; done
Thanks! Typed it one line i.e. for file in *.jpg; do python dreamify.py $file “dream_”$file”;
done
and it worked great!
Hi,
at the end i get the information "Killed" and can't find the result. What's the Problem?
Next try i got the message " F0714 11:00:49.675703 9710 syncedmem.hpp:27] Check failed: *ptr host alllocation of size 118619136
*** Check failure stack trace : ***
Aborted
Sounds like you're running out of RAM. Trying feeding it a smaller image.
Hey Andre, I am stuck.
when I type the password, nothing appears, but that seems to be O.K.
after that I type "/vagrant" and then the "ls", and that's where I get stuck.
nothing happens, I mean, the "Caffe repos" in blue appears followed by "Vagrantfile", what do I do now?
sorry, i am dumb and english is not my first language. :)
No problem, Marcelo. Try 'cd /vagrant' instead of just /vagrant. "cd" stands for "change directory." It's a navigational tool to make sure you're in the right place.
I think It worked. I'll try to do a whole music video using this. I'll credit you if it works. :)
thank you very much. take care.
Glad to hear it Marcelo!
Ooh, that sounds really cool. Be sure to post it here if you succeed. If you're going to be processing a lot of images, I recommend use a bash script to automate the process. Thousands of music videos frames would take a lot of effort manually.
yeah, I saw that on the deepdream video thread, but couldn't understand.
I THINK I'll have to do frame by frame (Y)
Andre, help me with one final thing?
I am getting a ValueError: rollaxis: axis must be >=0 and < 2
what does this mean?
Yeah, you'd need to break the video down into individual frames, and then process them one at a time. There are some utilities that do the breakdown for you.
I don't think I've seen that error before. What command are you typing in to get it?
is right before I tried to do the second image
I type: python dreamify.py yourfilename.jpg dream_yourfilename.jpg
and it gives me a bunch of info, and then this...
So it worked successfully on the first image? That's really weird. Looks like it might be a problem with numpy. Try restarting your powershell terminal, and repeat the listed steps, and see if that fixes it.
If not, you could try to reinstall numpy.
but of course I change the file names...
just did that, I'll try to reinstall numpy.
Okay. Try "sudo apt-get install python-numpy"
Let me know if that helps.
still getting the same error....
Hmm. I'm pretty much stumped, then. As a last-ditch effort, you could try typing 'vagrant destroy' and delete any VMs from virtual box and then reinstall everything from scratch and see if that helps.
If THAT doesn't work, you could always post on /r/deepdream and see if they have any ideas I don't.
thanks Andre, for everything. :)
Not a problem. Sorry I couldn't solve your issue!
Hi there, got right to the end but I am unable to type to put the 'vagrant' password in, any ideas?
That's weird. All lower case?
What error is it throwing?
nope its all good, i was just rushing things!
Awesome! Be sure to post some of your results. :)
This is loadsa fun! How do I edit that vagrantedit file though? At the moment I keep killing it when I try to run a higher resolution image through it. Thanks Andre!!
You can use any command-line text editor. If you aren't familiar with the command line text editors, I recommend nano.
Just type "nano filename.extension" to open the file, and then make whatever changes you need. I believe control-x exits, and then you have to type 'y' to save. Fair warning, though, I found that even increasing the memory, some image sizes just didn't work on a desktop machine.
Winner! Thanks again!
This is awesome. I am trying this. I have already joined the sub-reddit r/deepdream.
Thanks! But “conv2/3×3? doesn't work for me.
Also even when it does work the first thing it says is:
OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.
OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.
libdc1394 error: Failed to initialize libdc1394
As in, when I do something else than the line thing and it works.
That's strange. I just double-checked, and "conv2/3x3" works for me. Might be to do with the other error you're getting, which sounds like it might be hardware specific. Try it on a different machine?
Just a thought, make sure you're typing "conv2/3x3", and not copy-pasting it. Just in case some formatting weirdness is creeping in.
I tried copy-pasting the × from this article, from wikipedia and by Alt and 0 2 1 5, as per these instructions: https://en.wikipedia.org/wiki/Multiplication_sign#In_computer_software
Alt Gr and + is also supposed to generate a multiplication sign, but that does seem to work, and Alt and 0 D 7 generates •.
What version of python is everyone using?
When i spun up vagrant i had to set the python env.
I use 2.7 and I get a message saying numpy is not installed.
When i use 3.4 it compiles dreamify.py with an error on like 81.
PS C:\hashicorp\vagrant\bin\image-dreamer-master> python dreamify.py itnense.jpg intense.pg
Traceback (most recent call last):
File "dreamify.py", line 3, in
import numpy as np
ImportError: No module named numpy
Python 2.7.6
Not sure why you had to configure that manually. It should all be set up for you with vagrant.
Thnks Andre! "caffe repos" with "ls" in blue and "caffe repos" in white with "dir"
Great tutorial! I'm almost there! Got stucked on the last step! I'm getting this error "python: can't open file 'dreamify.py': [Errno 2] No such file or directory". Any clues if i'm doing something wrong? Help!
Hey Eric! Could you please enter 'ls' and 'dir' separately and tell me what you see? You're either in the wrong directory, or something didn't unpack properly.
Thnks Andre! “caffe repos” with “ls” in blue and “caffe repos” in white with “dir”
Thanks Eric. I think you're in the wrong directory. Give me a moment, and I'll figure out what went wrong.
Thanks Andre for the quick reply! Is there a way to undo the first time setup? So maybe this way when I do the "vargant up" it reinstalls everything again?
You shouldn't need to redo first time set-up. But, yes, there's a way to do that if it proves necessary.
Okay, I figured out what's going on. You just need to type "cd /vagrant"
That should get you to the proper directory. If you type 'ls' afterwards, you'll see 'dreamify.py' among other files. The commands should work from there.
Thanks Andre but still no go. I'm at "vagrant@data-science-toolbox:/vagrant$" when I try "ls" I get this: ls: cannot open directory .: Operation not permitted.
and when I try the python dreamify.py... get the same error as before
sorry I'm new at all of this, really trying to get this to work
Hey Eric Robinsón.. Make sure when typing in cd /vagrant you make a space between cd and /vagrant
That's peculiar. It sounds like you may not have execute permission to the directory.
My linux is a little rusty, but try "sudo su", and then "ls" again.
i'm having this exact same problem!
Did you try the 'sudo su' fix?
Also, I spent some time looking into it, and it looks like this can happen if you rename the vagrant project's parent folder. Does that sound like something that might have happened?