def cifar10_patches(data_set='cifar-10'):
    """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"""
    dir_path = os.path.join(data_path, data_set)
    filename = os.path.join(dir_path, 'cifar-10-python.tar.gz')
    if not data_available(data_set):
        download_data(data_set)
        import tarfile
        # This code is from Boris Babenko's blog post.
        # http://bbabenko.tumblr.com/post/86756017649/learning-low-level-vision-feautres-in-10-lines-of-code
        tfile = tarfile.open(filename, 'r:gz')
        tfile.extractall(dir_path)

    with open(os.path.join(dir_path, 'cifar-10-batches-py','data_batch_1'),'rb') as f:
        data = pickle.load(f)

    images = data['data'].reshape((-1,3,32,32)).astype('float32')/255
    images = np.rollaxis(images, 1, 4)
    patches = np.zeros((0,5,5,3))
    for x in range(0,32-5,5):
        for y in range(0,32-5,5):
            patches = np.concatenate((patches, images[:,x:x+5,y:y+5,:]), axis=0)
    patches = patches.reshape((patches.shape[0],-1))
    return data_details_return({'Y': patches, "info" : "32x32 pixel patches extracted from the CIFAR-10 data by Boris Babenko to demonstrate k-means features."}, data_set)
def cifar10_patches ( data_set = 'cifar-10' ) : dir_path = os . path . join ( data_path , data_set ) filename = os . path . join ( dir_path , 'cifar-10-python.tar.gz' ) if not data_available ( data_set ) : download_data ( data_set ) import tarfile tfile = tarfile . open ( filename , 'r:gz' ) tfile . extractall ( dir_path ) with open ( os . path . join ( dir_path , 'cifar-10-batches-py' , 'data_batch_1' ) , 'rb' ) as f : data = pickle . load ( f ) images = data [ 'data' ] . reshape ( ( - 1 , 3 , 32 , 32 ) ) . astype ( 'float32' ) / 255 images = np . rollaxis ( images , 1 , 4 ) patches = np . zeros ( ( 0 , 5 , 5 , 3 ) ) for x in range ( 0 , 32 - 5 , 5 ) : for y in range ( 0 , 32 - 5 , 5 ) : patches = np . concatenate ( ( patches , images [ : , x : x + 5 , y : y + 5 , : ] ) , axis = 0 ) patches = patches . reshape ( ( patches . shape [ 0 ] , - 1 ) ) return data_details_return ( { 'Y' : patches , "info" : "32x32 pixel patches extracted from the CIFAR-10 data by Boris Babenko to demonstrate k-means features." } , data_set )
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