Skip to main content

LLM-powered data augmentation policy designer with domain-safe, task-aware policies

Project description

AugmentAI ๐ŸŽจ

LLM-Powered Data Augmentation Policy Designer

Design domain-safe, task-aware augmentation policies through natural language conversation. No more manual hyperparameter tuningโ€”just describe your dataset and constraints, and get scientifically sound augmentation pipelines.

Design Philosophy: The LLM suggests. Rules decide. Code executes.

PyPI version Python 3.9+ License: MIT Open In Colab

๐ŸŒŸ Features

  • One-Command Preparation: augmentai prepare ./dataset - inspect, split, augment, export
  • ๐Ÿ†• AutoSearch: augmentai search ./dataset - find optimal policies automatically
  • Natural Language Interface: Describe your dataset in plain English
  • Domain-Aware Constraints: Built-in rules for medical, OCR, satellite, and natural images
  • Safety-First Design: Hard constraints that prevent scientifically invalid augmentations
  • Full Reproducibility: Seed locking, manifest tracking, deterministic pipelines
  • LLM as Advisor: OpenAI, Gemini, Ollama, or LM Studioโ€”LLM suggests, rules validate
  • Executable Output: Generate standalone Python scripts ready to run
  • Verbose/Quiet Modes: --verbose for debugging, --quiet for CI/CD pipelines

๐Ÿš€ Quick Start

Installation

# Install from PyPI
pip install augmentai

# Or install from source
git clone https://github.com/kyrozepto/augmentai.git
cd augmentai && pip install -e .

Set up your LLM provider

# Option 1: Environment variables (recommended)
export OPENAI_API_KEY="your-api-key"      # For OpenAI
export GOOGLE_API_KEY="your-api-key"       # For Gemini (from aistudio.google.com)

# Option 2: Pass directly via CLI
augmentai chat --provider gemini --api-key "your-key"
augmentai chat --provider openai --api-key "your-key"

# Option 3: Use Ollama (free, local)
ollama pull llama3.2
augmentai chat --provider ollama

Supported LLM Providers:

Provider Models API Key Env Var
openai gpt-4o-mini, gpt-4o OPENAI_API_KEY
gemini gemini-2.0-flash, gemini-1.5-pro GOOGLE_API_KEY
ollama llama3.2, mistral, etc. (none needed)
lmstudio local models (none needed)

One-Command Dataset Preparation

# Prepare dataset with auto-detected domain
augmentai prepare ./dataset

# Medical domain with custom split
augmentai prepare ./lung_ct --domain medical --split 70/15/15

# Preview what would happen (dry run)
augmentai prepare ./images --dry-run

Interactive Policy Design

# Start interactive chat
augmentai chat --domain medical

# List available domains
augmentai domains

# Validate an existing policy
augmentai validate my_policy.yaml --domain medical

๐Ÿ” AutoSearch: Find Optimal Policies Automatically

# Search for best policy (uses evolutionary optimization)
augmentai search ./dataset --domain medical --budget 50

# With custom output directory
augmentai search ./images --budget 100 --output ./search_results

# Preview search configuration
augmentai search ./data --dry-run

AutoSearch uses proxy metrics (diversity, coverage, strength, balance) to score policies without requiring full model training.

๏ฟฝ Output Structure

Running augmentai prepare generates:

prepared/
โ”œโ”€โ”€ data/
โ”‚   โ”œโ”€โ”€ train/           # Training split
โ”‚   โ”œโ”€โ”€ val/             # Validation split
โ”‚   โ””โ”€โ”€ test/            # Test split
โ”œโ”€โ”€ augmented/           # Output for augmented data
โ”œโ”€โ”€ augment.py           # Standalone augmentation script
โ”œโ”€โ”€ config.yaml          # Pipeline configuration
โ”œโ”€โ”€ manifest.json        # Reproducibility manifest
โ”œโ”€โ”€ requirements.txt     # Dependencies
โ””โ”€โ”€ README.md            # Usage instructions

๐ŸŽฏ Real-World Examples

๐Ÿฅ Medical: Dental Panoramic X-Ray

augmentai prepare "C:\Users\you\datasets\panoramic-xray" --domain medical --split 70/15/15

# Output:
# โœ“ Detected: 1,247 images across 4 classes (cavity, healthy, fracture, caries)
# โœ“ Split: 873 train, 187 val, 187 test
# โœ“ Policy: Conservative augmentations preserving dental anatomy
# โœ“ Forbidden: ElasticTransform, ColorJitter (would distort teeth/bone structure)

