PIXELBANKv9.1.0
Menu

Compose Multiple Transforms

Problem Statement

Use Compose to chain multiple transforms together into a single transform pipeline.

Background

In practice, you often need to apply multiple transforms in sequence. Compose lets you define a pipeline where the output of each transform becomes the input to the next one.

Your Task

Write a function create_transform_pipeline() that creates a Compose pipeline to:

  1. Convert the input to a tensor
  2. Normalize it with mean=0.5 and std=0.5 for each of 3 channels

The function should return a dictionary with the output's shape, value range, and mean when applied to an image.

Output Format

Return a dictionary with keys: "shape" (list), "min_val" (float, 2 decimals), "max_val" (float, 2 decimals), "mean" (float, 2 decimals).

Example:

Input:
numpy array of shape (2, 2, 3) with all values 127 (mid-gray)
Output:
{"shape": [3, 2, 2], "min_val": -0.0, "max_val": -0.0, "mean": -0.0}
Reasoning:

ToTensor converts 127 to ~0.498, then Normalize: (0.498-0.5)/0.5 ā‰ˆ -0.004 ā‰ˆ -0.0

Constraints:

  • Use torchvision.transforms.Compose, ToTensor, Normalize
  • Use mean=[0.5, 0.5, 0.5] and std=[0.5, 0.5, 0.5] for Normalize
  • Round all numeric values to 2 decimal places
  • Input will be a numpy array of shape (H, W, 3)
solution.py

Test Results

0/0
Run code to see test results.
Compose Multiple Transforms - Medium | PixelBank