Skip to main content

tfrecords: simplify and transplant the tfrecords

Project description

tfrecords

simplify and transplant the tfrecord dataset

record write and read demo

import tfrecords

options = tfrecords.TFRecordOptions(compression_type=tfrecords.TFRecordCompressionType.NONE)
def test_write(filename, N=3, context='aaa'):
    with tfrecords.TFRecordWriter(filename, options=options) as file_writer:
        for _ in range(N):
            # x, y = np.random.random(), np.random.random()
            file_writer.write(context + '____' + str(_))

def test_record_iterator():
    example_paths = tfrecords.glob('d:/example.tfrecords*')
    for example_path in example_paths:
        iterator = tfrecords.tf_record_iterator(example_path, options=options)
        num = 0
        for iter in iterator:
            num += 1
            print(iter)


def test_random_reader():
    example_paths = tfrecords.glob('d:/example.tfrecords*')
    for example_path in example_paths:
        file_reader = tfrecords.tf_record_random_reader(example_path, options=options)
        last_pos = 0
        while True:
            try:
                x,pos = file_reader.read(last_pos)
                print(x)
                last_pos = pos
            except:
                break

test_write('d:/example.tfrecords0',3,'file0')
test_write('d:/example.tfrecords1',10,'file1')
test_write('d:/example.tfrecords2',12,'file2')


print('\ntest_record_iterator')
test_record_iterator()

print('\ntest_random_reader')
test_random_reader()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

tfrecords-0.0.4-cp310-cp310-win_amd64.whl (958.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

tfrecords-0.0.4-cp310-cp310-manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.10

tfrecords-0.0.4-cp310-cp310-manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.10

tfrecords-0.0.4-cp39-cp39-win_amd64.whl (953.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

tfrecords-0.0.4-cp39-cp39-manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.9

tfrecords-0.0.4-cp39-cp39-manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.9

tfrecords-0.0.4-cp38-cp38-win_amd64.whl (957.9 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

tfrecords-0.0.4-cp38-cp38-manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.8

tfrecords-0.0.4-cp38-cp38-manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.8

tfrecords-0.0.4-cp37-cp37m-win_amd64.whl (957.3 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

tfrecords-0.0.4-cp37-cp37m-manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.7m

tfrecords-0.0.4-cp37-cp37m-manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.7m

tfrecords-0.0.4-cp36-cp36m-win_amd64.whl (957.3 kB view hashes)

Uploaded CPython 3.6m Windows x86-64

tfrecords-0.0.4-cp36-cp36m-manylinux2014_x86_64.whl (2.2 MB view hashes)

Uploaded CPython 3.6m

tfrecords-0.0.4-cp36-cp36m-manylinux2014_aarch64.whl (2.1 MB view hashes)

Uploaded CPython 3.6m

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page