Bird
Raised Fist0
Computer Visionml~20 mins

U-Net architecture in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
U-Net Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding U-Net's Skip Connections

In the U-Net architecture, what is the main purpose of the skip connections between the encoder and decoder parts?

ATo reduce the number of parameters by sharing weights between encoder and decoder layers.
BTo combine low-level spatial information from the encoder with high-level features in the decoder to improve segmentation accuracy.
CTo increase the depth of the network by adding more convolutional layers in the decoder.
DTo perform max pooling operations to downsample the feature maps.
Attempts:
2 left
💡 Hint

Think about how the network keeps details from the input image while reconstructing the output.

❓ Predict Output
intermediate
2:00remaining
Output Shape After U-Net Encoder Block

Given an input tensor of shape (batch_size=1, channels=3, height=128, width=128), what is the output shape after one encoder block in a U-Net that applies two 3x3 convolutions (padding=1, stride=1) followed by a 2x2 max pooling (stride=2)?

Computer Vision
import torch
import torch.nn as nn

class EncoderBlock(nn.Module):
    def __init__(self, in_channels, out_channels):
        super().__init__()
        self.conv = nn.Sequential(
            nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1),
            nn.ReLU(),
            nn.Conv2d(out_channels, out_channels, kernel_size=3, padding=1),
            nn.ReLU()
        )
        self.pool = nn.MaxPool2d(kernel_size=2, stride=2)

    def forward(self, x):
        x = self.conv(x)
        p = self.pool(x)
        return x, p

x = torch.randn(1, 3, 128, 128)
block = EncoderBlock(3, 64)
features, pooled = block(x)
output_shape = pooled.shape
A(1, 64, 64, 64)
B(1, 64, 128, 128)
C(1, 3, 64, 64)
D(1, 64, 32, 32)
Attempts:
2 left
💡 Hint

Remember that padding keeps spatial size after convolution, and max pooling halves height and width.

❓ Model Choice
advanced
2:00remaining
Choosing the Right Activation for U-Net Output

For a U-Net model designed to perform binary segmentation (classifying each pixel as foreground or background), which activation function is most appropriate to use in the final layer?

ASoftmax activation
BReLU activation
CTanh activation
DSigmoid activation
Attempts:
2 left
💡 Hint

Consider the output as a probability for each pixel belonging to the foreground class.

❓ Metrics
advanced
2:00remaining
Evaluating U-Net Segmentation with Dice Coefficient

Which of the following formulas correctly computes the Dice coefficient for evaluating the overlap between predicted and ground truth segmentation masks?

ADice = (2 * |Prediction ∩ GroundTruth|) / (|Prediction| + |GroundTruth|)
BDice = |Prediction ∩ GroundTruth| / |Prediction ∪ GroundTruth|
CDice = |Prediction ∪ GroundTruth| / (|Prediction| + |GroundTruth|)
DDice = |Prediction| / |GroundTruth|
Attempts:
2 left
💡 Hint

Dice coefficient measures similarity by doubling the intersection over the sum of sizes.

🔧 Debug
expert
3:00remaining
Identifying the Cause of Dimension Mismatch in U-Net Decoder

In a U-Net decoder block, a concatenation of the upsampled feature map and the corresponding encoder feature map fails with a dimension mismatch error. Given that the encoder feature map has shape (batch_size, 64, 64, 64) and the upsampled decoder feature map has shape (batch_size, 64, 65, 65), what is the most likely cause?

AThe encoder feature map has wrong channel size causing mismatch during concatenation.
BThe batch size is different between encoder and decoder feature maps.
CThe upsampling operation increased spatial dimensions incorrectly, causing a mismatch with encoder features.
DThe concatenation axis is set incorrectly to the batch dimension.
Attempts:
2 left
💡 Hint

Check how upsampling changes height and width compared to encoder features.

Practice

(1/5)
1. What is the main purpose of the U-Net architecture in computer vision?
easy
A. To compress images for storage
B. To classify images into categories
C. To find exact shapes and boundaries in images
D. To generate new images from noise

Solution

  1. Step 1: Understand U-Net's design goal

    U-Net is designed to segment images, meaning it finds exact shapes and boundaries.
  2. Step 2: Compare with other tasks

    Classification assigns labels, generation creates images, compression reduces size; these are not U-Net's main tasks.
  3. Final Answer:

    To find exact shapes and boundaries in images -> Option C
  4. Quick Check:

    U-Net = segmentation [OK]
