Bird
Raised Fist0
Intro to Computingfundamentals~20 mins

Computer vision basics in Intro to Computing - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Computer Vision Basics Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary purpose of image preprocessing in computer vision?
Image preprocessing is a crucial step before feeding images into a model. What is its main goal?
ATo enhance image quality and normalize data for better model performance
BTo increase the image file size for better resolution
CTo convert images into audio signals for analysis
DTo randomly shuffle pixel values to create data augmentation
Attempts:
2 left
💡 Hint
Think about how preparing data helps a model learn better.
🔍 Analysis
intermediate
2:00remaining
What is the output shape after applying a 3x3 convolution with stride 1 and padding 1 on a 28x28 grayscale image?
Given a single grayscale image of size 28x28 pixels, a convolutional layer uses a 3x3 filter, stride 1, and padding 1. What will be the output shape?
Intro to Computing
import torch
import torch.nn as nn

input_tensor = torch.randn(1, 1, 28, 28)  # batch_size=1, channels=1, height=28, width=28
conv = nn.Conv2d(in_channels=1, out_channels=10, kernel_size=3, stride=1, padding=1)
output = conv(input_tensor)
output.shape
Atorch.Size([1, 10, 26, 26])
Btorch.Size([1, 10, 28, 28])
Ctorch.Size([1, 1, 28, 28])
Dtorch.Size([1, 10, 30, 30])
Attempts:
2 left
💡 Hint
Padding of 1 keeps the spatial size same when stride is 1 and kernel size is 3.
❓ Model Choice
advanced
2:00remaining
Which model architecture is best suited for detecting objects at multiple scales in an image?
You want to build a computer vision model that detects objects of various sizes in images. Which architecture is most appropriate?
AA simple fully connected neural network
BA recurrent neural network (RNN)
CA convolutional neural network with feature pyramid networks (FPN)
DA linear regression model
Attempts:
2 left
💡 Hint
Think about architectures designed to handle different object sizes.
❓ Metrics
advanced
2:00remaining
Which metric is most appropriate to evaluate a binary image segmentation model?
You trained a model to segment objects in images (pixel-wise classification). Which metric best measures overlap between predicted and true segments?
AMean Squared Error (MSE)
BPrecision
CAccuracy
DIntersection over Union (IoU)
Attempts:
2 left
💡 Hint
This metric compares the area of overlap to the area of union between prediction and ground truth.
🔍 Analysis
expert
2:00remaining
Why does this CNN training code raise a runtime error?
Examine the code below. It raises a runtime error during training. What is the cause?
Intro to Computing
import torch
import torch.nn as nn

class SimpleCNN(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = nn.Conv2d(3, 16, 3)
        self.fc = nn.Linear(16*30*30, 10)
    def forward(self, x):
        x = self.conv(x)
        x = torch.relu(x)
        x = x.view(-1, 16*30*30)
        x = self.fc(x)
        return x

model = SimpleCNN()
input_tensor = torch.randn(4, 3, 32, 32)
output = model(input_tensor)
AThe input to the linear layer has incorrect size due to convolution output shape mismatch
BThe convolution layer has wrong number of input channels
CThe ReLU function is applied incorrectly
DThe batch size is too large for the model
Attempts:
2 left
💡 Hint
Check the size of the tensor after convolution before flattening.

Practice

(1/5)
1. What is the main goal of computer vision?
easy
A. To help computers understand images and videos
B. To write text documents automatically
C. To speed up internet connections
D. To create music from scratch

Solution

  1. Step 1: Understand the purpose of computer vision

    Computer vision is about making computers see and understand visual data like images and videos.
  2. Step 2: Compare options with this purpose

    Only To help computers understand images and videos matches this goal; others are unrelated to images or videos.
  3. Final Answer:

    To help computers understand images and videos -> Option A
  4. Quick Check:

    Computer vision = understanding images/videos [OK]
Hint: Computer vision means computers 'seeing' images [OK]
Common Mistakes:
  • Confusing computer vision with text or audio processing
  • Thinking it speeds up internet or unrelated tasks
2. Which Python library is commonly used to load and show images in computer vision?
easy
A. NumPy
B. OpenCV
C. Matplotlib
D. Pandas

Solution

  1. Step 1: Identify libraries for image handling

    OpenCV is a popular library designed for image and video processing.
  2. Step 2: Check other options

    NumPy handles arrays, Matplotlib plots graphs, Pandas manages tables; none focus on image loading/display like OpenCV.
  3. Final Answer:

    OpenCV -> Option B
  4. Quick Check:

    OpenCV = image loading/showing [OK]
Hint: OpenCV is the go-to for images/videos in Python [OK]
Common Mistakes:
  • Choosing NumPy which is for arrays, not images
  • Picking Matplotlib which is for plotting, not image loading
3. What will the following Python code print?
import cv2
img = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)
print(img.shape)
medium
A. A tuple with 2 values (height, width)
B. A tuple with 3 values (height, width, channels)
C. A single integer representing total pixels
D. An error because of wrong syntax

