Visualize and debug torchvision image transforms step-by-step using matplotlib.
This library helps you see exactly how each transform in your augmentation pipeline affects an image.
View the library on PyPi
Transform-Inspect-Video-GitHub.mp4
pip install torch-transform-inspectImport it in Python using:
from transform_inspector import inspect_transforms, inspect_randomNote: The PyPI package name (
torch-transform-inspect) is different from the Python import name (transform_inspector).
When working with computer vision pipelines, it's often unclear:
- Which transform causes distortion
- Whether augmentation is too aggressive
- Whether transform order is correct
- How randomness affects training data
Torch Transform Inspect makes this visual and intuitive.
from torchvision import transforms
from transform_inspector import inspect_transforms
transforms_pipeline = transforms.Compose([
transforms.Resize(256),
transforms.RandomResizedCrop(224, scale=(0.3, 0.6), ratio=(0.5, 1.5)),
transforms.RandomHorizontalFlip(p=1.0),
transforms.ColorJitter(brightness=0.5, contrast=0.5, saturation=0.1, hue=0.4),
transforms.RandomRotation(degrees=75),
transforms.Grayscale(num_output_channels=3),
transforms.ToTensor(),
])
inspect_transforms("path/to/image.jpg", transforms_pipeline, cols=3)- Loads the image
- Applies each transform one by one
- Displays intermediate outputs in a grid
- Labels each image with the transform name
To understand how random augmentations behave:
from transform_inspector import inspect_random
inspect_random("path/to/image.jpg", transform_pipeline, n=6, cols=3)This applies the full pipeline multiple times and shows different outputs.
- Uses native
torchvision.transforms - Supports
Composeand single transforms - Visualizes intermediate steps
- Read-only (never modifies data)
- Lightweight and simple API
- Supported in standalone Python files.
- Supported in Jupyter Notebooks including Google Colab
| Parameter | Description |
|---|---|
image |
Image path (str) or PIL.Image |
transform |
torchvision transform or transforms.Compose |
cols |
Number of columns in the output grid |
Example:
inspect_transforms("image.jpg", transform_pipeline, cols=3)| Parameter | Description |
|---|---|
image |
Image path (str) or PIL.Image |
transform |
torchvision transform or transforms.Compose |
n |
Number of random samples |
cols |
Number of columns in the grid |
Example:
inspect_random("image.jpg", transform_pipeline, n=6, cols=3)- Python ≥ 3.8
- torch
- torchvision
- pillow
- matplotlib
MIT License
# Install
# pip install torch-transform-inspect
from torchvision import transforms
from transform_inspector import inspect_transforms, inspect_random
# Define your transform pipeline
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ColorJitter(brightness=0.3, contrast=0.3),
transforms.ToTensor(),
])
# Visualize step-by-step
inspect_transforms("path/to/image.jpg", transform)
# Visualize randomness
inspect_random("path/to/image.jpg", transform, n=9)See exactly which transform is causing unexpected behavior.
Visually assess if your augmentations are too aggressive or too subtle.
Great for teaching and understanding how different transforms work.
Ensure your preprocessing pipeline produces the expected results before training.
Contributions are welcome! Please feel free to submit a Pull Request.
For issues, questions, or feature requests, please open an issue on the GitHub repository.
Built with ❤️ for the PyTorch computer vision community.

