Tested on:RPi3, Raspbian Jessie, Python 2
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
Internet connection
Hardware:Raspberry Pi camera module
24

DeepDream on the Raspberry Pi 3 with Raspbian Jessie

DeepDream is a Google software that makes an pattern detection algorithm overinterpret patterns. The result are beautiful hallucinations like the one below. DeepDream can be run on the Raspberry Pi 3 and Raspbian Jessie; find out how in this tutorial. Special thanks to the users chinlock and Ralf, who gave very good tips in their comments!

Setup the camera
Attach the camera and enable it with

(see tutorial camera module for more info on the camera module)

Install the dependencies
Open a terminal, then enter all of this. Yes, this will take a while…

Install caffe
Enter

In the now open file, replace the lines

with

Save, then enter in the terminal

and add at the end of the file the line

Protobuf installation
Enter in the terminal

In the now-open .bashrc add at the end of the file

Save, then type in the terminal

(google_test produces some errors, but runs through)

PsyCam
Boot the Raspberry Pi into the terminal (the graphical Desktop would take too much RAM), then install and run the PsyCam by entering

This will make a single snapshot. Add a -c and the camera will make snapshots repeatedly.

Links
camera module tutorial: http://www.knight-of-pi.org/raspberry-pi-camera-and-night-vision-with-pinoir
DeepDream Wiki: https://en.wikipedia.org/wiki/DeepDream

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.