๐Ÿ›ฐ๏ธ Satellite: Land Use Classification

augmentai prepare ./sentinel2_tiles --domain satellite --seed 42

# Multi-spectral imagery gets special treatment:
# โœ“ Allowed: Rotation (any angle), flips, scale
# โœ“ Forbidden: ColorJitter, HSV, ChannelShuffle (breaks spectral bands!)

๐Ÿ“ OCR: Document Scanning

augmentai prepare ./scanned_receipts --domain ocr

# Text legibility is preserved:
# โœ“ Allowed: Slight rotation (ยฑ5ยฐ), brightness adjustment
# โœ“ Forbidden: MotionBlur, ElasticTransform (destroys text)

๐Ÿ–ผ๏ธ Natural: Instagram-style Photos

augmentai prepare ./pet_photos --domain natural

# Maximum flexibility for general images:
# โœ“ Allowed: Everything! Color jitter, elastic, cutout, mixup
# โœ“ Strong augmentations for robust models

๐Ÿ”ฌ Research: Reproducible Experiments

# Exact same augmentations every time
augmentai prepare ./experiment_data --seed 12345 --output ./exp_v1

# Later, reproduce with the manifest
cat ./exp_v1/manifest.json
# {
#   "seed": 12345,
#   "dataset_hash": "a1b2c3d4...",
#   "policy_hash": "e5f6g7h8...",
#   "augmentai_version": "0.1.0"
# }

๐Ÿญ Production: Batch Processing

# Prepare multiple datasets with consistent settings
for dataset in chest_xray brain_mri skin_lesion; do
    augmentai prepare ./raw/$dataset --domain medical --output ./prepared/$dataset
done

๐Ÿ’ป Python API: Full Control

from augmentai.core import Policy, Transform
from augmentai.domains import get_domain
from augmentai.rules.enforcement import RuleEnforcer
from augmentai.export import ScriptGenerator

# Create custom policy
policy = Policy(
    name="dental_xray_v2",
    domain="medical",
    transforms=[
        Transform("HorizontalFlip", 0.5),
        Transform("Rotate", 0.7, parameters={"limit": 20}),
        Transform("CLAHE", 0.4, parameters={"clip_limit": 2.0}),
        Transform("GaussNoise", 0.3, parameters={"var_limit": (10, 30)}),
        Transform("RandomBrightnessContrast", 0.5),
    ]
)

# Validate against medical rules
enforcer = RuleEnforcer(get_domain("medical"))
result = enforcer.enforce_policy(policy)
print(f"Safe transforms: {len(result.policy.transforms)}")

# Generate standalone script
generator = ScriptGenerator()
script = generator.generate_augment_script(result.policy, seed=42)
with open("my_augment.py", "w") as f:
    f.write(script)

๐Ÿ”„ Modifying Generated Config

After running augmentai prepare, edit config.yaml:

# config.yaml - tweak as needed!
policy:
  name: dental_xray_policy
  domain: medical
  seed: 42
transforms:
  - name: HorizontalFlip
    probability: 0.5          # โ† Increase to 0.7?
  - name: Rotate
    probability: 0.5
    parameters:
      limit: 15               # โ† Bump to 25 for more variety
  - name: CLAHE               # โ† Add new transforms!
    probability: 0.4
    parameters:
      clip_limit: 2.0

Then re-run the generated script:

python augment.py --input data/train --output augmented/train --seed 42

๐ŸŽ“ Interactive Learning Session

$ augmentai chat --domain medical

You: I have dental panoramic x-rays with cavity annotations. What augmentations 
     are safe? I'm worried about distorting the teeth.

๐Ÿค– AugmentAI: Great concern! For dental x-rays, I recommend:

โœ… Safe for dental imaging:
  โ€ข HorizontalFlip (p=0.5) - Teeth are roughly symmetric
  โ€ข Rotate (p=0.5, limit=ยฑ10ยฐ) - Small rotations are realistic
  โ€ข CLAHE (p=0.3) - Enhances contrast in x-rays
  โ€ข GaussNoise (p=0.2) - Simulates sensor noise

โš ๏ธ Automatically blocked:
  โ€ข ElasticTransform - Would warp tooth boundaries unrealistically
  โ€ข GridDistortion - Same issue, breaks tooth geometry  
  โ€ข ColorJitter - X-rays are grayscale, color transforms invalid

You: Can I increase rotation to 30 degrees?

