├── .gitignore
├── Dockerfile
├── README.md
├── deepdream
├── deepdream.py
├── favicon.ico
├── index.html
├── inputs
│ └── .gitkeep
├── make_json.sh
├── outputs
│ └── .gitkeep
├── process_images.sh
├── process_images_once.sh
├── scripts
│ ├── angular-deckgrid.js
│ ├── angular-deckgrid.min.js
│ ├── app.js
│ ├── controllers
│ │ ├── home.js
│ │ └── home.js~
│ ├── directives
│ │ └── imageloaded.js
│ └── vendor
│ │ ├── angular-route.min.js
│ │ ├── angular.min.js
│ │ └── lodash.min.js
├── serve_files.sh
├── settings.json
├── styles
│ ├── images
│ │ └── spinner.gif
│ ├── main.css
│ └── vendor
│ │ └── hint.css
└── templates
│ ├── deckgrid-card.html
│ └── home.html
├── deepdream_vision_ai_screenshot.png
├── deepdream_vision_ai_screenshot2.png
├── deepdream_vision_ai_screenshot3.png
├── enter.sh
├── start.sh
├── stop.sh
└── youtube.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | tmp
2 | inputs
3 | outputs
4 | tmp.prototxt
5 | log.html
6 | input.jpg
7 | output.jpg
8 | images.json
9 | *.mp4
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:14.04
2 |
3 |
4 | ENV PYTHONPATH /opt/caffe/python
5 |
6 | # Add caffe binaries to path
7 | ENV PATH $PATH:/opt/caffe/.build_release/tools
8 |
9 | # Get dependencies
10 | RUN apt-get update && apt-get install -y \
11 | bc \
12 | cmake \
13 | curl \
14 | gcc-4.6 \
15 | g++-4.6 \
16 | gcc-4.6-multilib \
17 | g++-4.6-multilib \
18 | gfortran \
19 | git \
20 | libprotobuf-dev \
21 | libleveldb-dev \
22 | libsnappy-dev \
23 | libopencv-dev \
24 | libboost-all-dev \
25 | libhdf5-serial-dev \
26 | liblmdb-dev \
27 | libjpeg62 \
28 | libfreeimage-dev \
29 | libatlas-base-dev \
30 | pkgconf \
31 | protobuf-compiler \
32 | python-dev \
33 | python-pip \
34 | unzip \
35 | wget \
36 | python-numpy \
37 | python-scipy \
38 | python-pandas \
39 | python-sympy \
40 | python-nose
41 |
42 | # Use gcc 4.6
43 | RUN update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-4.6 30 && \
44 | update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-4.6 30 && \
45 | update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 30 && \
46 | update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 30
47 |
48 |
49 |
50 | # Clone the Caffe repo
51 | RUN cd /opt && git clone https://github.com/BVLC/caffe.git
52 |
53 |
54 | # Glog
55 | RUN cd /opt && wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz && \
56 | tar zxvf glog-0.3.3.tar.gz && \
57 | cd /opt/glog-0.3.3 && \
58 | ./configure && \
59 | make && \
60 | make install
61 |
62 | # Workaround for error loading libglog:
63 | # error while loading shared libraries: libglog.so.0: cannot open shared object file
64 | # The system already has /usr/local/lib listed in /etc/ld.so.conf.d/libc.conf, so
65 | # running `ldconfig` fixes the problem (which is simpler than using $LD_LIBRARY_PATH)
66 | # TODO: looks like this needs to be run _every_ time a new docker instance is run,
67 | # so maybe LD_LIBRARY_PATh is a better approach (or add call to ldconfig in ~/.bashrc)
68 | RUN ldconfig
69 |
70 | # Gflags
71 | RUN cd /opt && \
72 | wget https://github.com/schuhschuh/gflags/archive/master.zip && \
73 | unzip master.zip && \
74 | cd /opt/gflags-master && \
75 | mkdir build && \
76 | cd /opt/gflags-master/build && \
77 | export CXXFLAGS="-fPIC" && \
78 | cmake .. && \
79 | make VERBOSE=1 && \
80 | make && \
81 | make install
82 |
83 | # Build Caffe core
84 | RUN cd /opt/caffe && \
85 | cp Makefile.config.example Makefile.config && \
86 | echo "CPU_ONLY := 1" >> Makefile.config && \
87 | echo "CXX := /usr/bin/g++-4.6" >> Makefile.config && \
88 | sed -i 's/CXX :=/CXX ?=/' Makefile && \
89 | make all
90 |
91 | # Add ld-so.conf so it can find libcaffe.so
92 | #ADD caffe-ld-so.conf /etc/ld.so.conf.d/
93 |
94 | # Run ldconfig again (not sure if needed)
95 | RUN ldconfig
96 |
97 | # Install python deps
98 | RUN cd /opt/caffe && \
99 | (pip install -r python/requirements.txt)
100 |
101 | # Numpy include path hack - github.com/BVLC/caffe/wiki/Setting-up-Caffe-on-Ubuntu-14.04
102 | #RUN NUMPY_EGG=`ls /usr/local/lib/python2.7/dist-packages | grep -i numpy` && \
103 | # ln -s /usr/local/lib/python2.7/dist-packages/$NUMPY_EGG/numpy/core/include/numpy /usr/include/python2.7/numpy
104 |
105 | # Build Caffe python bindings
106 | RUN cd /opt/caffe && make pycaffe
107 |
108 |
109 | # Make + run tests
110 | RUN cd /opt/caffe && make test && make runtest
111 |
112 | #Download GoogLeNet
113 | RUN /opt/caffe/scripts/download_model_binary.py /opt/caffe/models/bvlc_googlenet
114 |
115 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dockerized deepdream: Generate ConvNet Art in the Cloud
2 |
3 | Google recently released the
4 | [deepdream](https://github.com/google/deepdream) software package for generating images like
5 |
6 | 
7 |
8 | which uses the [Caffe](http://caffe.berkeleyvision.org/) Deep Learning
9 | Library and a cool iPython notebook example.
10 |
11 | Setting up Caffe, Python, and all of the required dependencies is not
12 | trivial if you haven't done it before! More importantly, a GPU isn't
13 | required if you're willing to wait a couple of seconds for the images
14 | to be generated.
15 |
16 | Let's make it brain-dead simple to launch your very own
17 | deepdreaming server (in the cloud, on an Ubuntu machine, Mac via
18 | Docker, and maybe even Windows if you try out Kitematic by Docker)!
19 |
20 | ### Motivation
21 |
22 | I decided to create a self-contained Caffe+GoogLeNet+Deepdream Docker image
23 | which has everything you need to generate your own deepdream art. In
24 | order to make the Docker image very portable, it uses the CPU version
25 | of Caffe and comes bundled with the GoogLeNet model.
26 |
27 | The compilation procedure was done on Docker Hub and for advanced
28 | users, the final image can be pulled down via:
29 |
30 | ```
31 | docker pull visionai/clouddream
32 | ```
33 |
34 | The docker image is 2.5GB, but it contains a precompiled version of
35 | Caffe, all of the python dependencies, as well as the pretrained
36 | GoogLeNet model.
37 |
38 | For those of you who are new to Docker, I hope you will pick up some
39 | valuable engineering skills and tips along the way. Docker makes it very easy
40 | to bundle complex software. If you're somebody like me who likes a
41 | clean Mac OS X on a personal laptop, and do the heavy-lifting in the
42 | cloud, then read on.
43 |
44 | # Instructions
45 |
46 | We will be monitoring the `inputs` directory for source images and
47 | dumping results into the `outputs` directory. Nginx (also inside a
48 | Docker container) will be used to serve the resulting files and a
49 | simple AngularJS GUI to render the images in a webpage.
50 |
51 | Prerequisite:
52 |
53 | You've launched a Cloud instance using a VPS provider like
54 | DigitalOcean and this instance has Docker running. If you don't know
55 | about DigitalOcean, then you should give them a try. You can lauch a
56 | Docker-ready cloud instance in a few minutes. If you're going to set
57 | up a new DigitalOcean account, consider using my referral link:
58 | [https://www.digitalocean.com/?refcode=64f90f652091](https://www.digitalocean.com/?refcode=64f90f652091).
59 |
60 | Will need an instance with at least 1GB of RAM for processing small output images.
61 |
62 | Let's say our cloud instance is at the address 1.2.3.4 and we set it
63 | up so that it contains our SSH key for passwordless log-in.
64 |
65 | ```
66 | ssh root@1.2.3.4
67 | git clone https://github.com/VISIONAI/clouddream.git
68 | cd clouddream
69 | ./start.sh
70 | ```
71 |
72 | To make sure everything is working properly you can do
73 | ```
74 | docker ps
75 | ```
76 |
77 | You should see three running containers: deepdream-json, deepdream-compute, and deepdream-files
78 | ```
79 | root@deepdream:~/clouddream# docker ps
80 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
81 | 21d495211abf ubuntu:14.04 "/bin/bash -c 'cd /o 7 minutes ago Up 7 minutes deepdream-json
82 | 7dda17dafa5a visionai/clouddream "/bin/bash -c 'cd /o 7 minutes ago Up 7 minutes deepdream-compute
83 | 010427d8c7c2 nginx "nginx -g 'daemon of 7 minutes ago Up 7 minutes 0.0.0.0:80->80/tcp, 443/tcp deepdream-files
84 | ```
85 |
86 | If you want to stop the processing, just run:
87 | ```
88 | ./stop.sh
89 | ```
90 |
91 | If you want to jump inside the container to debug something, just run:
92 | ```
93 | ./enter.sh
94 | cd /opt/deepdream
95 | python deepdream.py
96 | #This will take input.jpg, run deepdream, and write output.jpg
97 | ```
98 |
99 | ## Feeding images into deepdream
100 |
101 | From your local machine you can just scp images into the `inputs`
102 | directory inside deepdream as follows:
103 |
104 | ```
105 | # From your local machine
106 | scp images/*jpg root@1.2.3.4:~/clouddream/deepdream/inputs/
107 | ```
108 |
109 | ## Instructions for Mac OS X and boot2docker
110 |
111 | First, install boot2docker. Now start boot2docker.
112 |
113 | ```
114 | boot2docker start
115 | ```
116 |
117 |
118 | My boot2docker on Mac returns something like this:
119 | ```
120 | Waiting for VM and Docker daemon to start...
121 | .............o
122 | Started.
123 | Writing /Users/tomasz/.boot2docker/certs/boot2docker-vm/ca.pem
124 | Writing /Users/tomasz/.boot2docker/certs/boot2docker-vm/cert.pem
125 | Writing /Users/tomasz/.boot2docker/certs/boot2docker-vm/key.pem
126 |
127 | To connect the Docker client to the Docker daemon, please set:
128 | export DOCKER_TLS_VERIFY=1
129 | export DOCKER_HOST=tcp://192.168.59.103:2376
130 | export DOCKER_CERT_PATH=/Users/tomasz/.boot2docker/certs/boot2docker-vm
131 | ```
132 |
133 | So I simply paste the last three lines (the ones starting with export)
134 | right into the terminal.
135 | ```
136 | export DOCKER_TLS_VERIFY=1
137 | export DOCKER_HOST=tcp://192.168.59.103:2376
138 | export DOCKER_CERT_PATH=/Users/tomasz/.boot2docker/certs/boot2docker-vm
139 | ```
140 |
141 | Keep this IP address in mind. For me it is `192.168.59.103`.
142 |
143 | NOTE: if running a `docker ps` command fails at this point and it says
144 | something about certificates, you can try:
145 | ```
146 | boot2docker ssh sudo /etc/init.d/docker restart
147 | ```
148 |
149 | Now proceed just like you're in a Linux environment.
150 |
151 | ```
152 | cd ~/projects
153 | git clone https://github.com/VISIONAI/clouddream.git
154 | cd clouddream
155 | ./start.sh
156 | ```
157 |
158 | You should now be able to visit `http://192.168.59.103` in your browser.
159 |
160 | ## Processing a YouTube video
161 |
162 | If don't have your own source of cool jpg images to process, or simply
163 | want to see what the output looks like on a youtube video, I've
164 | included a short `youtube.sh` script which does all the work for you.
165 |
166 | If you want to start processing the "Charlie Bit My Finger" video, simply run:
167 | ```
168 | ./youtube.sh https://www.youtube.com/watch?v=DDZQAJuB3rI
169 | ```
170 |
171 | And then visit the `http://1.2.3.4:8000` URL to see the frames show up
172 | as they are being processed one by one. The final result will be
173 | writen to `http://1.2.3.4/out.mp4`
174 |
175 | Here are some frames from the
176 | [Daft Punk - Pentatonix](https://www.youtube.com/watch?v=3MteSlpxCpo)
177 | video:
178 |
179 | 
180 |
181 |
182 | ## Navigating the Image Gallery
183 |
184 | You should now be able to visit `http://1.2.3.4` in your browser and
185 | see the resulting images appear in a nicely formatted mobile-ready grid.
186 |
187 | You can also show only `N` images by changing to the URL so something like this:
188 | ```
189 | http://1.2.3.4/#/?N=20
190 | ```
191 |
192 | And instead of showing random `N` images, you can view the latest images:
193 | ```
194 | http://1.2.3.4/#/?latest
195 | ```
196 |
197 | You can view the processing log here:
198 | ```
199 | http://1.2.3.4/log.html
200 | ```
201 |
202 | You can view the current image being processed:
203 | ```
204 | http://1.2.3.4/input.jpg
205 | ```
206 |
207 | You can view the current settings:
208 | ```
209 | http://1.2.3.4/settings.json
210 | ```
211 |
212 |
213 | Here is a screenshot of what things should look like when using the 'conv2/3x3' setting:
214 | 
215 |
216 | And if you instead use the 'inception_4c/output' setting:
217 | 
218 |
219 | Additionally, you can browse some more cool images on the
220 | [deepdream.vision.ai](http://deepdream.vision.ai) server, which I've
221 | currently configured to run deepdream through some Dali art. When you
222 | go to the page, just hit refresh to see more goodies.
223 |
224 | ### User contributed DeepDream images
225 |
226 | Several people ran their own experiments on different images and
227 | different layers. For example, GitHub user
228 | [ihaventkilledanybodysince1984](https://github.com/ihaventkilledanybodysince1984)
229 | shows an example of different layer effects on a frog drawing.
230 |
231 | 
232 |
233 | Check out the [frog face effect gallery on imgur](http://imgur.com/a/yMCGZ).
234 |
235 |
236 | ### Changing image size and processing layer
237 |
238 | Inside deepdream/settings.json you'll find a settings file that looks like this:
239 | ```javascript
240 | {
241 | "maxwidth" : 400,
242 | "layer" : "inception_4c/output"
243 | }
244 | ```
245 |
246 | You can change `maxwidth` to something larger like 1000 if you want
247 | big output images for big input images, remeber that will you need more RAM memory
248 | for processing lager images. For testing `maxwidth` of 200
249 | will give you results much faster. If you change the settings and
250 | want to regenerate outputs for your input images, simply remove the
251 | contents of the outputs directory:
252 |
253 | ```
254 | rm deepdream/outputs/*
255 | ```
256 |
257 | Possible values for `layer` are as follows. They come from the
258 | tmp.prototxt file which lists the layers of the GoogLeNet network used
259 | in this demo. Note that the ReLU and Dropout layers are not valid for deepdreaming.
260 |
261 | ```
262 | "conv1/7x7_s2"
263 | "pool1/3x3_s2"
264 | "pool1/norm1"
265 | "conv2/3x3_reduce"
266 | "conv2/3x3"
267 | "conv2/norm2"
268 | "pool2/3x3_s2"
269 | "inception_3a/1x1"
270 | "inception_3a/3x3_reduce"
271 | "inception_3a/3x3"
272 | "inception_3a/5x5_reduce"
273 | "inception_3a/5x5"
274 | "inception_3a/pool"
275 | "inception_3a/pool_proj"
276 | "inception_3a/output"
277 | "inception_3b/1x1"
278 | "inception_3b/3x3_reduce"
279 | "inception_3b/3x3"
280 | "inception_3b/5x5_reduce"
281 | "inception_3b/5x5"
282 | "inception_3b/pool"
283 | "inception_3b/pool_proj"
284 | "inception_3b/output"
285 | "pool3/3x3_s2"
286 | "inception_4a/1x1"
287 | "inception_4a/3x3_reduce"
288 | "inception_4a/3x3"
289 | "inception_4a/5x5_reduce"
290 | "inception_4a/5x5"
291 | "inception_4a/pool"
292 | "inception_4a/pool_proj"
293 | "inception_4a/output"
294 | "inception_4b/1x1"
295 | "inception_4b/3x3_reduce"
296 | "inception_4b/3x3"
297 | "inception_4b/5x5_reduce"
298 | "inception_4b/5x5"
299 | "inception_4b/pool"
300 | "inception_4b/pool_proj"
301 | "inception_4b/output"
302 | "inception_4c/1x1"
303 | "inception_4c/3x3_reduce"
304 | "inception_4c/3x3"
305 | "inception_4c/5x5_reduce"
306 | "inception_4c/5x5"
307 | "inception_4c/pool"
308 | "inception_4c/pool_proj"
309 | "inception_4c/output"
310 | "inception_4d/1x1"
311 | "inception_4d/3x3_reduce"
312 | "inception_4d/3x3"
313 | "inception_4d/5x5_reduce"
314 | "inception_4d/5x5"
315 | "inception_4d/pool"
316 | "inception_4d/pool_proj"
317 | "inception_4d/output"
318 | "inception_4e/1x1"
319 | "inception_4e/3x3_reduce"
320 | "inception_4e/3x3"
321 | "inception_4e/5x5_reduce"
322 | "inception_4e/5x5"
323 | "inception_4e/pool"
324 | "inception_4e/pool_proj"
325 | "inception_4e/output"
326 | "pool4/3x3_s2"
327 | "inception_5a/1x1"
328 | "inception_5a/3x3_reduce"
329 | "inception_5a/3x3"
330 | "inception_5a/5x5_reduce"
331 | "inception_5a/5x5"
332 | "inception_5a/pool"
333 | "inception_5a/pool_proj"
334 | "inception_5a/output"
335 | "inception_5b/1x1"
336 | "inception_5b/3x3_reduce"
337 | "inception_5b/3x3"
338 | "inception_5b/5x5_reduce"
339 | "inception_5b/5x5"
340 | "inception_5b/pool"
341 | "inception_5b/pool_proj"
342 | "inception_5b/output"
343 | ```
344 |
345 | ### The GUI
346 |
347 | The final GUI is based on https://github.com/akoenig/angular-deckgrid.
348 |
349 | ### Credits
350 |
351 | The included Dockerfile is an extended version of
352 | https://github.com/taras-sereda/docker_ubuntu_caffe
353 |
354 | Which is a modification from the original Caffe CPU master Dockerfile tleyden:
355 | https://github.com/tleyden/docker/tree/master/caffe/cpu/master
356 |
357 | This dockerfile uses the deepdream code from:
358 | https://github.com/google/deepdream
359 |
360 | ### License
361 |
362 | MIT License. Have fun. Never stop learning.
363 |
364 | --Enjoy!
365 | The vision.ai team
366 |
367 |
368 |
--------------------------------------------------------------------------------
/deepdream/deepdream.py:
--------------------------------------------------------------------------------
1 | # imports and basic notebook setup
2 | from cStringIO import StringIO
3 | import numpy as np
4 | import scipy.ndimage as nd
5 | import PIL.Image
6 | import json
7 | from IPython.display import clear_output, Image, display
8 | from google.protobuf import text_format
9 |
10 | import caffe
11 |
12 | def showarray(a, fmt='jpeg'):
13 | a = np.uint8(np.clip(a, 0, 255))
14 | f = StringIO()
15 | PIL.Image.fromarray(a).save(f, fmt)
16 | display(Image(data=f.getvalue()))
17 |
18 | with open("settings.json") as json_file:
19 | json_data = json.load(json_file)
20 | #print()
21 |
22 |
23 | model_path = '../caffe/models/bvlc_googlenet/' # substitute your path here
24 | net_fn = model_path + 'deploy.prototxt'
25 | param_fn = model_path + 'bvlc_googlenet.caffemodel'
26 |
27 | # Patching model to be able to compute gradients.
28 | # Note that you can also manually add "force_backward: true" line to "deploy.prototxt".
29 | model = caffe.io.caffe_pb2.NetParameter()
30 | text_format.Merge(open(net_fn).read(), model)
31 | model.force_backward = True
32 | open('tmp.prototxt', 'w').write(str(model))
33 |
34 | net = caffe.Classifier('tmp.prototxt', param_fn,
35 | mean = np.float32([104.0, 116.0, 122.0]), # ImageNet mean, training set dependent
36 | channel_swap = (2,1,0)) # the reference model has channels in BGR order instead of RGB
37 |
38 | # a couple of utility functions for converting to and from Caffe's input image layout
39 | def preprocess(net, img):
40 | return np.float32(np.rollaxis(img, 2)[::-1]) - net.transformer.mean['data']
41 | def deprocess(net, img):
42 | return np.dstack((img + net.transformer.mean['data'])[::-1])
43 |
44 | def make_step(net, step_size=1.5, end='inception_4c/output', jitter=32, clip=True):
45 | '''Basic gradient ascent step.'''
46 |
47 | src = net.blobs['data'] # input image is storred in Net's 'data' blob
48 | dst = net.blobs[end]
49 |
50 | ox, oy = np.random.randint(-jitter, jitter+1, 2)
51 | src.data[0] = np.roll(np.roll(src.data[0], ox, -1), oy, -2) # apply jitter shift
52 |
53 | net.forward(end=end)
54 | dst.diff[:] = dst.data # specify the optimiation objective
55 | net.backward(start=end)
56 | g = src.diff[0]
57 | # apply normaized ascent step to the input image
58 | src.data[:] += step_size/np.abs(g).mean() * g
59 |
60 | src.data[0] = np.roll(np.roll(src.data[0], -ox, -1), -oy, -2) # unshift image
61 |
62 | if clip:
63 | bias = net.transformer.mean['data']
64 | src.data[:] = np.clip(src.data, -bias, 255-bias)
65 |
66 | def deepdream(net, base_img, iter_n=10, octave_n=4, octave_scale=1.4, end='inception_4c/output', clip=True, **step_params):
67 | # prepare base images for all octaves
68 | octaves = [preprocess(net, base_img)]
69 | for i in xrange(octave_n-1):
70 | octaves.append(nd.zoom(octaves[-1], (1, 1.0/octave_scale,1.0/octave_scale), order=1))
71 |
72 | src = net.blobs['data']
73 | detail = np.zeros_like(octaves[-1]) # allocate image for network-produced details
74 | for octave, octave_base in enumerate(octaves[::-1]):
75 | h, w = octave_base.shape[-2:]
76 | if octave > 0:
77 | # upscale details from the previous octave
78 | h1, w1 = detail.shape[-2:]
79 | detail = nd.zoom(detail, (1, 1.0*h/h1,1.0*w/w1), order=1)
80 |
81 | src.reshape(1,3,h,w) # resize the network's input image size
82 | src.data[0] = octave_base+detail
83 | for i in xrange(iter_n):
84 | make_step(net, end=end, clip=clip, **step_params)
85 |
86 | # visualization
87 | vis = deprocess(net, src.data[0])
88 | if not clip: # adjust image contrast if clipping is disabled
89 | vis = vis*(255.0/np.percentile(vis, 99.98))
90 | #showarray(vis)
91 | print octave, i, end, vis.shape
92 | clear_output(wait=True)
93 |
94 | # extract details produced on the current octave
95 | detail = src.data[0]-octave_base
96 | # returning the resulting image
97 | return deprocess(net, src.data[0])
98 |
99 |
100 | maxwidth = json_data['maxwidth']
101 | img = PIL.Image.open('input.jpg')
102 | width = img.size[0]
103 |
104 | if width > maxwidth:
105 | wpercent = (maxwidth/float(img.size[0]))
106 | hsize = int((float(img.size[1])*float(wpercent)))
107 | img = img.resize((maxwidth,hsize), PIL.Image.ANTIALIAS)
108 |
109 | img = np.float32(img)
110 |
111 | frame = img
112 | #frame_i = 0
113 |
114 | frame = deepdream(net, frame, end=json_data['layer'])
115 | #frame = deepdream(net, img, end='inception_3b/5x5_reduce')
116 | #frame = deepdream(net, img, end='conv2/3x3')
117 |
118 | PIL.Image.fromarray(np.uint8(frame)).save("output.jpg")
119 |
120 | #h, w = frame.shape[:2]
121 | #s = 0.05 # scale coefficient
122 | #for i in xrange(100):
123 | # frame = deepdream(net, frame)
124 | # PIL.Image.fromarray(np.uint8(frame)).save("output/%04d.jpg"%frame_i)
125 | # frame = nd.affine_transform(frame, [1-s,1-s,1], [h*s/2,w*s/2,0], order=1)
126 | # frame_i += 1
127 |
--------------------------------------------------------------------------------
/deepdream/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VISIONAI/clouddream/f8c27874a84ffc6622db8837f1babfd6c2e2ff87/deepdream/favicon.ico
--------------------------------------------------------------------------------
/deepdream/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | deepdream.vision.ai
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/deepdream/inputs/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VISIONAI/clouddream/f8c27874a84ffc6622db8837f1babfd6c2e2ff87/deepdream/inputs/.gitkeep
--------------------------------------------------------------------------------
/deepdream/make_json.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Simple script to make an images.json file from the contents of all files
3 | # inside the outputs/ directory
4 | #
5 | # Generate a json file from a directory listing so that it can be consumed by
6 | # $http inside angularjs-deckgrid
7 | # Copyright vision.ai, 2015
8 |
9 | #the amount of time to wait before regenerating images.json
10 | SLEEP_TIME=5
11 |
12 | make_json () {
13 |
14 | cd outputs
15 |
16 | rm ../temp.json 2>/dev/null
17 | touch ../temp.json
18 | chmod 644 ../temp.json
19 | echo -n "[" > ../temp.json
20 |
21 | nfiles=`find . -type f -not -path '*/\.*' | wc -l`
22 | echo nf is $nfiles
23 |
24 | counter=1
25 | find . -type f -not -path '*/\.*' -print0 | while read -d $'\0' f;
26 | do
27 | id=$counter
28 | name=`basename $f`
29 | src="/outputs/$name"
30 | echo -n "{\"id\":\"$id\",\"name\":\"$name\",\"src\":\"$src\"}" >> ../temp.json
31 | if [ "$id" != "$nfiles" ]; then
32 | echo -n "," >> ../temp.json
33 | else
34 | echo "skipping trailing one"
35 | fi
36 | counter=`expr $counter + 1`
37 | done
38 | echo -n "]" >> ../temp.json
39 | mv ../temp.json ../images.json
40 |
41 | cd - 2>&1 /dev/null
42 | echo "Finished processing " `expr $counter - 1` "files"
43 | }
44 |
45 | cd `dirname $0`
46 |
47 |
48 | #Start the infinite for loop which will keep regenerating image.json
49 | while [ true ];
50 | do
51 | echo "Making images.json"
52 | make_json;
53 | sleep ${SLEEP_TIME};
54 | done
55 |
--------------------------------------------------------------------------------
/deepdream/outputs/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VISIONAI/clouddream/f8c27874a84ffc6622db8837f1babfd6c2e2ff87/deepdream/outputs/.gitkeep
--------------------------------------------------------------------------------
/deepdream/process_images.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Simple script to process all of the images inside the inputs/ folder
3 | # We will be running this script inside the visionai/clouddream Docker image
4 | # Copyright vision.ai, 2015
5 |
6 | while [ true ];
7 | do
8 | ./process_images_once.sh
9 | sleep 1
10 | done
11 |
--------------------------------------------------------------------------------
/deepdream/process_images_once.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Simple script to process all of the images inside the inputs/ folder
3 | # We will be running this script inside the visionai/clouddream Docker image
4 | # Copyright vision.ai, 2015
5 |
6 | cd /opt/deepdream/inputs
7 | find . -type f -not -path '*/\.*' -print0 | while read -d $'\0' f;
8 | do
9 | cd /opt/deepdream
10 | if [ -e outputs/${f} ];
11 | then
12 | echo "File ${f} already processed"
13 | else
14 | echo "Deepdream" ${f}
15 | chmod gou+r inputs/${f}
16 | cp inputs/${f} input.jpg
17 | python deepdream.py
18 | ERROR_CODE=$?
19 | echo "Error Code is" ${ERROR_CODE}
20 | cp output.jpg outputs/${f}
21 | rm output.jpg
22 | echo "Just created" outputs/${f}
23 | fi
24 | done
25 |
26 |
27 |
--------------------------------------------------------------------------------
/deepdream/scripts/angular-deckgrid.js:
--------------------------------------------------------------------------------
1 | /*! angular-deckgrid (v0.5.0) - Copyright: 2013 - 2014, André König (andre.koenig@posteo.de) - MIT */
2 | /*
3 | * angular-deckgrid
4 | *
5 | * Copyright(c) 2013-2014 André König
6 | * MIT Licensed
7 | *
8 | */
9 |
10 | /**
11 | * @author André König (andre.koenig@posteo.de)
12 | *
13 | */
14 |
15 | angular.module('akoenig.deckgrid', []);
16 |
17 | angular.module('akoenig.deckgrid').directive('deckgrid', [
18 |
19 | 'DeckgridDescriptor',
20 |
21 | function initialize (DeckgridDescriptor) {
22 |
23 | 'use strict';
24 |
25 | return DeckgridDescriptor.create();
26 | }
27 | ]);
28 | /*
29 | * angular-deckgrid
30 | *
31 | * Copyright(c) 2013-2014 André König
32 | * MIT Licensed
33 | *
34 | */
35 |
36 | /**
37 | * @author André König (andre.koenig@posteo.de)
38 | *
39 | */
40 |
41 | angular.module('akoenig.deckgrid').factory('DeckgridDescriptor', [
42 |
43 | 'Deckgrid',
44 | '$templateCache',
45 |
46 | function initialize (Deckgrid, $templateCache) {
47 |
48 | 'use strict';
49 |
50 | /**
51 | * This is a wrapper around the AngularJS
52 | * directive description object.
53 | *
54 | */
55 | function Descriptor () {
56 | this.restrict = 'AE';
57 |
58 | this.template = '
' +
59 | '' +
60 | '
';
61 |
62 | this.scope = {
63 | 'model': '=source'
64 | };
65 |
66 | //
67 | // Will be created in the linking function.
68 | //
69 | this.$$deckgrid = null;
70 |
71 | this.transclude = true;
72 | this.link = this.$$link.bind(this);
73 |
74 | //
75 | // Will be incremented if using inline templates.
76 | //
77 | this.$$templateKeyIndex = 0;
78 |
79 | }
80 |
81 | /**
82 | * @private
83 | *
84 | * Cleanup method. Will be called when the
85 | * deckgrid directive should be destroyed.
86 | *
87 | */
88 | Descriptor.prototype.$$destroy = function $$destroy () {
89 | this.$$deckgrid.destroy();
90 | };
91 |
92 | /**
93 | * @private
94 | *
95 | * The deckgrid link method. Will instantiate the deckgrid.
96 | *
97 | */
98 | Descriptor.prototype.$$link = function $$link (scope, elem, attrs, nullController, transclude) {
99 | var templateKey = 'deckgrid/innerHtmlTemplate' + (++this.$$templateKeyIndex) + '.html';
100 |
101 | scope.$on('$destroy', this.$$destroy.bind(this));
102 |
103 | if (angular.isUndefined(attrs.cardtemplate)) {
104 | if (angular.isUndefined(attrs.cardtemplatestring)) {
105 | // use the provided inner html as template
106 | transclude(scope, function onTransclude (innerHTML) {
107 | var extractedInnerHTML = [],
108 | i = 0,
109 | len = innerHTML.length,
110 | outerHTML;
111 |
112 | for (i; i < len; i = i + 1) {
113 | outerHTML = innerHTML[i].outerHTML;
114 |
115 | if (angular.isDefined(outerHTML)) {
116 | extractedInnerHTML.push(outerHTML);
117 | }
118 | }
119 |
120 | $templateCache.put(templateKey, extractedInnerHTML.join());
121 | });
122 | } else {
123 | // use the provided template string
124 | //
125 | // note: the attr is accessed via the elem object, as the attrs content
126 | // is already compiled and thus lacks the {{...}} expressions
127 | $templateCache.put(templateKey, elem.attr('cardtemplatestring'));
128 | }
129 |
130 | scope.cardTemplate = templateKey;
131 | } else {
132 | // use the provided template file
133 | scope.cardTemplate = attrs.cardtemplate;
134 | }
135 |
136 | scope.mother = scope.$parent;
137 |
138 | this.$$deckgrid = Deckgrid.create(scope, elem[0]);
139 | };
140 |
141 | return {
142 | create : function create () {
143 | return new Descriptor();
144 | }
145 | };
146 | }
147 | ]);
148 |
149 | /*
150 | * angular-deckgrid
151 | *
152 | * Copyright(c) 2013-2014 André König
153 | * MIT Licensed
154 | *
155 | */
156 |
157 | /**
158 | * @author André König (andre.koenig@posteo.de)
159 | *
160 | */
161 |
162 | angular.module('akoenig.deckgrid').factory('Deckgrid', [
163 |
164 | '$window',
165 | '$log',
166 |
167 | function initialize ($window, $log) {
168 |
169 | 'use strict';
170 |
171 | /**
172 | * The deckgrid directive.
173 | *
174 | */
175 | function Deckgrid (scope, element) {
176 | var self = this,
177 | watcher,
178 | mql;
179 |
180 | this.$$elem = element;
181 | this.$$watchers = [];
182 |
183 | this.$$scope = scope;
184 | this.$$scope.columns = [];
185 |
186 | //
187 | // The layout configuration will be parsed from
188 | // the pseudo "before element." There you have to save all
189 | // the column configurations.
190 | //
191 | this.$$scope.layout = this.$$getLayout();
192 |
193 | this.$$createColumns();
194 |
195 | //
196 | // Register model change.
197 | //
198 | watcher = this.$$scope.$watchCollection('model', this.$$onModelChange.bind(this));
199 |
200 | this.$$watchers.push(watcher);
201 |
202 | //
203 | // Register media query change events.
204 | //
205 | angular.forEach(self.$$getMediaQueries(), function onIteration (rule) {
206 | var handler = self.$$onMediaQueryChange.bind(self);
207 |
208 | function onDestroy () {
209 | rule.removeListener(handler);
210 | }
211 |
212 | rule.addListener(handler);
213 |
214 | self.$$watchers.push(onDestroy);
215 | });
216 |
217 | mql = $window.matchMedia('(orientation: portrait)');
218 | mql.addListener(self.$$onMediaQueryChange.bind(self));
219 |
220 | }
221 |
222 | /**
223 | * @private
224 | *
225 | * Extracts the media queries out of the stylesheets.
226 | *
227 | * This method will fetch the media queries out of the stylesheets that are
228 | * responsible for styling the angular-deckgrid.
229 | *
230 | * @return {array} An array with all respective styles.
231 | *
232 | */
233 | Deckgrid.prototype.$$getMediaQueries = function $$getMediaQueries () {
234 | var stylesheets = [],
235 | mediaQueries = [];
236 |
237 | stylesheets = Array.prototype.concat.call(
238 | Array.prototype.slice.call(document.querySelectorAll('style[type=\'text/css\']')),
239 | Array.prototype.slice.call(document.querySelectorAll('link[rel=\'stylesheet\']'))
240 | );
241 |
242 | function extractRules (stylesheet) {
243 | try {
244 | return (stylesheet.sheet.cssRules || []);
245 | } catch (e) {
246 | return [];
247 | }
248 | }
249 |
250 | function hasDeckgridStyles (rule) {
251 | var regexe = /\[(\w*-)?deckgrid\]::?before/g,
252 | i = 0,
253 | selector = '';
254 |
255 | if (!rule.media || angular.isUndefined(rule.cssRules)) {
256 | return false;
257 | }
258 |
259 | i = rule.cssRules.length - 1;
260 |
261 | for (i; i >= 0; i = i - 1) {
262 | selector = rule.cssRules[i].selectorText;
263 |
264 | if (angular.isDefined(selector) && selector.match(regexe)) {
265 | return true;
266 | }
267 | }
268 |
269 | return false;
270 | }
271 |
272 | angular.forEach(stylesheets, function onIteration (stylesheet) {
273 | var rules = extractRules(stylesheet);
274 |
275 | angular.forEach(rules, function inRuleIteration (rule) {
276 | if (hasDeckgridStyles(rule)) {
277 | mediaQueries.push($window.matchMedia(rule.media.mediaText));
278 | }
279 | });
280 | });
281 |
282 | return mediaQueries;
283 | };
284 |
285 | /**
286 | * @private
287 | *
288 | * Creates the column segmentation. With other words:
289 | * This method creates the internal data structure from the
290 | * passed "source" attribute. Every card within this "source"
291 | * model will be passed into this internal column structure by
292 | * reference. So if you modify the data within your controller
293 | * this directive will reflect these changes immediately.
294 | *
295 | * NOTE that calling this method will trigger a complete template "redraw".
296 | *
297 | */
298 | Deckgrid.prototype.$$createColumns = function $$createColumns () {
299 | var self = this;
300 |
301 | if (!this.$$scope.layout) {
302 | return $log.error('angular-deckgrid: No CSS configuration found (see ' +
303 | 'https://github.com/akoenig/angular-deckgrid#the-grid-configuration)');
304 | }
305 |
306 | this.$$scope.columns = [];
307 |
308 | angular.forEach(this.$$scope.model, function onIteration (card, index) {
309 | var column = (index % self.$$scope.layout.columns) | 0;
310 |
311 | if (!self.$$scope.columns[column]) {
312 | self.$$scope.columns[column] = [];
313 | }
314 |
315 | card.$index = index;
316 | self.$$scope.columns[column].push(card);
317 | });
318 | };
319 |
320 | /**
321 | * @private
322 | *
323 | * Parses the configuration out of the configured CSS styles.
324 | *
325 | * Example:
326 | *
327 | * .deckgrid::before {
328 | * content: '3 .column.size-1-3';
329 | * }
330 | *
331 | * Will result in a three column grid where each column will have the
332 | * classes: "column size-1-3".
333 | *
334 | * You are responsible for defining the respective styles within your CSS.
335 | *
336 | */
337 | Deckgrid.prototype.$$getLayout = function $$getLayout () {
338 | var content = $window.getComputedStyle(this.$$elem, ':before').content,
339 | layout;
340 |
341 | if (content) {
342 | content = content.replace(/'/g, ''); // before e.g. '3 .column.size-1of3'
343 | content = content.replace(/"/g, ''); // before e.g. "3 .column.size-1of3"
344 | content = content.split(' ');
345 |
346 | if (2 === content.length) {
347 | layout = {};
348 | layout.columns = (content[0] | 0);
349 | layout.classList = content[1].replace(/\./g, ' ').trim();
350 | }
351 | }
352 |
353 | return layout;
354 | };
355 |
356 | /**
357 | * @private
358 | *
359 | * Event that will be triggered if a CSS media query changed.
360 | *
361 | */
362 | Deckgrid.prototype.$$onMediaQueryChange = function $$onMediaQueryChange () {
363 | var self = this,
364 | layout = this.$$getLayout();
365 |
366 | //
367 | // Okay, the layout has changed.
368 | // Creating a new column structure is not avoidable.
369 | //
370 | if (layout.columns !== this.$$scope.layout.columns) {
371 | self.$$scope.layout = layout;
372 |
373 | self.$$scope.$apply(function onApply () {
374 | self.$$createColumns();
375 | });
376 | }
377 | };
378 |
379 | /**
380 | * @private
381 | *
382 | * Event that will be triggered when the source model has changed.
383 | *
384 | */
385 | Deckgrid.prototype.$$onModelChange = function $$onModelChange (newModel, oldModel) {
386 | var self = this;
387 |
388 | newModel = newModel || [];
389 | oldModel = oldModel || [];
390 |
391 | if (!angular.equals(oldModel, newModel)) {
392 | self.$$createColumns();
393 | }
394 | };
395 |
396 | /**
397 | * Destroys the directive. Takes care of cleaning all
398 | * watchers and event handlers.
399 | *
400 | */
401 | Deckgrid.prototype.destroy = function destroy () {
402 | var i = this.$$watchers.length - 1;
403 |
404 | for (i; i >= 0; i = i - 1) {
405 | this.$$watchers[i]();
406 | }
407 | };
408 |
409 | return {
410 | create : function create (scope, element) {
411 | return new Deckgrid(scope, element);
412 | }
413 | };
414 | }
415 | ]);
416 |
--------------------------------------------------------------------------------
/deepdream/scripts/angular-deckgrid.min.js:
--------------------------------------------------------------------------------
1 | /*! angular-deckgrid (v0.5.0) - Copyright: 2013 - 2014, André König (andre.koenig@posteo.de) - MIT */
2 | angular.module("akoenig.deckgrid",[]),angular.module("akoenig.deckgrid").directive("deckgrid",["DeckgridDescriptor",function(a){"use strict";return a.create()}]),angular.module("akoenig.deckgrid").factory("DeckgridDescriptor",["Deckgrid","$templateCache",function(a,b){"use strict";function c(){this.restrict="AE",this.template='