Tutorial
raspberrypi.org/magpi The Official Raspberry Pi Projects Book 133
DEEPDREAMS
Above A magical city in a far-off land
Every input neuron is connected to all neurons of
the first hidden layer, but every connection has a
distinct weight. The higher the weight, the more of
the input neuron’s signal reaches the hidden neuron.
If the total signal strength arriving at a hidden neuron
tops its activation threshold, the hidden neuron fires
a signal to all neurons of the next layer which, in
this simplified example, is the output layer. Again,
the signal intensity depends on the weight of the
connection and the incoming signal strength.
The output layer has one neuron for every object to
be classified, so ten neurons are used to identify the
numbers from zero to nine. If the activation threshold
of an output neuron is surpassed by the weighted
incoming connections, the resulting signal strength is
a measure of confidence in the classification.
Machine learning
The weights and thresholds are initialised randomly,
which can cause very bad classification results.
If an output neuron is activated incorrectly (e.g.
if an image from the training set shows a five, but
the output neuron for two produces a strong signal),
its activation threshold and all the weights of its
incoming connections are adjusted. Then, the error is
propagated back proportionally through all connected
neurons lower in the chain, from the highest hidden
layer down to the input layer. This process is repeated
for all of the images in the training data set until the
results given by the network begin to improve.
Instead of accurately detecting objects in images,
by contrast, DeepDream actually changes the input
image to make it more similar to the objects learned
from the training data.
Imagine a cloud as an input image. Some structure
in the cloud might have a vague similarity to the
features DeepDream associates with a ‘dog-like’
object. If this is the case, the input image is changed
to look more dog-like.
Additionally, DeepDream allows for selection of the
hidden layer depth. Since a layer has more detail the
closer it is to the output level, output images can range
from basic shapes to detailed dream-like creatures.
Have some DeepDreams
Insert an SD card with Raspbian installed into
the Raspberry Pi, attach the Camera Module and
peripherals, then boot it up. To install the DeepDream
software, enter the following in a Terminal:
mkdir ~/deepdream && cd ~/deepdream
git clone https://github.com/JoBergs/PsyCam
cd PsyCam
python install_tools.py packages
python install_tools.py caffe
python install_tools.py protobuf
python install_tools.py camera
sudo reboot
After downloading the project from GitHub, use
the custom installer to first install all packages with
pip or apt-get. Then, install the open-source neural
network framework Caffe. Because speed matters, you
should also install the serial data processor protobuf
from Google. Finally, activate the camera and reboot.
All in all, the installation takes a few hours, so
you’ll need to be patient! The installer should also
work for any newish Ubuntu operating system. If you
encounter problems, try using the manual installation
instructions at magpi.cc/2eCSxDt.
Enter the following, and your Pi can start to dream:
cd ~/deepdream/PsyCam
python psycam.py
The network parameters depth (-d), octave (-o),
and type (-t) are randomized. Add a -c to dream
continuously. Pass -i IMAGE.jpg to use an image
as the base for the dream instead of a snapshot. Find
more information on input arguments by checking the
command-line help:
python psycam.py –help
When the Pi finishes dreaming, the dream and the
original photo are stored in the directory /home/pi/
deepdream/PsyCam/dreams with a timestamp. You
can watch them by opening the directory in the file
browser and double-clicking the image.
Language
>PYTHON
DOWNLOAD:
magpi.cc/2eCSQOD
ORIGINAL
DEEPDREAM
ARTICLE
Have a look at
the amazing
original
article about
DeepDream
by Alexander
Mordvintsev,
Christopher
Olah, and Mike
Tyka here:
magpi.cc/
2eCRHH3
NEURAL
NETWORK
TUTORIAL
If you want to
learn more
about neural
networks,
why not
check out this
interesting and
well-written
introduction
by Michael
Nielsen?:
magpi.cc/
2eCUO1u
KIVY GUI
Try the
powerful
Python GUI
framework
Kivy (kivy.org)
for building
a GUI: it is
slick enough
to embrace
DeepDream.
Alice in a very colourful wonderland