Hint: U-Net = image segmentation for shapes [OK]
Common Mistakes:
  • Confusing segmentation with classification
  • Thinking U-Net generates images
  • Assuming U-Net compresses images
2. Which of the following correctly describes the structure of U-Net?
easy
A. Two paths: one shrinks and one expands the image size
B. A single path that shrinks the image size
C. A path that only expands the image size
D. Multiple independent paths without connection

Solution

  1. Step 1: Recall U-Net architecture parts

    U-Net has an encoder path that shrinks and a decoder path that expands the image size.
  2. Step 2: Eliminate incorrect options

    Single shrinking path or only expanding path do not match U-Net. Independent paths without connection are incorrect.
  3. Final Answer:

    Two paths: one shrinks and one expands the image size -> Option A
  4. Quick Check:

    U-Net = encoder + decoder [OK]
Hint: U-Net has encoder and decoder paths [OK]
Common Mistakes:
  • Thinking U-Net only shrinks images
  • Believing U-Net only expands images
  • Ignoring the connection between paths
3. Consider this simplified U-Net code snippet in Python using PyTorch:
import torch
import torch.nn as nn

class SimpleUNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.down = nn.Conv2d(1, 16, 3, padding=1)
        self.up = nn.ConvTranspose2d(16, 1, 2, stride=2)

    def forward(self, x):
        x1 = self.down(x)  # shrink
        x2 = self.up(x1)   # expand
        return x2

model = SimpleUNet()
input_tensor = torch.randn(1, 1, 64, 64)
output = model(input_tensor)
print(output.shape)
What will be the printed output shape?
medium
A. torch.Size([1, 1, 64, 64])
B. torch.Size([1, 1, 128, 128])
C. torch.Size([1, 16, 64, 64])
D. torch.Size([1, 16, 32, 32])

Solution

  1. Step 1: Analyze down convolution output size

    Input is 64x64, Conv2d with kernel=3, padding=1 keeps size 64x64, output channels=16.
  2. Step 2: Analyze up convolution output size

    ConvTranspose2d with kernel=2, stride=2 doubles spatial size to 128x128, output channels=1.
  3. Step 3: Check actual output shape

    Output shape is (batch=1, channels=1, height=128, width=128).
  4. Final Answer:

    torch.Size([1, 1, 128, 128]) -> Option B
  5. Quick Check:

    Upsample doubles size = 128x128 [OK]
Hint: ConvTranspose2d with stride 2 doubles size [OK]
Common Mistakes:
  • Assuming Conv2d changes size without padding
  • Ignoring stride effect in ConvTranspose2d
  • Mixing channel numbers in output
4. In a U-Net implementation, a student forgot to add skip connections between encoder and decoder layers. What is the most likely effect?
medium
A. The model will not train at all and cause an error
B. The model will have better accuracy due to fewer connections
C. The model will run faster and produce the same results
D. The model will lose fine details and perform worse on segmentation

Solution

  1. Step 1: Understand skip connections role

    Skip connections pass fine details from encoder to decoder to improve segmentation accuracy.
  2. Step 2: Effect of missing skip connections

    Without them, decoder lacks detail info, causing worse segmentation results.
  3. Final Answer:

    The model will lose fine details and perform worse on segmentation -> Option D
  4. Quick Check:

    Skip connections = better detail [OK]
Hint: No skip connections = loss of detail [OK]
Common Mistakes:
  • Thinking fewer connections always improve accuracy
  • Assuming model will error without skip connections
  • Believing speed improves without accuracy loss
5. You want to improve a U-Net model's segmentation on small objects in medical images. Which change is most effective?
hard
A. Increase the depth of the encoder to capture more features
B. Remove skip connections to simplify the model
C. Use larger convolution kernels to cover bigger areas
D. Add more pooling layers to reduce spatial size aggressively

Solution

  1. Step 1: Identify challenge with small objects

    Small objects need detailed features and context captured by deeper layers.
  2. Step 2: Evaluate options

    Increasing encoder depth helps learn more features. Removing skip connections loses detail. Larger kernels may blur small details. More pooling reduces spatial resolution, losing small object info.
  3. Final Answer:

    Increase the depth of the encoder to capture more features -> Option A
  4. Quick Check:

    Deeper encoder = better small object features [OK]
Hint: Deeper encoder = better small object detection [OK]
Common Mistakes:
  • Removing skip connections harms detail
  • Larger kernels blur small features
  • More pooling loses small object info
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard