def cifar10_patches(data_set='<STR_LIT>'):
dir_path = os.path.join(data_path, data_set)<EOL>filename = os.path.join(dir_path, '<STR_LIT>')<EOL>if not data_available(data_set):<EOL><INDENT>download_data(data_set)<EOL>import tarfile<EOL>tfile = tarfile.open(filename, '<STR_LIT>')<EOL>tfile.extractall(dir_path)<EOL><DEDENT>with open(os.path.join(dir_path, '<STR_LIT>','<STR_LIT>'),'<STR_LIT:rb>') as f:<EOL><INDENT>data = pickle.load(f)<EOL><DEDENT>images = data['<STR_LIT:data>'].reshape((-<NUM_LIT:1>,<NUM_LIT:3>,<NUM_LIT:32>,<NUM_LIT:32>)).astype('<STR_LIT>')/<NUM_LIT:255><EOL>images = np.rollaxis(images, <NUM_LIT:1>, <NUM_LIT:4>)<EOL>patches = np.zeros((<NUM_LIT:0>,<NUM_LIT:5>,<NUM_LIT:5>,<NUM_LIT:3>))<EOL>for x in range(<NUM_LIT:0>,<NUM_LIT:32>-<NUM_LIT:5>,<NUM_LIT:5>):<EOL><INDENT>for y in range(<NUM_LIT:0>,<NUM_LIT:32>-<NUM_LIT:5>,<NUM_LIT:5>):<EOL><INDENT>patches = np.concatenate((patches, images[:,x:x+<NUM_LIT:5>,y:y+<NUM_LIT:5>,:]), axis=<NUM_LIT:0>)<EOL><DEDENT><DEDENT>patches = patches.reshape((patches.shape[<NUM_LIT:0>],-<NUM_LIT:1>))<EOL>return data_details_return({'<STR_LIT:Y>': patches, "<STR_LIT:info>" : "<STR_LIT>"}, data_set)<EOL>
The Candian Institute for Advanced Research 10 image data set. Code for loading in this data is taken from this Boris Babenko's blog post, original code available here: http://bbabenko.tumblr.com/post/86756017649/learning-low-level-vision-feautres-in-10-lines-of-code