# HG changeset patch # User James Bergstra # Date 1256251996 14400 # Node ID 3c1fb6f14a14f2f39d5e7165980e02836450c4f0 # Parent d7ee9c906d7eb8bc3878bb6ecc40f819304e20d4 moved COIL100 code to sandbox diff -r d7ee9c906d7e -r 3c1fb6f14a14 pylearn/dataset_ops/COIL100.py --- a/pylearn/dataset_ops/COIL100.py Thu Oct 22 18:52:47 2009 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ - -""" -http://www1.cs.columbia.edu/CAVE/software/softlib/coil-100.php - -"Columbia Object Image Library (COIL-100)," - S. A. Nene, S. K. Nayar and H. Murase, - Technical Report CUCS-006-96, February 1996. - -""" - -import os, cPickle -import Image, numpy -from pylearn.datasets.config import data_root # config - -from .memo import memo - -def filenames(): - root = os.path.join(data_root(), 'COIL-100', 'coil-100', ) - for filename in os.listdir(root): - yield filename, os.path.join(root,filename ) - -def filenameidx_imgidx(filename): - if filename.startswith("obj"): - obj_idx = int(filename[3:filename.index("_")]) - img_idx = int(filename[filename.index("_")+2:filename.index(".")]) - return obj_idx, img_idx - else: - raise ValueError(filename) - -_32x32grey_path = os.path.join(data_root(), "COIL-100", "dct_32x32_grey.pkl") -_32x32grey_header = "Dictionary of COIL-100 dataset at 32x32 resolution, greyscale" -def build_32x32_grey(): - f = file(_32x32grey_path, "w") - cPickle.dump(_32x32grey_header, f, protocol=cPickle.HIGHEST_PROTOCOL) - - dct = {} - for filename, fullname in filenames(): - if filename.startswith('obj'): - obj_idx, img_idx = filenameidx_imgidx(filename) - img = numpy.asarray(Image.open(fullname)) - dct.setdefault(obj_idx, {})[img_idx] = img.mean(axis=2)[::4,::4] - rval = numpy.empty((100, 72, 32, 32), dtype='float32') - rval[...] = -1 - for obj_id, dd in dct.iteritems(): - for img_id, v in dd.iteritems(): - rval[obj_id, img_id, :, :] = v - assert numpy.all(rval >= 0.0) - - cPickle.dump(rval, f, protocol=cPickle.HIGHEST_PROTOCOL) - f.close() - -@memo -def get_32x32_grey(): - f = file(_path_32x32_grey) - if _32x32grey_header != cPickle.load(f): - raise ValueError('wrong pickle file') - rval = cPickle.load(f) - f.close() - return rval - - - diff -r d7ee9c906d7e -r 3c1fb6f14a14 pylearn/dataset_ops/sandbox/COIL100.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylearn/dataset_ops/sandbox/COIL100.py Thu Oct 22 18:53:16 2009 -0400 @@ -0,0 +1,62 @@ + +""" +http://www1.cs.columbia.edu/CAVE/software/softlib/coil-100.php + +"Columbia Object Image Library (COIL-100)," + S. A. Nene, S. K. Nayar and H. Murase, + Technical Report CUCS-006-96, February 1996. + +""" + +import os, cPickle +import Image, numpy +from pylearn.datasets.config import data_root # config + +from .memo import memo + +def filenames(): + root = os.path.join(data_root(), 'COIL-100', 'coil-100', ) + for filename in os.listdir(root): + yield filename, os.path.join(root,filename ) + +def filenameidx_imgidx(filename): + if filename.startswith("obj"): + obj_idx = int(filename[3:filename.index("_")]) + img_idx = int(filename[filename.index("_")+2:filename.index(".")]) + return obj_idx, img_idx + else: + raise ValueError(filename) + +_32x32grey_path = os.path.join(data_root(), "COIL-100", "dct_32x32_grey.pkl") +_32x32grey_header = "Dictionary of COIL-100 dataset at 32x32 resolution, greyscale" +def build_32x32_grey(): + f = file(_32x32grey_path, "w") + cPickle.dump(_32x32grey_header, f, protocol=cPickle.HIGHEST_PROTOCOL) + + dct = {} + for filename, fullname in filenames(): + if filename.startswith('obj'): + obj_idx, img_idx = filenameidx_imgidx(filename) + img = numpy.asarray(Image.open(fullname)) + dct.setdefault(obj_idx, {})[img_idx] = img.mean(axis=2)[::4,::4] + rval = numpy.empty((100, 72, 32, 32), dtype='float32') + rval[...] = -1 + for obj_id, dd in dct.iteritems(): + for img_id, v in dd.iteritems(): + rval[obj_id, img_id, :, :] = v + assert numpy.all(rval >= 0.0) + + cPickle.dump(rval, f, protocol=cPickle.HIGHEST_PROTOCOL) + f.close() + +@memo +def get_32x32_grey(): + f = file(_path_32x32_grey) + if _32x32grey_header != cPickle.load(f): + raise ValueError('wrong pickle file') + rval = cPickle.load(f) + f.close() + return rval + + +