Studio 6

Google DeepDream Inception Image Processing

INSTALLATION

Installation of Google Deep Dream program is quite complicated. Out of all the methods I tried, docker method is the easiest to understand and implement.

Things to note before we start:

1) During the installation, there could be tons of errors/system issues. (I faced them too, Keep resolving and move on to the next step as this code works!! )

2) Patience is the key. The code itself takes hours to run for all the layers of neural network to work its magic on your image. So, let’s start!

System Requirements:

Note: Docker for Mac will launch only if all of these requirements are met.

◦Mac must be a 2010 or newer model, with Intel’s hardware support for memory management unit (MMU) virtualization; i.e., Extended Page Tables (EPT) and Unrestricted Mode.

◦OS X El Capitan 10.11 and newer macOS releases are supported. At a minimum, Docker for Mac requires macOS Yosemite 10.10.3 or newer, with the caveat that going forward 10.10.x is a use-at-your-own risk proposition.

◦Starting with Docker for Mac Stable release 1.13 (upcoming), and concurrent Edge releases, we will no longer address issues specific to OS X Yosemite 10.10. In future releases, Docker for Mac could stop working on OS X Yosemite 10.10 due to the deprecated status of this OS X version. We recommend upgrading to the latest version of macOS.

◦At least 4GB of RAM

◦VirtualBox prior to version 4.3.30 must NOT be installed (it is incompatible with Docker for Mac)

Note: If your system does not satisfy these requirements, you can install Docker Toolbox, which uses Oracle VirtualBox instead of HyperKit.

◦I faced port connection issue while using safari browser. So, I would recommend you to use Google Chrome for the docker installation.

RESOURCES

Source code if you want to take a look at it: https://github.com/google/deepdream

Documentation for Google Deep Dream Installation. This page has detailed instructions. Read through thoroughly and execute the steps. http://ryankennedy.io/running-the-deep-dream/

Installation Guide for Docker: https://docs.docker.com/docker-for-mac/

Overview of Steps

in case the above documentation is difficult to follow:

1. Download and Install https://download.docker.com/mac/stable/Docker.dmg

2. Open terminal and Run:

docker pull ryankennedyio/deepdream

3. Now we boot the container using this command

docker run -d -p 443:8888 -e "PASSWORD=password" -v /path/to/this/repository:/src ryankennedyio/deepdream

Special note:

path/to/this/repository should be the location where you want to play with input images. In this case, that would be /Users/ryankennedy/Pictures. This directory is being shared with the Docker container, so that you can access your input pictures.

•It could be possible that the port you are trying to access is already allocated. In that case, try using 4430 instead of 443.

•To check port allocation. Type in terminal docker ps

Example :

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f83ecdbb39e2 ryankennedyio/deepdream "/notebook.sh" About an hour ago Up 34 minutes 0.0.0.0:4430->8888/tcp confident_brown

b368985b4ac0 ryankennedyio/deepdream "/notebook.sh" 2 hours ago Up About an hour 0.0.0.0:443->8888/tcp clever_wozniak

Rahuls-Air:Pictures rahulgeorge33$ docker

Usage:docker COMMAND

We see that two ID’s have been created for deepdream f83ecdbb39e2, b368985b4ac0. So, we need to stop one of them so that the docker is allocated to a single port. Below I have stopped both the dockers for fresh install.

docker stop

"docker stop" requires at least 1 argument(s).

See 'docker stop --help'.

Usage: docker stop [OPTIONS] CONTAINER [CONTAINER...]

Stop one or more running containers

docker stop b368985b4ac0

docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

f83ecdbb39e2 ryankennedyio/deepdream "/notebook.sh" About an hour ago Up 36 minutes 0.0.0.0:4430->8888/tcp confident_brown

docker stop f83ecdbb39e2

f83ecdbb39e2

4. Run the command below to boot the container once the ports are correctly allocated.

docker run -d -p 4430:8888 -e "PASSWORD=password" -v //Users/rahulgeorge33/Pictures:/src ryankennedyio/deepdream

5. Once this command has been completed successfully, Open Google Chrome and type in https://localhost:4430/ . This will generate python notebook (dream.ipnyb). Click on this link and you will see chunks of code Google Deep Dream program already imported. Benefit of using Python notebook is that, it is an easier way for execution as you can run the code in chunks as opposed to running 200 lines of code at once.

6. Now we input our image to test the deep dream code. Note: Make sure the path mentioned in the repository is correct and the image is mentioned in the exact folder or the docker will fail to bind. Provide the image name on this line of the code.

Code: img = np.float32(PIL.Image.open('/src/input1.jpg'))

showarray(img)

Replace ‘input1.jpg’ with your ‘image name’.

An example of how the path should be in the repository-

Location at the terminal: //Users/rahulgeorge33/Pictures:/src

showarray(img)

Code: img = np.float32(PIL.Image.open('/src/input1.jpg'))

8. Run every instance (chunk of code) by clicking (Shift + Enter). You will see the processed image with each iteration. It takes quite some time to get the output image so, relax. Grab a coffee, and wait patiently for the deep dream to work. For me, the last iteration of the image took a LONG time (5+ hours). The final result is worth the wait though. To challenge the result further, you can play around with the parameters in the code, get some deep dreaming done and create your own customized images.

Goodluck!