<s> import os <EOL> import h5py <EOL> from scipy . io import loadmat <EOL> from fuel . converters . base import fill_hdf5_file , MissingInputFiles <EOL> def convert_silhouettes ( size , directory , output_directory , <EOL> output_file = None ) : <EOL> """<STR_LIT>""" <EOL> if size not in ( <NUM_LIT:16> , <NUM_LIT> ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if output_file is None : <EOL> output_file = '<STR_LIT>' . format ( size ) <EOL> output_file = os . path . join ( output_directory , output_file ) <EOL> input_file = '<STR_LIT>' . format ( size ) <EOL> input_file = os . path . join ( directory , input_file ) <EOL> if not os . path . isfile ( input_file ) : <EOL> raise MissingInputFiles ( '<STR_LIT>' , [ input_file ] ) <EOL> with h5py . File ( output_file , mode = "<STR_LIT:w>" ) as h5file : <EOL> mat = loadmat ( input_file ) <EOL> train_features = mat [ '<STR_LIT>' ] . reshape ( [ - <NUM_LIT:1> , <NUM_LIT:1> , size , size ] ) <EOL> train_targets = mat [ '<STR_LIT>' ] <EOL> valid_features = mat [ '<STR_LIT>' ] . reshape ( [ - <NUM_LIT:1> , <NUM_LIT:1> , size , size ] ) <EOL> valid_targets = mat [ '<STR_LIT>' ] <EOL> test_features = mat [ '<STR_LIT>' ] . reshape ( [ - <NUM_LIT:1> , <NUM_LIT:1> , size , size ] ) <EOL> test_targets = mat [ '<STR_LIT>' ] <EOL> data = ( <EOL> ( '<STR_LIT:train>' , '<STR_LIT>' , train_features ) , <EOL> ( '<STR_LIT:train>' , '<STR_LIT>' , train_targets ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , valid_features ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , valid_targets ) , <EOL> ( '<STR_LIT:test>' , '<STR_LIT>' , test_features ) , <EOL> ( '<STR_LIT:test>' , '<STR_LIT>' , test_targets ) , <EOL> ) <EOL> fill_hdf5_file ( h5file , data ) <EOL> for i , label in enumerate ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:width>' ) ) : <EOL> h5file [ '<STR_LIT>' ] . dims [ i ] . label = label <EOL> for i , label in enumerate ( ( '<STR_LIT>' , '<STR_LIT:index>' ) ) : <EOL> h5file [ '<STR_LIT>' ] . dims [ i ] . label = label <EOL> return ( output_file , ) <EOL> def fill_subparser ( subparser ) : <EOL> """<STR_LIT>""" <EOL> subparser . add_argument ( <EOL> "<STR_LIT:size>" , type = int , choices = ( <NUM_LIT:16> , <NUM_LIT> ) , <EOL> help = "<STR_LIT>" ) <EOL> return convert_silhouettes </s>
