Skip to content

[Feature Request] Add transform pipeline inspection and visualization utilities #9657

Description

@kanaad-lims

🚀 The feature

When working with image transformation pipelines, it can be difficult to understand how individual transforms affect an input image, especially when multiple augmentations are composed together.

I’d like to propose adding a small transform inspection/visualization utility to torchvision.transforms.v2 that can capture the intermediate outputs of a transform pipeline and display them together, for example as a Matplotlib grid.

For example, given:

transforms = v2.Compose([
    v2.RandomResizedCrop(...),
    v2.RandomHorizontalFlip(),
    v2.ColorJitter(...),
    v2.Normalize(...),
])

the utility could make it easy to inspect the result after each transformation:

Original
   ↓
RandomResizedCrop
   ↓
RandomHorizontalFlip
   ↓
ColorJitter
   ↓
Normalize

I have added a transforms pipeline code snippet and corresponding feature result as additional context below.

This would be useful for:

  • debugging unexpected augmentation behavior
  • visually validating augmentation pipelines
  • understanding the effect of individual transforms
  • quickly identifying overly aggressive transformations
  • developing and tuning data augmentation pipelines

I have already implemented this functionality as a standalone open-source library, Torch-Transform-Inspector, which provides intermediate transform visualization using Matplotlib.

I would be interested in implementing a lightweight, torchvision-native version that follows the existing transforms.v2 API and conventions, rather than requiring users to install an external package.

Would this functionality be considered a good fit for torchvision.transforms.v2? If so, I’d be happy to work on an initial implementation based on maintainer feedback.

Motivation, pitch

Image transformation pipelines can become difficult to debug as multiple augmentations are composed together, making it hard to see how each transform affects the input.

For e.g., while working on a CNN pretraining pipeline for brain MRI images, we had a complex pipeline with 20+ augmentation steps. It was difficult to inspect how the image changed after each individual transformation and identify whether any augmentation was producing an unexpected result.

A lightweight inspection utility would allow users to visualize intermediate outputs after each transform, making it easier to validate augmentation pipelines, identify unexpected transformations, and tune augmentations during model development.

I have already built a standalone implementation of this idea in Torch-Transform-Inspector and would be interested in bringing a lightweight, torchvision-native version to torchvision.transforms.v2.

Alternatives

No response

Additional context

Implementation Example:

Consider the following transforms pipeline:

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)

With the feature, the transformations that the image goes through is seen as this -

Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions