changeset 1380:785aeb7a4df2

added a fn to datasets/tiny_images to output a mosaic of images from the dataset
author James Bergstra <bergstrj@iro.umontreal.ca>
date Fri, 03 Dec 2010 09:09:00 -0500
parents d90971353e22
children 0673e6af650a
files pylearn/datasets/tinyimages.py
diffstat 1 files changed, 33 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/pylearn/datasets/tinyimages.py	Thu Dec 02 12:46:50 2010 -0500
+++ b/pylearn/datasets/tinyimages.py	Fri Dec 03 09:09:00 2010 -0500
@@ -9,6 +9,8 @@
 import PIL.Image
 import numpy
 
+import pylearn.io.image_tiling
+
 logger = logging.getLogger('pylearn.datasets.tinyimages')
 
 def sorted_listdir(*path):
@@ -61,20 +63,39 @@
         yield it.next()
         i +=1
 
+
+def arrange_first_N_into_tiling(R,C, filename):
+    R=int(R)
+    C=int(C)
+    A = numpy.asarray([i.copy() for i,ii in zip(image_generator(), xrange(R*C))],
+            dtype='float32')
+    print A.shape
+    A.shape = (R*C, 32*32,3)
+    pylearn.io.image_tiling.save_tiled_raster_images(
+        pylearn.io.image_tiling.tile_raster_images(
+            (A[:,:,0], A[:,:,1], A[:,:,2], None),
+            (32,32)),
+        filename)
+
+
 n_images = 1608356 
 
-def main():
-    def iter_len(x):
-        i = 0
-        for xx in x:
-            i += 1
-        return i
-    n_files = iter_len(iterate_over_filenames())
-    print 'got %i files' % n_files
-    assert n_images == n_files
+def main(argv=[]):
+    if argv:
+        arrange_first_N_into_tiling( argv[0], argv[1], argv[2])
+    else:
+        def iter_len(x):
+            i = 0
+            for xx in x:
+                i += 1
+            return i
+        n_files = iter_len(iterate_over_filenames())
+        print 'got %i files' % n_files
+        assert n_images == n_files
 
-    for p in load_first_N(10):
-        load_image(os.path.join(*p))
+        for p in load_first_N(10):
+            load_image(os.path.join(*p))
+
 
 if __name__ == '__main__':
-    sys.exit(main())
+    sys.exit(main(sys.argv[1:]))