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:
- Convert the input to a tensor
- 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
numpy array of shape (2, 2, 3) with all values 127 (mid-gray)
{"shape": [3, 2, 2], "min_val": -0.0, "max_val": -0.0, "mean": -0.0}- Input: a image with 3 colour channels, stored height × width × channels, every value the 8-bit integer 127 (mid-gray).
- Stage 1, rescale and reorder: each value is divided by 255, so , and the axes move to channels × height × width. That is why the shape becomes
[3, 2, 2]: channel count first, then the spatial size. - Stage 2, standardise per channel: with mean and standard deviation , each value becomes .
- Statistics: every entry is identical, so the minimum, maximum and mean are all . Rounded to 2 decimal places that is (the sign survives), so
-0.0formin_val,max_valandmean. - Notice: these two stages map onto . Pure black (0) lands at and pure white (255) at , while 127 sits just below the midpoint because the exact middle would be 127.5.
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)