#NEWLINE# def main( ) : #NEWLINE# #INDENT# data_dir = string_utils . preprocess ( '${PYLEARN2_DATA_PATH}/cifar10' ) #NEWLINE# print ( 'Loading CIFAR-10 train dataset...' ) #NEWLINE# train = CIFAR10 ( which_set = 'train' ) #NEWLINE# print ( 'Preparing output directory...' ) #NEWLINE# output_dir = ( data_dir + '/pylearn2_whitened' ) #NEWLINE# serial . mkdir ( output_dir ) #NEWLINE# README = open ( ( output_dir + '/README' ) , 'w' ) #NEWLINE# README . write ( textwrap . dedent ( '\n    The .pkl files in this directory may be opened in python using\n    cPickle, pickle, or pylearn2.serial.load.\n\n    train.pkl, and test.pkl each contain\n    a pylearn2 Dataset object defining a labeled\n    dataset of a 32x32 approximately whitened version of the STL-10\n    dataset. train.pkl contains labeled train examples. test.pkl\n    contains labeled test examples.\n\n    preprocessor.pkl contains a pylearn2 ZCA object that was used\n    to approximately whiten the images. You may want to use this\n    object later to preprocess other images.\n\n    They were created with the pylearn2 script make_cifar10_whitened.py.\n\n    All other files in this directory, including this README, were\n    created by the same script and are necessary for the other files\n    to function correctly.\n    ' ) ) #NEWLINE# README . close ( ) #NEWLINE# print ( 'Learning the preprocessor and preprocessing           the unsupervised train data...' ) #NEWLINE# preprocessor = preprocessing . ZCA ( ) #NEWLINE# train . apply_preprocessor ( preprocessor = preprocessor , can_fit = True ) #NEWLINE# print ( 'Saving the unsupervised data' ) #NEWLINE# train . use_design_loc ( ( output_dir + '/train.npy' ) ) #NEWLINE# serial . save ( ( output_dir + '/train.pkl' ) , train ) #NEWLINE# print ( 'Loading the test data' ) #NEWLINE# test = CIFAR10 ( which_set = 'test' ) #NEWLINE# print ( 'Preprocessing the test data' ) #NEWLINE# test . apply_preprocessor ( preprocessor = preprocessor , can_fit = False ) #NEWLINE# print ( 'Saving the test data' ) #NEWLINE# test . use_design_loc ( ( output_dir + '/test.npy' ) ) #NEWLINE# serial . save ( ( output_dir + '/test.pkl' ) , test ) #NEWLINE# serial . save ( ( output_dir + '/preprocessor.pkl' ) , preprocessor )