Skip to content

Commit

Permalink
Removed dependencies on skimage and matplotlib to shrink distribution.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjc committed May 4, 2016
1 parent d5301d9 commit 6ec6557
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 15 additions & 8 deletions doodle.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def error(message, *lines):
os.environ.setdefault('THEANO_FLAGS', 'floatX=float32,device={},force_device=True,'\
'print_active_device=False'.format(args.device))

# Scientific Libraries
# Scientific & Imaging Libraries
import numpy as np
import scipy.optimize
import skimage.transform
import PIL

# Numeric Computing (GPU)
import theano
Expand Down Expand Up @@ -320,23 +320,30 @@ def normalize_components(self, layer, array, norms):
# Initialization & Setup
#------------------------------------------------------------------------------------------------------------------

def rescale_image(self, img, scale):
"""Re-implementing skimage.transform.scale without the extra dependency. Saves a lot of space and hassle!
"""
output = scipy.misc.toimage(img, cmin=0.0, cmax=255)
output.thumbnail((int(output.size[0]*scale), int(output.size[1]*scale)), PIL.Image.ANTIALIAS)
return np.asarray(output)

def prepare_content(self, scale=1.0):
"""Called each phase of the optimization, rescale the original content image and its map to use as inputs.
"""
content_image = skimage.transform.rescale(self.content_img_original, scale) * 255.0
self.content_img = self.model.prepare_image(content_image)
content_img = self.rescale_image(self.content_img_original, scale)
self.content_img = self.model.prepare_image(content_img)

content_map = skimage.transform.rescale(self.content_map_original, scale) * 255.0
content_map = self.rescale_image(self.content_map_original, scale)
self.content_map = content_map.transpose((2, 0, 1))[np.newaxis].astype(np.float32)

def prepare_style(self, scale=1.0):
"""Called each phase of the optimization, process the style image according to the scale, then run it
through the model to extract intermediate outputs (e.g. sem4_1) and turn them into patches.
"""
style_image = skimage.transform.rescale(self.style_img_original, scale) * 255.0
self.style_img = self.model.prepare_image(style_image)
style_img = self.rescale_image(self.style_img_original, scale)
self.style_img = self.model.prepare_image(style_img)

style_map = skimage.transform.rescale(self.style_map_original, scale) * 255.0
style_map = self.rescale_image(self.style_map_original, scale)
self.style_map = style_map.transpose((2, 0, 1))[np.newaxis].astype(np.float32)

# Compile a function to run on the GPU to extract patches for all layers at once.
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
colorama
matplotlib>=1.5
scikit-image>=0.12
Theano>=0.8.1
git+https://github.com/Lasagne/Lasagne.git@0440814#egg=Lasagne==0.2-dev

0 comments on commit 6ec6557

Please sign in to comment.