Skip to main content

Rust implementation to read TFRecord files into PyTorch tensors

Project description

rustfrecord

The TFRecord format is a simple format for storing a sequence of binary records.

This package implements a high-performance reader for Example records stored in TFRecord files.

Examples are loaded into native PyTorch Tensors.

Installation

The wheel can be installed on any Linux system with Python 3.8 or higher:

pip3 install rustfrecord

Getting Started

The Reader class reads TFRecord files and yields Dict[str, Tensor] objects.

from torch import Tensor
from rustfrecord import Reader

filename = "data/002scattered.training_examples.tfrecord.gz"
r = Reader(filename, compressed=True)

for (i, features) in enumerate(r):
    print(features.keys())
    # ['variant_type', 'image/encoded', 'image/shape',
    #  'variant/encoded', 'label', 'alt_allele_indices/encoded',
    #  'locus', 'sequencing_type']

    label: Tensor = features['label']
    shape = torch.Size(tuple(features['image/shape']))
    image: Tensor = features['image/encoded'][0].reshape(shape)

    print(i, label, image.shape)

Development

To develop this package (not just use it), you need to install the Rust compiler and the Python development headers.

pip install uv
uv venv
source .venv/bin/activate

uv pip compile pyproject.toml -o requirements.txt
uv pip install -r requirements.txt

export LIBTORCH_USE_PYTORCH=1
CARGO_TARGET_DIR=target_maturin maturin develop

python main.py

Project details


Download files

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

Source Distribution

rustfrecord-0.1.4.tar.gz (19.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rustfrecord-0.1.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (436.6 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

rustfrecord-0.1.4-cp38-abi3-macosx_11_0_arm64.whl (302.4 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file rustfrecord-0.1.4.tar.gz.

File metadata

  • Download URL: rustfrecord-0.1.4.tar.gz
  • Upload date:
  • Size: 19.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.5.1

File hashes

Hashes for rustfrecord-0.1.4.tar.gz
Algorithm Hash digest
SHA256 993ab6ab65ff29b935856a9f0668cd8610e48618e3ee20762cc1fc59d4f025fd
MD5 c4f20ac68ef2fd3b0ca376649c5ecc5e
BLAKE2b-256 58936e2a198792f1408e53845e004c1e7b2b9180b317f40baa2b5233a8419745

See more details on using hashes here.

File details

Details for the file rustfrecord-0.1.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rustfrecord-0.1.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5c13be66862043363f576853b0710cbf8c15e806e3acc26d1dee72bf89bedf0
MD5 246c6f6a53bd53f91d108e7fbb787645
BLAKE2b-256 30aefb53028bb87acee97c82ce9ccfdebdda8244f3429c5ef52719c885b41071

See more details on using hashes here.

File details

Details for the file rustfrecord-0.1.4-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rustfrecord-0.1.4-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 115c6264b2b2de1c4cdd1244d884fe3cbd5cf6729ca40d55984a50028f885fb5
MD5 e90d517b4a21d0124b979e4df898e272
BLAKE2b-256 ac0bc598976376203f48b82485c8be23c0c0bd02a1d5833d8b731b70d8d1eeb9

See more details on using hashes here.

Supported by

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