# HG changeset patch # User James Bergstra # Date 1233780960 18000 # Node ID 4a7d413c3425455149cc50b7c5558fa802cac06d # Parent 546795d7cbaf740f91ae266e4988f1dc5cade455 adding a little hacky script to flickr that renders a few images as png diff -r 546795d7cbaf -r 4a7d413c3425 pylearn/datasets/flickr.py --- 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) + + +