tfrecord-lite

raw JSON →
0.0.8 verified Sat May 09 auth: no python

A lightweight tfrecord parser that reads TensorFlow TFRecord files without requiring TensorFlow. Version 0.0.8 supports Python >=3.6 and provides both low-level reading and higher-level dataset creation.

pip install tfrecord-lite
error ModuleNotFoundError: No module named 'tensorflow'
cause You are trying to import tfrecord_lite.data.TFRecordDataset which requires TensorFlow.
fix
Install TensorFlow: pip install tensorflow, or avoid using TFRecordDataset and use tf_record_iterator instead.
error TypeError: a bytes-like object is required, not 'str'
cause You passed a string to TFRecordWriter.write() instead of bytes.
fix
Encode string: writer.write('data'.encode())
gotcha TFRecordWriter.write expects bytes, not str. If you pass a string, it will fail with TypeError.
fix Encode strings to bytes: writer.write('text'.encode())
gotcha tf_record_iterator yields raw bytes records. It does NOT decode TensorFlow Example protos automatically.
fix Use decode_example from tfrecord_lite to parse Example protos.
deprecated There is no deprecated API in current version. However, note that TFRecordLoader is no longer present in recent versions; it was renamed to decode_example.
fix Use decode_example instead of TFRecordLoader.

Basic read/write operations using tfrecord-lite.

import tfrecord_lite

# Write a TFRecord file
writer = tfrecord_lite.TFRecordWriter('example.tfrecord')
writer.write(b'Hello, world!')
writer.close()

# Read back with iterator
for record in tfrecord_lite.tf_record_iterator('example.tfrecord'):
    print(record)  # b'Hello, world!'

# Decode TFRecord with TensorFlow proto (requires numpy)
from tfrecord_lite import decode_example
# Assuming you have an Example proto bytes
# example_bytes = ...
# result = decode_example(example_bytes)  # returns dict of numpy arrays