<s> """<STR_LIT>""" <EOL> import itertools <EOL> import numpy <EOL> from pylearn2 . datasets import preprocessing <EOL> from pylearn2 . utils import serial <EOL> from pylearn2 . datasets import dense_design_matrix <EOL> from pylearn2 . utils . rng import make_np_rng <EOL> from pylearn2 . datasets . vector_spaces_dataset import VectorSpacesDataset <EOL> from pylearn2 . space import VectorSpace , CompositeSpace , Conv2DSpace <EOL> def generate ( opc ) : <EOL> """<STR_LIT>""" <EOL> dim = <NUM_LIT> <EOL> reg = <NUM_LIT> <EOL> total = <NUM_LIT> <EOL> im1 = numpy . zeros ( ( total , reg , reg , <NUM_LIT:1> ) , dtype = '<STR_LIT>' ) <EOL> im2 = numpy . zeros ( ( total , reg , reg , <NUM_LIT:1> ) , dtype = '<STR_LIT>' ) <EOL> Y = numpy . zeros ( ( total , <NUM_LIT:1> ) , dtype = '<STR_LIT>' ) <EOL> rng = make_np_rng ( <NUM_LIT> , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , which_method = "<STR_LIT>" ) <EOL> transformation = opc <EOL> if transformation == '<STR_LIT>' : <EOL> shifts = list ( itertools . product ( range ( - <NUM_LIT:3> , <NUM_LIT:4> ) , range ( - <NUM_LIT:3> , <NUM_LIT:4> ) ) ) <EOL> t = <NUM_LIT:0> <EOL> while t < total : <EOL> x = rng . uniform ( <NUM_LIT:0> , <NUM_LIT:1> , ( dim , dim ) ) <EOL> x = numpy . ceil ( x * <NUM_LIT:255> ) <EOL> im_x = x [ <NUM_LIT:3> : <NUM_LIT:16> , <NUM_LIT:3> : <NUM_LIT:16> ] [ : , : , None ] <EOL> ind = rng . randint ( <NUM_LIT:0> , len ( shifts ) ) <EOL> Y [ t ] = ind <EOL> txy = shifts [ ind ] <EOL> tx , ty = txy <EOL> im_y = x [ ( <NUM_LIT:3> + tx ) : ( <NUM_LIT:16> + tx ) , ( <NUM_LIT:3> + ty ) : ( <NUM_LIT:16> + ty ) ] [ : , : , None ] <EOL> im1 [ t , : ] = im_x <EOL> im2 [ t , : ] = im_y <EOL> t += <NUM_LIT:1> <EOL> else : <EOL> assert transformation == '<STR_LIT>' <EOL> import Image <EOL> angs = numpy . linspace ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) <EOL> t = <NUM_LIT:0> <EOL> while t < total : <EOL> x = rng . uniform ( <NUM_LIT:0> , <NUM_LIT:1> , ( dim , dim ) ) <EOL> x = numpy . ceil ( x * <NUM_LIT:255> ) <EOL> im_x = x [ <NUM_LIT:3> : <NUM_LIT:16> , <NUM_LIT:3> : <NUM_LIT:16> ] [ : , : , None ] <EOL> ind = rng . randint ( <NUM_LIT:0> , len ( angs ) ) <EOL> Y [ t ] = ind <EOL> ang = angs [ ind ] <EOL> y = numpy . asarray ( Image . fromarray ( x ) . rotate ( ang ) ) <EOL> im_y = y [ <NUM_LIT:3> : <NUM_LIT:16> , <NUM_LIT:3> : <NUM_LIT:16> ] [ : , : , None ] <EOL> im1 [ t , : ] = im_x <EOL> im2 [ t , : ] = im_y <EOL> t += <NUM_LIT:1> <EOL> view_converter = dense_design_matrix . DefaultViewConverter ( ( reg , reg , <NUM_LIT:1> ) ) <EOL> design_X = view_converter . topo_view_to_design_mat ( im1 ) <EOL> design_Y = view_converter . topo_view_to_design_mat ( im2 ) <EOL> pipeline = preprocessing . Pipeline ( ) <EOL> gcn = preprocessing . GlobalContrastNormalization ( <EOL> sqrt_bias = <NUM_LIT> , use_std = True ) <EOL> pipeline . items . append ( gcn ) <EOL> XY = numpy . concatenate ( ( design_X , design_Y ) , <NUM_LIT:0> ) <EOL> XY_ImP = dense_design_matrix . DenseDesignMatrix ( X = XY ) <EOL> XY_ImP . apply_preprocessor ( preprocessor = pipeline , can_fit = True ) <EOL> X1 = XY_ImP . X [ <NUM_LIT:0> : design_X . shape [ <NUM_LIT:0> ] , : ] <EOL> X2 = XY_ImP . X [ design_X . shape [ <NUM_LIT:0> ] : , : ] <EOL> topo_X1 = view_converter . design_mat_to_topo_view ( X1 ) <EOL> topo_X2 = view_converter . design_mat_to_topo_view ( X2 ) <EOL> axes = ( '<STR_LIT:b>' , <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT:c>' ) <EOL> data_specs = ( CompositeSpace ( <EOL> [ Conv2DSpace ( ( reg , reg ) , num_channels = <NUM_LIT:1> , axes = axes ) , <EOL> Conv2DSpace ( ( reg , reg ) , num_channels = <NUM_LIT:1> , axes = axes ) , <EOL> VectorSpace ( <NUM_LIT:1> ) ] ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> train = VectorSpacesDataset ( ( topo_X1 , topo_X2 , Y ) , data_specs = data_specs ) <EOL> import os <EOL> save_path = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> serial . save ( os . path . join ( save_path , '<STR_LIT>' ) , train ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> generate ( '<STR_LIT>' ) </s>
