changeset 648:4a7d413c3425

adding a little hacky script to flickr that renders a few images as png
author James Bergstra <bergstrj@iro.umontreal.ca>
date Wed, 04 Feb 2009 15:56:00 -0500
parents 546795d7cbaf
children c433b9cf9d09
files pylearn/datasets/flickr.py
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/datasets/flickr.py	Wed Feb 04 15:55:19 2009 -0500
+++ b/pylearn/datasets/flickr.py	Wed Feb 04 15:56:00 2009 -0500
@@ -26,6 +26,10 @@
     valid = filetensor.read(open(os.path.join(root, path_valid_10class)))
     test = filetensor.read(open(os.path.join(root, path_test_10class)))
 
+    assert train.shape[1] == 75*75 +1
+    assert valid.shape[1] == 75*75 +1
+    assert test.shape[1] == 75*75 +1
+
     rval = Dataset()
 
     rval.train = Dataset.Obj(
@@ -46,3 +50,22 @@
 def translations_10class():
     raise NotImplementedError('TODO')
 
+
+def render_a_few_images(n=10, prefix='flickr_img', suffix='png'):
+    #TODO: document this and move it to a more common 
+    #      place where other datasets can use it
+    from PIL import Image
+    root = os.path.join(data_root(), 'flickr')
+    valid = filetensor.read(open(os.path.join(root, path_valid_10class)))
+    assert valid.shape == (1000,75*75+1)
+    for i in xrange(n):
+        pixelarray = valid[i,0:-1].reshape((75,75)).T
+        assert numpy.all(pixelarray >= 0)
+        assert numpy.all(pixelarray <= 1)
+
+        pixel_uint8 = numpy.asarray( pixelarray * 255.0, dtype='uint8')
+        im = Image.frombuffer('L', pixel_uint8.shape, pixel_uint8.data, 'raw', 'L', 0, 1)
+        im.save(prefix + str(i) + '.' + suffix)
+        
+
+