Tutorial WALKTHROUGH JOHANNES BERGS Strange critters Johannes Bergs wants to know roam the Earth on more and likes the realm of a chilly winter day humans and machines. knight-of-pi.org

GOOGLE DEEPDREAM ON THE RASPBERRY PI Do computers of electric sheep? Find out by making your You’ll Raspberry Pi dream with the amazing Google DeepDream Need reams can be beautiful, surreal, or even Artificial neurons > Camera Module D scary. While we can assume that they play a Artificial neurons mimic their natural counterparts, magpi.cc/ role in learning, their exact purpose remains the neurons in the human brain. Every artificial 28IjIsz unknown. What would a computer see if it could neuron has an activation threshold and numerous > PsyCam dream? You can find out by installing the amazing weighted incoming and outgoing connections to other magpi.cc/ Google DeepDream software on your Raspberry Pi! neurons. If the sum of the weighted signals from 2eCSQOD DeepDream is derived from a neural network the incoming connections exceeds the activation for object recognition, which has been modified threshold, the neuron fires a signal. to express every object it vaguely recognises. The resulting images are impressively surrealistic, Neural networks RASPBERRY PI 2 bearing more than a passing resemblance to the Generally, neural networks consist of at least three COMPATIBILITY paintings of artists like Salvador Dalí. layers of neurons. The input layer reads the input, one Neural networks are a very versatile technology. or more hidden layers process the information, and Although the They can be applied to a variety of complex problems the output layer shows the result. Pi 3 with its advanced like facial recognition, text translation, or even Consider a neural network for recognising the processing playing games like Go. numbers zero to nine in images with a size of 28×28 power is , the neural network upon which Google built pixels. The input layer would have 784 neurons, one preferable, the project DeepDream, was originally developed for identifying for every pixel. If an image is presented to the input will run on a objects in images. To achieve this, the network is layer, every neuron in it produces a signal with a Pi 2 without trained on a large set of images to identify the main strength corresponding to the greyscale value of its modifications. features of the objects presented. pixel, with a darker pixel generating a stronger signal.

58 January 2017 raspberrypi.org/magpi DEEPDREAMS Tutorial

Have some DeepDreams Language Insert an SD card with Raspbian Jessie installed into >PYTHON the Raspberry Pi, attach the Camera Module and peripherals, then boot it up. To install the DeepDream DOWNLOAD: magpi.cc/2eCSQOD software, enter the following in a Terminal:

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