Skip to content

Commit 15a2cef

Browse files
committed
Alternative to PIL.image for Mac OS X.
1 parent 4aaaeb1 commit 15a2cef

File tree

7 files changed

+23
-13
lines changed

7 files changed

+23
-13
lines changed

Diff for: code/cA.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
from logistic_sgd import load_data
4343
from utils import tile_raster_images
4444

45-
import PIL.Image
45+
try:
46+
import PIL.Image as Image
47+
except ImportError:
48+
import Image
4649

4750

4851
class cA(object):
@@ -290,7 +293,7 @@ def test_cA(learning_rate=0.01, training_epochs=20,
290293

291294
print >> sys.stderr, ('The code for file ' + os.path.split(__file__)[1] +
292295
' ran for %.2fm' % ((training_time) / 60.))
293-
image = PIL.Image.fromarray(tile_raster_images(
296+
image = Image.fromarray(tile_raster_images(
294297
X=ca.W.get_value(borrow=True).T,
295298
img_shape=(28, 28), tile_shape=(10, 10),
296299
tile_spacing=(1, 1)))

Diff for: code/dA.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
from logistic_sgd import load_data
4646
from utils import tile_raster_images
4747

48-
import PIL.Image
48+
try:
49+
import PIL.Image as Image
50+
except ImportError:
51+
import Image
4952

5053

5154
class dA(object):
@@ -306,7 +309,7 @@ def test_dA(learning_rate=0.1, training_epochs=15,
306309
print >> sys.stderr, ('The no corruption code for file ' +
307310
os.path.split(__file__)[1] +
308311
' ran for %.2fm' % ((training_time) / 60.))
309-
image = PIL.Image.fromarray(
312+
image = Image.fromarray(
310313
tile_raster_images(X=da.W.get_value(borrow=True).T,
311314
img_shape=(28, 28), tile_shape=(10, 10),
312315
tile_spacing=(1, 1)))
@@ -352,7 +355,7 @@ def test_dA(learning_rate=0.1, training_epochs=15,
352355
os.path.split(__file__)[1] +
353356
' ran for %.2fm' % (training_time / 60.))
354357

355-
image = PIL.Image.fromarray(tile_raster_images(
358+
image = Image.fromarray(tile_raster_images(
356359
X=da.W.get_value(borrow=True).T,
357360
img_shape=(28, 28), tile_shape=(10, 10),
358361
tile_spacing=(1, 1)))

Diff for: code/rbm.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import cPickle
88
import gzip
99
import time
10-
import PIL.Image
10+
11+
try:
12+
import PIL.Image as Image
13+
except ImportError:
14+
import Image
1115

1216
import numpy
1317

@@ -396,7 +400,7 @@ def test_rbm(learning_rate=0.1, training_epochs=15,
396400
# Plot filters after each training epoch
397401
plotting_start = time.clock()
398402
# Construct image from the weight matrix
399-
image = PIL.Image.fromarray(tile_raster_images(
403+
image = Image.fromarray(tile_raster_images(
400404
X=rbm.W.get_value(borrow=True).T,
401405
img_shape=(28, 28), tile_shape=(10, 10),
402406
tile_spacing=(1, 1)))
@@ -459,7 +463,7 @@ def test_rbm(learning_rate=0.1, training_epochs=15,
459463
tile_spacing=(1, 1))
460464
# construct image
461465

462-
image = PIL.Image.fromarray(image_data)
466+
image = Image.fromarray(image_data)
463467
image.save('samples.png')
464468
os.chdir('../')
465469

Diff for: code/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def tile_raster_images(X, img_shape, tile_shape, tile_spacing=(0, 0),
4747
4848
4949
:returns: array suitable for viewing as an image.
50-
(See:`PIL.Image.fromarray`.)
50+
(See:`Image.fromarray`.)
5151
:rtype: a 2-d array with same dtype as X.
5252
5353
"""

Diff for: doc/dA.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ save the filters as an image :
588588

589589
.. code-block:: python
590590

591-
image = PIL.Image.fromarray(tile_raster_images(X=da.W.get_value(borrow=True).T,
591+
image = Image.fromarray(tile_raster_images(X=da.W.get_value(borrow=True).T,
592592
img_shape=(28, 28), tile_shape=(10, 10),
593593
tile_spacing=(1, 1)))
594594
image.save('filters_corruption_30.png')

Diff for: doc/rbm.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ been shown to lead to a better generative model ([Tieleman08]_).
754754
# Plot filters after each training epoch
755755
plotting_start = time.clock()
756756
# Construct image from the weight matrix
757-
image = PIL.Image.fromarray(tile_raster_images(
757+
image = Image.fromarray(tile_raster_images(
758758
X=rbm.W.get_value(borrow=True).T,
759759
img_shape=(28, 28), tile_shape=(10, 10),
760760
tile_spacing=(1, 1)))
@@ -841,7 +841,7 @@ samples at every 1000 steps.
841841
tile_spacing=(1, 1))
842842
# construct image
843843

844-
image = PIL.Image.fromarray(image_data)
844+
image = Image.fromarray(image_data)
845845
print ' ... plotting sample ', idx
846846
image.save('samples.png')
847847

Diff for: doc/utilities.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Tiling minibatches together is done for us by the
7878

7979

8080
:returns: array suitable for viewing as an image.
81-
(See:`PIL.Image.fromarray`.)
81+
(See:`Image.fromarray`.)
8282
:rtype: a 2-d array with same dtype as X.
8383

8484
"""

0 commit comments

Comments
 (0)