Skip to main content

Opinionated declarative utility library for writing PyTorch dataset classes

Project description

What is it?

Opinionated declarative utility library for writing dataset classes. Intended for small pytorch experiments.

Rationale

Pytorch dataset loading often involves certain common tasks:

  • Load tensors or values from a filelist
  • Truncate sequence/spatial dims to a maximum length
  • Drop items that don't satisfy particular requirements
  • Pad sequence/spatial dims to a multiple of a number or a maximum per-batch length
  • Pad sequence/spatial dims in groups across multiple data fields in a batch
  • Or (on training datasets only) randomly subsample sequence/spatial dims to meet a maximum length constraint, and add a "length" field for the pre-padding lengths
  • Apply data augmentations

Implementing these tasks is often highly repetitive and error prone.

Dataset loading code can be further simplified by making certain assumptions:

  • All data to be loaded takes the form of either a literal or a single file tensor which can be loaded from disk.
  • Each dataset class takes only one filelist.
  • Filelists contain only paths to tensors or python literals (such as class IDs).

Example usage

We use an example a 3-column dataset specified as a filelist:

# filelist.txt
test/test_files/tensor1_0.pt|test/test_files/tensor2_0.pt|0
test/test_files/tensor1_1.pt|test/test_files/tensor2_1.pt|1
test/test_files/tensor1_2.pt|test/test_files/tensor2_2.pt|2

When creating a dt.Dataset we specify names and datatypes for the columns in order.

import datatia as dt
dataset = dt.Dataset(filelist='filelist.txt',
    field_specs=[
        dt.FieldSpec(name='tensor1', datatype=torch.Tensor),
        dt.FieldSpec(name='tensor2', datatype=torch.Tensor),
        dt.FieldSpec(name='id', datatype=int),
    ],
    actions=[dt.PadGroup(fields=['tensor1', 'tensor2'], 
        dims=[0, 1], values=[0, 0], to_multiple=[4, 5])])
loader = dataset.loader(batch_size=4)
batch = next(iter(loader))

The PadGroup action pads dimensions within a group of tensor columns for a batch to either the next largest common multiple of a number (to_multiple), to a fixed length (to_length), or to the maximum size of the dimensions within the batch.

See datatia/actions.py for other actions (Truncate, Drop, PreMap, LiveMapRow, RandomSubsample, PadGroup) and datatia/datatia.py for FieldSpec and dt.Dataset API.

Action order

Actions may be provided to the API in any order, but they are always executed in a predefined order:

When the dataset initializes:

  • Truncate
  • PreMap (only works on in-memory tensors)
  • Drop Before collation:
  • LiveMapRow
  • RandomSubsample During collation:
  • PadGroup

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

datatia-0.4.4.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

datatia-0.4.4-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file datatia-0.4.4.tar.gz.

File metadata

  • Download URL: datatia-0.4.4.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for datatia-0.4.4.tar.gz
Algorithm Hash digest
SHA256 187e942ee469049495620507fd4a5164ac6b7cc5396d2429b7e9c2e651f6d1cc
MD5 e9399f17f5f2f9e3be9379a0845185b5
BLAKE2b-256 4bf4ff11ce5da1db53c67a59e5eb20237f55a02a9734c0fd87c31cfd5db1b9c1

See more details on using hashes here.

File details

Details for the file datatia-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: datatia-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for datatia-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f8048cade882c5b5b24e1fd1bd8bff15412d0b7fa9fc96be824abf770b21a54f
MD5 d42e8406328f03ed6b7e1456ab83451f
BLAKE2b-256 cdbf8a3090d717be2dd3f200d761eca185354b6e91cc4403d1fc4c43c80b740f

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