Solution

  1. Step 1: Understand cv2.imread with GRAYSCALE flag

    Loading an image in grayscale returns a 2D array with height and width only (no color channels).
  2. Step 2: Check what img.shape returns

    For grayscale images, shape is a tuple of two values: (height, width).
  3. Final Answer:

    A tuple with 2 values (height, width) -> Option A
  4. Quick Check:

    Grayscale image shape = (height, width) [OK]
Hint: Grayscale images have 2D shape, color images have 3D [OK]
Common Mistakes:
  • Expecting 3 values for grayscale images
  • Thinking shape returns total pixels as integer
  • Assuming code has syntax error
4. The code below tries to convert a color image to grayscale but throws an error. What is the mistake?
import cv2
img = cv2.imread('photo.png')
gray = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
cv2.imshow('Gray', gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
medium
A. cv2.waitKey() needs an argument
B. Missing cv2.imread() function
C. cv2.imshow() cannot show grayscale images
D. Using COLOR_GRAY2BGR instead of COLOR_BGR2GRAY

Solution

  1. Step 1: Check color conversion code

    The code uses cv2.COLOR_GRAY2BGR which converts grayscale to color, but input is color image.
  2. Step 2: Correct conversion for color to grayscale

    To convert color to grayscale, use cv2.COLOR_BGR2GRAY instead.
  3. Final Answer:

    Using COLOR_GRAY2BGR instead of COLOR_BGR2GRAY -> Option D
  4. Quick Check:

    Color to grayscale needs COLOR_BGR2GRAY [OK]
Hint: Use COLOR_BGR2GRAY to convert color to grayscale [OK]
Common Mistakes:
  • Mixing up color conversion flags
  • Thinking cv2.imshow can't show grayscale images
  • Assuming waitKey needs argument
5. You want to build a simple system that detects if an image is mostly dark or bright. Which approach is best to start with?
hard
A. Count the number of colors in the image
B. Use a deep neural network without preprocessing
C. Convert the image to grayscale and calculate the average pixel brightness
D. Resize the image to a smaller size without changing colors

Solution

  1. Step 1: Understand the problem of brightness detection

    Brightness relates to how light or dark pixels are; grayscale simplifies this by removing color.
  2. Step 2: Choose a simple and effective method

    Converting to grayscale and averaging pixel values gives a direct measure of brightness, easy and fast.
  3. Final Answer:

    Convert the image to grayscale and calculate the average pixel brightness -> Option C
  4. Quick Check:

    Grayscale average brightness = brightness check [OK]
Hint: Grayscale average pixel value shows image brightness [OK]
Common Mistakes:
  • Using complex models without simple preprocessing
  • Counting colors which doesn't measure brightness
  • Resizing without addressing brightness
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