<s> """<STR_LIT>""" <EOL> import os <EOL> import tensorflow as tf <EOL> import input_data <EOL> tf . app . flags . DEFINE_string ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> tf . app . flags . DEFINE_integer ( '<STR_LIT>' , <NUM_LIT> , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> FLAGS = tf . app . flags . FLAGS <EOL> def _int64_feature ( value ) : <EOL> return tf . train . Feature ( int64_list = tf . train . Int64List ( value = [ value ] ) ) <EOL> def _bytes_feature ( value ) : <EOL> return tf . train . Feature ( bytes_list = tf . train . BytesList ( value = [ value ] ) ) <EOL> def convert_to ( images , labels , name ) : <EOL> num_examples = labels . shape [ <NUM_LIT:0> ] <EOL> print ( '<STR_LIT>' , labels . shape [ <NUM_LIT:0> ] ) <EOL> if images . shape [ <NUM_LIT:0> ] != num_examples : <EOL> raise ValueError ( "<STR_LIT>" % <EOL> ( images . shape [ <NUM_LIT:0> ] , num_examples ) ) <EOL> rows = images . shape [ <NUM_LIT:1> ] <EOL> cols = images . shape [ <NUM_LIT:2> ] <EOL> depth = images . shape [ <NUM_LIT:3> ] <EOL> filename = os . path . join ( FLAGS . directory , name + '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' , filename ) <EOL> writer = tf . python_io . TFRecordWriter ( filename ) <EOL> for index in range ( num_examples ) : <EOL> image_raw = images [ index ] . tostring ( ) <EOL> example = tf . train . Example ( features = tf . train . Features ( feature = { <EOL> '<STR_LIT>' : _int64_feature ( rows ) , <EOL> '<STR_LIT:width>' : _int64_feature ( cols ) , <EOL> '<STR_LIT>' : _int64_feature ( depth ) , <EOL> '<STR_LIT:label>' : _int64_feature ( int ( labels [ index ] ) ) , <EOL> '<STR_LIT>' : _bytes_feature ( image_raw ) } ) ) <EOL> writer . write ( example . SerializeToString ( ) ) <EOL> def main ( argv ) : <EOL> train_images = input_data . read_images_from ( ) <EOL> train_labels = input_data . read_labels_from ( ) <EOL> print ( train_images . shape ) <EOL> validation_images = train_images [ : FLAGS . validation_size , : , : , : ] <EOL> validation_labels = train_labels [ : FLAGS . validation_size ] <EOL> train_images = train_images [ FLAGS . validation_size : , : , : , : ] <EOL> train_labels = train_labels [ FLAGS . validation_size : ] <EOL> convert_to ( train_images , train_labels , '<STR_LIT:train>' ) <EOL> convert_to ( validation_images , validation_labels , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> tf . app . run ( ) </s>
