TFRecordWriter

class dragon.io.TFRecordWriter(
  path,
  features,
  max_examples=9223372036854775807,
  zfill_width=5
)[source]

Write examples into the TFRecord.

To write the TFRecord, a descriptor is required to describe the features for different examples:

features = "{
    'data': tf.FixedLenFeature([], tf.string, ''),
    'label': tf.VarLenFeature(tf.int64, -1),
}"

Then you should fill a example with features:

example = dragon.io.TFRecordExample()
example.add_strings('data', [img_bytes])
example.add_ints('shape', img_shape)
example.add_ints('label', labels)

Finally, open a writer to write this example:

with dragon.io.TFRecordWriter(path, features) as writer:
    writer.write(example)

For how to fill examples, see dragon.io.TFRecordExample.

__init__

TFRecordWriter.__init__(
  path,
  features,
  max_examples=9223372036854775807,
  zfill_width=5
)[source]

Create a TFRecordWriter.

Parameters:
  • path (str) – The path to write the record file.
  • features (str) – The descriptor for reading.
  • max_examples (int, optional) – The max examples of a single record file.
  • zfill_width (int, optional, default=5) – The width of zfill for naming record files.

Methods

close

TFRecordWriter.close()[source]

Close the file.

write

TFRecordWriter.write(example)[source]

Write a example to the file.

Parameters: