Skip to main content

PyTorch based library focused on data processing and input pipelines in general.

Project description

  • Use map, apply, reduce or filter directly on Dataset objects
  • cache data in RAM/disk or via your own method (partial caching supported)
  • Full PyTorch's Dataset and IterableDataset support
  • General torchdata.maps like Flatten or Select
  • Extensible interface (your own cache methods, cache modifiers, maps etc.)
  • Useful torchdata.datasets classes designed for general tasks (e.g. file reading)
  • Support for torchvision datasets (e.g. ImageFolder, MNIST, CIFAR10) via td.datasets.WrapDataset
  • Minimal overhead (single call to super().__init__())
Version Docs Tests Coverage Style PyPI Python PyTorch Docker Roadmap
Version Documentation Tests Coverage codebeat PyPI Python PyTorch Docker Roadmap

:bulb: Examples

Check documentation here: https://szymonmaszke.github.io/torchdata

General example

  • Create image dataset, convert it to Tensors, cache and concatenate with smoothed labels:
import torchdata as td
import torchvision

class Images(td.Dataset): # Different inheritance
    def __init__(self, path: str):
        super().__init__() # This is the only change
        self.files = [file for file in pathlib.Path(path).glob("*")]

    def __getitem__(self, index):
        return Image.open(self.files[index])

    def __len__(self):
        return len(self.files)


images = Images("./data").map(torchvision.transforms.ToTensor()).cache()

You can concatenate above dataset with another (say labels) and iterate over them as per usual:

for data, label in images | labels:
    # Do whatever you want with your data
  • Cache first 1000 samples in memory, save the rest on disk in folder ./cache:
images = (
    ImageDataset.from_folder("./data").map(torchvision.transforms.ToTensor())
    # First 1000 samples in memory
    .cache(td.modifiers.UpToIndex(1000, td.cachers.Memory()))
    # Sample from 1000 to the end saved with Pickle on disk
    .cache(td.modifiers.FromIndex(1000, td.cachers.Pickle("./cache")))
    # You can define your own cachers, modifiers, see docs
)

To see what else you can do please check torchdata documentation

Integration with torchvision

Using torchdata you can easily split torchvision datasets and apply augmentation only to the training part of data without any troubles:

import torchvision

import torchdata as td

# Wrap torchvision dataset with WrapDataset
dataset = td.datasets.WrapDataset(torchvision.datasets.ImageFolder("./images"))

# Split dataset
train_dataset, validation_dataset, test_dataset = torch.utils.data.random_split(
    model_dataset,
    (int(0.6 * len(dataset)), int(0.2 * len(dataset)), int(0.2 * len(dataset))),
)

# Apply torchvision mappings ONLY to train dataset
train_dataset.map(
    td.maps.To(
        torchvision.transforms.Compose(
            [
                torchvision.transforms.RandomResizedCrop(224),
                torchvision.transforms.RandomHorizontalFlip(),
                torchvision.transforms.ToTensor(),
                torchvision.transforms.Normalize(
                    mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
                ),
            ]
        )
    ),
    # Apply this transformation to zeroth sample
    # First sample is the label
    0,
)

Please notice you can use td.datasets.WrapDataset with any existing torch.utils.data.Dataset instance to give it additional caching and mapping powers!

:wrench: Installation

:snake: pip

Latest release:

pip install --user torchdata

Nightly:

pip install --user torchdata-nightly

:whale2: Docker

CPU standalone and various versions of GPU enabled images are available at dockerhub.

For CPU quickstart, issue:

docker pull szymonmaszke/torchdata:18.04

Nightly builds are also available, just prefix tag with nightly_. If you are going for GPU image make sure you have nvidia/docker installed and it's runtime set.

:question: Contributing

If you find any issue or you think some functionality may be useful to others and fits this library, please open new Issue or create Pull Request.

To get an overview of thins one can do to help this project, see Roadmap

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

torchdatasets-0.2.0.tar.gz (26.3 kB view details)

Uploaded Source

Built Distribution

torchdatasets-0.2.0-py3-none-any.whl (29.5 kB view details)

Uploaded Python 3

File details

Details for the file torchdatasets-0.2.0.tar.gz.

File metadata

  • Download URL: torchdatasets-0.2.0.tar.gz
  • Upload date:
  • Size: 26.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for torchdatasets-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3a6f51c3cc89b190a0745bb2dfa7723394c4605d45a3f78d98e806b3618b433c
MD5 ca73bf1066c9cafae78a1b8a26154bfe
BLAKE2b-256 2aa8dea414bf0de7e48167722d0133d6f4b4d27813f11b457f83f15b0076161d

See more details on using hashes here.

File details

Details for the file torchdatasets-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: torchdatasets-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for torchdatasets-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a96f8628c25d308642252d4eb80249345d8c9e6501deae015b116776ff91385
MD5 5381b9cb08039b335303f2dc6e58e4b7
BLAKE2b-256 55d8640f1b2415b5b3c4b656e3f162d439aeac7130fd48141ca2d83e3493b60b

See more details on using hashes here.

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