24 Comments

  1. Amazing work, thank you.. but:


    $ python psycam.py
    Traceback (most recent call last):
    File “psycam.py”, line 16, in
    import caffe
    File “/home/pi/deepdream/caffe/python/caffe/__init__.py”, line 1, in
    from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
    File “/home/pi/deepdream/caffe/python/caffe/pycaffe.py”, line 15, in
    import caffe.io
    File “/home/pi/deepdream/caffe/python/caffe/io.py”, line 8, in
    from caffe.proto import caffe_pb2
    File “/home/pi/deepdream/caffe/python/caffe/proto/caffe_pb2.py”, line 23, in
    x10\n\x05scale\x18\x11 \x01(\x02:\x01\x31\x12\x10\n\x08meanfile\x18\x12 \x01(\t\x12\x11\n\tbatchsize\x18\x13 \x01(\r\x12\x13\n\x08\x63ropsize\x18\x14 \x01(\r:\x01\x30\x12\x15\n\x06mirror\x18\x15 \x01(\x08:\x05\x66\x61lse\x12\x1f\n\x05\x62lobs\x18\x32 \x03(\x0b\x32\x10.caffe.BlobProto\x12\x10\n\x08\x62lobs_lr\x18\x33 \x03(\x02\x12\x14\n\x0cweight_decay\x18\x34 \x03(\x02\x12\x14\n\trand_skip\x18\x35 \x01(\r:\x01\x30\x12\x1d\n\x10\x64\x65t_fg_threshold\x18\x36 \x01(\x02:\x03\x30.5\x12\x1d\n\x10\x64\x65t_bg_threshold\x18\x37 \x01(\x02:\x03\x30.5\x12\x1d\n\x0f\x64\x65t_fg_fraction\x18\x38 \x01(\x02:\x04\x30.25\x12\x1a\n\x0f\x64\x65t_context_pad\x18: \x01(\r:\x01\x30\x12\x1b\n\rdet_crop_mode\x18; \x01(\t:\x04warp\x12\x12\n\x07new_num\x18 \x01(\x05:\x01\x30\x12\x14\n\tnew_width\x18? \x01(\x05:\x01\x30\x12\x1d\n\x0eshuffle_images\x18@ \x01(\x08:\x05\x66\x61lse\x12\x15\n\nconcat_dim\x18\x41 \x01(\r:\x01\x31\x12\x36\n\x11hdf5_output_param\x18\xe9\x07 \x01(\x0b\x32\x1a.caffe.HDF5OutputParameter\”.\n\nPoolMethod\x12\x07\n\x03MAX\x10\x00\x12\x07\n\x03\x41VE\x10\x01\x12\x0e\n\nSTOCHASTIC\x10\x02\”W\n\x0ePReLUParameter\x12&\n\x06\x66iller\x18\x01 \x01(\x0b\x32\x16.caffe.FillerParameter\x12\x1d\n\x0e\x63hannel_shared\x18\x02 \x01(\x08:\x05\x66\x61lse*\x1c\n\x05Phase\x12\t\n\x05TRAIN\x10\x00\x12\x08\n\x04TEST\x10\x01′)
    TypeError: __init__() got an unexpected keyword argument ‘syntax’

    Raspbian GNU/Linux 10 \n \l

    • Hey,

      did you try the installation under Raspbian Jessie? I really haven’t tried to install it for a more recent version of Raspbian.
      I think i’ve read something that they’ve updated the Caffe library, but i really can’t look into it right now.
      Probably your best chance is installing Raspbian Jessie freshly on a SD card and then try the automated installation you’ll find in this edition of MagPi (p. 52).

      Hope this helps!

  2. I fixed the typeError by commenting out all lines
    syntax=proto2

    The psycam.py now works – sort of
    I get the following output
    /usr/lib/python2.7/dist-packages/scipy/ndimage/interpolation.py:568: Userwarning: from SciPy 0.13.0, the output shape of zoom() is calculated with round() instead of int() – for these inputs the size of the array has changed.

    “the returned array has changed.”, UserWarning

    And it is taking what feels like FOREVER. How long should this take on a pi3?

    • That depends on the image size and layer depth. Mostly 5-20 minutes. I also didn’t test this on the newest RPi3. You could experiment with using more cores for this. Others recommended that but i didn’t try.

      • how do i tell python to use more cores
        python psycam.py -j4

        ?

  3. python camtest.py gives the error

    picamera not found.

    This was fixed with

    pip install “picamera[array]”

  4. I followed the whole tutorial and everything went as expected until the last two lines
    python psycam.py –help
    python psycam.py

    TypeError: _init_() got an unexpected keyword argument ‘syntax’

    The file giving the error is
    /home/pi/deepdream/caffe/python/caffe/proto/caffe_pb2.py , line 23

    help?

  5. Hello, i’ve installed caffe as it’s shown, but when i try to import caffe in a python code, it can’t find the library installed. Any suggestion of how can i fix this? Tnks!

    • Hey Joao,

      did you perform the installation for Raspbian Jessie?
      Didn’t install protobuf, but the installation seemed to work so far…
      For Stretch, strict use of pip2 and python2 might help.

      De nada!

  6. How can I use deep dream on a raspberry pi without a camera? I should be able to manually supply an image.

  7. When I put this ” ./scripts/download_model_binary.py models/bvlc_googlenet ” in the terminal it tells me that there is no module named yaml.

    Any ideas how to fix that??

  8. Any chance in heck that Deep Dream or PsyCam can run on a Zero W? The form factor of the Zero W with the official red/white case (w/ camera-friendly lid) is fantastic for photography projects, so DD/PsyCam would be awesome for it. I know they were compatible with RPi 2, but the Zero W’s specs are just below that. Is it worth spending a day trying to give it a shot, or is it just wasted energy?

    • I’m pretty sure it would be wasted energy! DD runs barely on a Raspberry Pi 2, and even on the RPi3 it only allows low image sizes.
      But you could flatten a Pi3 by desoldering the GPIO and the other connectors…

  9. Excellent, well-polished tutorial and program! Very awesome concept! Finished the installation just now. Bought my first Pi for this.

    • Sam, that’s great!

      I wish you plenty of fun with the Raspberry Pi.
      Feel free to drop me a message if you build something cool.

  10. Also if you add the switch -j you can select the number of cores used by make. example make all -j4. if you are over clocking or are running a damageed/not to speck cpu it might fail…

  11. why are we expected to compile such a tool train it on infections deficiency it will make the sighs easier to see. this will help doctors and farmers learn from AI findings.

    • Yes! DeepDream is a result of experiments for examining neural network behaviour/learning. The concept has many potential uses.

Comment

Time limit is exhausted. Please reload CAPTCHA.