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.

import torch
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.5.tar.gz (20.4 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.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (441.1 kB view details)

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

rustfrecord-0.1.5-cp38-abi3-macosx_11_0_arm64.whl (306.2 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for rustfrecord-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b9680a7b7944d6965063dca01b7b2db839dea6a33e3f81e972edd4ab6ed3e081
MD5 efabf1b1104e3cab30f937ef83e6654a
BLAKE2b-256 4154cb6c2cecfa623af3dfd18ecc7dbdd08c37b7d3c1c24f238df53beb1dd9df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustfrecord-0.1.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 566f5deb275485ef40aed0404b4fd2992ed87832e6e3d4871f14bac95c48cd19
MD5 033c0924fe02215c3725683be2c47577
BLAKE2b-256 dda40defe5b9faee40828dc4cccf295f179789dc62955bbd013c8547002dcdb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rustfrecord-0.1.5-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 abe11b4628539ce523f3cff66664cf14464b6d4dcfdfd050f8f722ceb29a4254
MD5 73a59241cac861a3f1ac723e141911c1
BLAKE2b-256 2059351111a001d56317e8fd194086c2f91e72aba917279754877911f0601252

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