Challenge - 5 Problems
Custom Transform Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a custom PyTorch transform on a tensor
Given the following custom transform class and input tensor, what is the output tensor after applying the transform?
PyTorch
import torch class AddScalar: def __init__(self, scalar): self.scalar = scalar def __call__(self, x): return x + self.scalar transform = AddScalar(3) tensor = torch.tensor([1, 2, 3]) output = transform(tensor) print(output)
Attempts:
2 left
💡 Hint
Remember the transform adds the scalar 3 to each element of the tensor.
✗ Incorrect
The transform adds 3 to each element of the input tensor [1, 2, 3], resulting in [4, 5, 6].
❓ Model Choice
intermediate2:00remaining
Choosing the correct custom transform for image normalization
You want to create a custom PyTorch transform that normalizes an image tensor by subtracting the mean and dividing by the standard deviation. Which class correctly implements this?
Attempts:
2 left
💡 Hint
Normalization means subtracting mean and dividing by std deviation.
✗ Incorrect
Option A correctly subtracts the mean and divides by the std deviation, which is the standard normalization formula.
❓ Hyperparameter
advanced2:00remaining
Effect of changing scalar in a custom transform
You have a custom transform that multiplies input tensors by a scalar value. If you increase the scalar from 2 to 5, what is the expected effect on the model training when using this transform on input data?
Attempts:
2 left
💡 Hint
Multiplying inputs by a larger scalar increases their magnitude.
✗ Incorrect
Increasing the scalar increases input magnitude, which can speed learning but may cause instability if too large.
🔧 Debug
advanced2:00remaining
Identify the error in this custom transform code
What error will this custom transform code raise when applied to a tensor?
PyTorch
import torch class Multiply: def __init__(self, factor): self.factor = factor def __call__(self, x): return x * self.factor transform = Multiply(4) tensor = torch.tensor([1, 2, 3]) output = transform(tensor) print(output)
Attempts:
2 left
💡 Hint
Check variable usage inside the __call__ method.
✗ Incorrect
Inside __call__, 'factor' is used without 'self.', causing a NameError.
🧠 Conceptual
expert2:00remaining
Why use custom transforms instead of built-in ones?
Which of the following is the best reason to create a custom transform in PyTorch instead of using built-in transforms?
Attempts:
2 left
💡 Hint
Think about when you need something special that built-in tools don't offer.
✗ Incorrect
Custom transforms allow you to add unique preprocessing steps tailored to your data or task.