Skip to main content

A kit for managing data in a pytorch training/inference pipeline

Project description

Data Processing Kit

A kit for managing data in a PyTorch training/inference pipeline.

Features

  • ImageProcessor: Configure and apply image transformation pipelines for training and inference with separate transforms for training (with augmentation) and evaluation
  • TransformDataset: Generic dataset wrapper that applies transformations with type safety and automatic class information extraction
  • CheckpointManager: Safe model checkpointing using safetensors format to avoid pickle security issues

Installation

Prerequisites

  • Python 3.14 or higher
  • uv (recommended) or pip

Using uv (recommended)

uv add data-processing-kit

Using pip

pip install data-processing-kit 

Usage

ImageProcessor

import torch
import torchvision.transforms.v2 as v2
from PIL import Image
from data_processing_kit import ImageProcessor

processor = ImageProcessor(
    train_transforms=[
        v2.Resize((224, 224)),
        v2.RandomHorizontalFlip(),
        v2.ToImage(),
        v2.ToDtype(torch.float32, scale=True),
        v2.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    ],
    eval_transforms=[
        v2.Resize((224, 224)),
        v2.ToImage(),
        v2.ToDtype(torch.float32, scale=True),
        v2.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    ]
)

# Process single image during inference
image = Image.open("example.jpg")
tensor = processor.inference_process_single(image, device=torch.device("cpu"))

# Process batch or stream
images = [Image.open(f"example-{i}.jpg") for i in range(10)] # Open 10 images
tensor_batch = processor.inference_process_batch(images, device=torch.device("cuda"))
tensor_stream = processor.inference_process_stream(images, device=torch.device("cuda"))

# Save processor to a file (or use CheckpointManager, see below)
processor.save("processor.pt")

TransformDataset

from data_processing_kit import TransformDataset
from torchvision.datasets import ImageFolder

dataset = ImageFolder("path/to/data")
transform_dataset = TransformDataset(
    dataset=dataset,
    transform=processor.get_train_compose(),
    classes=["cat", "dog"]
)

print(f"Number of classes: {transform_dataset.num_classes}")
print(f"Class mapping: {transform_dataset.class_to_idx}")

CheckpointManager

import torch
from data_processing_kit import CheckpointManager

manager = CheckpointManager()

# Save model and processor
model = YourModel()
manager.save(model, processor, path="checkpoints/my_model")

# Load checkpoint
model_state, loaded_processor = manager.load("checkpoints/my_model")
model.load_state_dict(model_state)

License

MIT License - see LICENSE for details.

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

data_processing_kit-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

data_processing_kit-0.1.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file data_processing_kit-0.1.0.tar.gz.

File metadata

  • Download URL: data_processing_kit-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for data_processing_kit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d63efc303f36934b2c381c8bcb513281a0f59d58cea8efa1be996f3b6b6f113f
MD5 9ba38651bbcc2e36764f0a2237467659
BLAKE2b-256 f756ac4dd0af212e58273718ad3901d14294863d82b5a9d273545486cdf4ba6d

See more details on using hashes here.

File details

Details for the file data_processing_kit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: data_processing_kit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for data_processing_kit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f71f1d5c3d2887092fcd6b24969615cb55c31946f926b8b7ea26c5679d4eae47
MD5 76f1b212f3640ce1bf9dfa02323a4959
BLAKE2b-256 1d1ab629e53ed6a11a5d2d9a17dd490079ea3eb332994a8d3424463c1c5a1afb

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