KPLRecordWriter

class dragon.io.KPLRecordWriter(
  path,
  protocol,
  name=None
)[source]

Write examples into the KPLRecord.

To write the KPLRecord, a protocol is required to describe the structure for different examples:

# Nest descriptors can be used: (dict, list)
# Type descriptors can be used: (bytes, float64, int64, string)
my_protocol = {
    'data': 'bytes',
    'shape': ['int64'],
    'object': [{
        'name': 'string',
        'bbox': ['float64'],
    }]
}

Then, you can open a writer to write corresponding examples:

with dragon.io.KPLRecordWriter(path, my_protocol) as writer:
    writer.write({
        'data': image.tostring(),
        'shape': [300, 500, 3],
        'object': [{
            'name': 'cat',
            'bbox': [0., 0., 100., 200.],
        }
    })

For how to read the record file, see dragon.io.KPLRecordDataset.

__init__

KPLRecordWriter.__init__(
  path,
  protocol,
  name=None
)[source]

Create a KPLRecordWriter.

Parameters:
  • path (str) – The path to write the record file.
  • protocol (Union[str, List, Dict]) – The descriptor of example structure.
  • name (str, optional) – The optional dataset name.

Methods

close

KPLRecordWriter.close()[source]

Close the file.

write

KPLRecordWriter.write(example)[source]

Write a example into the file.

Parameters:
  • example (dict) – The data corresponding to protocol.