๐Ÿค– AugmentAI: I'd advise caution. Dental panoramic x-rays are typically taken 
with the patient positioned consistently. Rotations beyond ยฑ15ยฐ might create 
unrealistic training samples. However, if your dataset has varied positioning, 
ยฑ20ยฐ could work. I'll set it to 20ยฐ as a compromise.

/preview
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Transform                  โ”‚ Probability โ”‚ Parameters           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ HorizontalFlip             โ”‚ 50%         โ”‚ -                    โ”‚
โ”‚ Rotate                     โ”‚ 50%         โ”‚ limit=20             โ”‚
โ”‚ CLAHE                      โ”‚ 30%         โ”‚ clip_limit=2.0       โ”‚
โ”‚ GaussNoise                 โ”‚ 20%         โ”‚ var_limit=(5, 25)    โ”‚
โ”‚ RandomBrightnessContrast   โ”‚ 30%         โ”‚ brightness_limit=0.1 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

/export dental_cavity_policy.py
โœ“ Exported to dental_cavity_policy.py

๐Ÿฅ Domain Safety

AugmentAI enforces hard constraints that cannot be overridden:

Domain Forbidden Transforms Reason
Medical ElasticTransform, GridDistortion, ColorJitter Breaks anatomy, invalid for grayscale
OCR MotionBlur, ElasticTransform Destroys text legibility
Satellite ColorJitter, HSV, ChannelShuffle Breaks spectral band relationships

๐Ÿ“ Project Structure

augmentai/
โ”œโ”€โ”€ cli/              # CLI commands (prepare, chat, validate, search)
โ”œโ”€โ”€ core/             # Policy, Transform, Manifest, Pipeline
โ”œโ”€โ”€ domains/          # Domain rules (medical, ocr, satellite, natural)
โ”œโ”€โ”€ inspection/       # Dataset auto-detection & analysis
โ”œโ”€โ”€ splitting/        # Train/val/test splitting strategies
โ”œโ”€โ”€ export/           # Script & folder generation
โ”œโ”€โ”€ llm/              # LLM client and prompts
โ”œโ”€โ”€ rules/            # Safety validation & enforcement
โ”œโ”€โ”€ compilers/        # Backend code generation
โ”œโ”€โ”€ search/           # ๐Ÿ†• AutoSearch: evolutionary policy optimization
โ”œโ”€โ”€ utils/            # ๐Ÿ†• Progress bars, logging utilities
โ””โ”€โ”€ exceptions.py     # ๐Ÿ†• Custom error hierarchy

๐Ÿ”ง Configuration

Create augmentai.yaml in your project:

llm:
  provider: openai  # or ollama, lmstudio
  model: gpt-4o-mini
  temperature: 0.7

backend: albumentations
output_dir: ./policies

๐ŸŽฏ Custom Domains

Define your own domain constraints in YAML:

# my_domain.yaml
name: my_custom_domain
description: Custom constraints for my task

constraints:
  - transform_name: ElasticTransform
    level: forbidden
    reason: Not suitable for my task

  - transform_name: Rotate
    level: recommended
    reason: Good for rotation invariance
    parameter_limits:
      limit: [-30, 30]

recommended_transforms:
  - HorizontalFlip
  - RandomBrightnessContrast

Load with:

augmentai chat --domain-file my_domain.yaml

๐Ÿค Contributing

Contributions welcome! See CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

MIT License - see LICENSE for details.

๐Ÿ™ Acknowledgments

  • Albumentations for the augmentation backend
  • Rich for beautiful terminal UI
  • OpenAI, Ollama, LM Studio for LLM support

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

augmentai-0.1.1.tar.gz (142.9 kB view details)

Uploaded Source

Built Distribution

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

augmentai-0.1.1-py3-none-any.whl (152.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: augmentai-0.1.1.tar.gz
  • Upload date:
  • Size: 142.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for augmentai-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5e96ec86c0e6b51cd8e2ff4fed86c22309326556a26b89236a6efafbc99be8f6
MD5 d6c1952b45d00b628c961441328e2210
BLAKE2b-256 fd233d13e8fbb04768ca5e83139136394b94835c6b6da02be2bab0e7ce970d55

See more details on using hashes here.

File details

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

File metadata

  • Download URL: augmentai-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 152.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for augmentai-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd34c1bffceeb90096b3cd0dcc338cf4e8599723f4b89de0a42ca5a94554504a
MD5 597303f9eb0741a8bb12eedace7c45f7
BLAKE2b-256 09ffae38287dd822d7cb6d68c80fef86567ef84404fc39a71c5d1a03ab2c8ff4

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