Skip to main content

Utilities to load and use pytorch datasets stored in Minio S3

Project description

Torch Dataset Utilities

The python library torchdatasetutils produces torch DataLoader classes and utility functions for several imaging datasets. This currently includes sets of images and annotations from CVAT, COCO dataset. "torchdatasetutil" uses an s3 object storage to hold dataset data. This enables training and test to be performed on nodes different from where the dataset is stored with application defined credentials. It uses torch PyTorch worker threads to prefetch data for efficient GPU or CPU training and inference.

"torchdatasetutils" takes as an input the pymlutil.s3 object to access the object storage.

Two json or yaml dictionaries are loaded from the object storage to identify and process the dataset: the dataset description and class dictionary. The the dataset description is unique for each type of dataset. The class dictionary is common to all datasets and describes data transformation and data augmentation.

Library structure

See torchdatasetutil.ipynb for library interface and usage

Class Dictionary

COCO Dataset

To load coco dataset you must have a credentials yaml file identifying the final s3 location and credentials for the dataset with the following keys:

s3:
- name: store
  type: trainer
  address: <address>:<port>
  access key: <access key>
  secret key: <secret key>
  tls: false
  cert verify: false
  cert path: null
  sets:
    dataset: {"bucket":"imgml","prefix":"data", "dataset_filter":"" }
    trainingset: {"bucket":"imgml","prefix":"training", "dataset_filter":"" }
    model: {"bucket":"imgml","prefix":"model", "dataset_filter":"" }
    test: {"bucket":"imgml","prefix":"test", "dataset_filter":"" }

Call torchdatasetutil.getcoco to retrieve the COCO dataset and stage it into object storage

python3 -m torchdatasetutil.getcoco

To train with the coco dataset, first create dataset loaders

from torchdatasetutil.cocostore import CreateCocoLoaders

# Create dataset loaders
dataset_bucket = s3def['sets']['dataset']['bucket']
if args.dataset=='coco':
    class_dictionary = s3.GetDict(s3def['sets']['dataset']['bucket'],args.coco_class_dict)
    loaders = CreateCocoLoaders(s3, dataset_bucket, 
        class_dict=args.coco_class_dict, 
        batch_size=args.batch_size,
        num_workers=args.num_workers,
        cuda = args.cuda,
        height = args.height,
        width = args.width,
    )

# Identify training and test loaders
trainloader = next(filter(lambda d: d.get('set') == 'train', loaders), None)
testloader = next(filter(lambda d: d.get('set') == 'test' or d.get('set') == 'val', loaders), None)

# Iterate through the dataset
for i, data in tqdm(enumerate(trainloader['dataloader']), 
                    bar_format='{desc:<8.5}{percentage:3.0f}%|{bar:50}{r_bar}', 
                    total=trainloader['batches'], desc="Train batches", disable=args.job):

    # Extract dataset data
    inputs, labels, mean, stdev = data

    # Remaining steps

Cityscapes Dataset

To download cityscapes, your cityscapes credentials must be included in you credentials yaml file with the following structure

cityscapes:
  username: <username>
  password: <password>

Call torchdatasetutil.getcityscapes to retrieve the cityscapes dataset and stage it into object storage

python3 -m torchdatasetutil.getcityscapes
if args.dataset=='cityscapes':
    class_dictionary = s3.GetDict(s3def['sets']['dataset']['bucket'],args.cityscapes_class_dict)
    loaders = CreateCityscapesLoaders(s3, s3def, 
        src = args.cityscapes_data,
        dest = args.dataset_path+'/cityscapes',
        class_dictionary = class_dictionary,
        batch_size = args.batch_size, 
        num_workers=args.num_workers,
        height=args.height,
        width=args.width, 
    )

Imagenet:

  1. Data from kaggle:

    Data from https://www.kaggle.com/competitions/imagenet-object-localization-challenge/data?select=LOC_sample_submission.csv

  2. Extract and move validation folder data: https://discuss.pytorch.org/t/issues-with-dataloader-for-imagenet-should-i-use-datasets-imagefolder-or-datasets-imagenet/115742/7
  3. Zip ILSVRC/Data/CLS-LOC/ to ILSVRC2012_devkit_t12.tar.gz
    tar -czvf ILSVRC2012_devkit_t12.tar.gz ILSVRC/Data/CLS-LOC
    
  4. Imagenet directories
  5. Imagenet indexes

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

torchdatasetutil-0.1.30.tar.gz (46.0 kB view details)

Uploaded Source

Built Distribution

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

torchdatasetutil-0.1.30-py3-none-any.whl (54.6 kB view details)

Uploaded Python 3

File details

Details for the file torchdatasetutil-0.1.30.tar.gz.

File metadata

  • Download URL: torchdatasetutil-0.1.30.tar.gz
  • Upload date:
  • Size: 46.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.26.0 setuptools/59.5.0 requests-toolbelt/0.8.0 tqdm/4.56.0 CPython/3.8.10

File hashes

Hashes for torchdatasetutil-0.1.30.tar.gz
Algorithm Hash digest
SHA256 1bc6d8e49b56fd6674a74deeacc331fa2283b17e02d58bc93bceaa4f95690669
MD5 45db5202ab0abaf1aa9aed5ea215c05b
BLAKE2b-256 88c817d268101d6051cae5a7711a991136002fc6bb43d57e161c6cdc0a7831a7

See more details on using hashes here.

File details

Details for the file torchdatasetutil-0.1.30-py3-none-any.whl.

File metadata

  • Download URL: torchdatasetutil-0.1.30-py3-none-any.whl
  • Upload date:
  • Size: 54.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.26.0 setuptools/59.5.0 requests-toolbelt/0.8.0 tqdm/4.56.0 CPython/3.8.10

File hashes

Hashes for torchdatasetutil-0.1.30-py3-none-any.whl
Algorithm Hash digest
SHA256 afe00c5661b719b6be6b8597150f3cf72640e1e48a26141d5542539193852205
MD5 42de7774ee520da23f97eb58d48b5f37
BLAKE2b-256 e8102a9524b6395a56eb30e909ef0446b916db1e08c6b97ce3175a16b362f06c

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