(data_set, name)
Converts a dataset to tfrecords.
Converts a dataset to tfrecords.
Converts a dataset to tfrecords .
def conver_to_tfrecords(data_set, name):
  """Converts a dataset to tfrecords."""
  if not os.path.exists(RECORD_DIR):
      os.makedirs(RECORD_DIR)
  filename = os.path.join(RECORD_DIR, name)
  print('>> Writing', filename)
  writer = tf.python_io.TFRecordWriter(filename)
  num_examples = len(data_set)
  for index in range(num_examples):
    image = data_set[index][0]
    height = image.shape[0]
    width = image.shape[1]
    image_raw = image.tostring()
    label = data_set[index][1]
    label_raw = label_to_one_hot(label).tostring()
    example = tf.train.Example(features=tf.train.Features(feature={
        'height': _int64_feature(height),
        'width': _int64_feature(width),
        'label_raw': _bytes_feature(label_raw),
        'image_raw': _bytes_feature(image_raw)}))
    writer.write(example.SerializeToString())
  writer.close()
  print('>> Writing Done!')
def conver_to_tfrecords ( data_set , name ) : if not os . path . exists ( RECORD_DIR ) : os . makedirs ( RECORD_DIR ) filename = os . path . join ( RECORD_DIR , name ) print ( '>> Writing' , filename ) writer = tf . python_io . TFRecordWriter ( filename ) num_examples = len ( data_set ) for index in range ( num_examples ) : image = data_set [ index ] [ 0 ] height = image . shape [ 0 ] width = image . shape [ 1 ] image_raw = image . tostring ( ) label = data_set [ index ] [ 1 ] label_raw = label_to_one_hot ( label ) . tostring ( ) example = tf . train . Example ( features = tf . train . Features ( feature = { 'height' : _int64_feature ( height ) , 'width' : _int64_feature ( width ) , 'label_raw' : _bytes_feature ( label_raw ) , 'image_raw' : _bytes_feature ( image_raw ) } ) ) writer . write ( example . SerializeToString ( ) ) writer . close ( ) print ( '>> Writing Done!' )