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.state_dict(), processor, save_directory="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.1.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.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: data_processing_kit-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 fabc228d6518e85e8a1fbb3b2a822a8eee766e111b74a9529cc6d97f24394501
MD5 0b2293546664ed065a5dba68086c6d90
BLAKE2b-256 4e68c0f467012c35e9806e2eb199a830cc056f97b86668149601ca5a81c7e323

See more details on using hashes here.

File details

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

File metadata

  • Download URL: data_processing_kit-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7a5c6f33f9a59c222bc2e8dbd71dfb7159b955c19be3166ca5f118c5cea159e
MD5 c6366f0234ffd47fe5b740f97098cfc5
BLAKE2b-256 5de9be8f8c8159ebb8bc0e2325e3444ee76f59ca8a3328b7d34f97c1dd9e0ab4

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