0
0
Computer Visionml~20 mins

Python CV ecosystem (OpenCV, PIL, torchvision) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Python CV Ecosystem Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this OpenCV image shape code?
Given an image loaded with OpenCV, what will be the output of the shape attribute?
Computer Vision
import cv2
img = cv2.imread('sample.jpg')
print(img.shape)
A(height, width, channels) tuple representing image dimensions
B(width, height, channels) tuple representing image dimensions
CA single integer representing total pixels
DRaises an error because shape attribute does not exist
Attempts:
2 left
💡 Hint
OpenCV loads images as NumPy arrays with shape (rows, columns, channels).
Model Choice
intermediate
2:00remaining
Which torchvision model is best for image classification on ImageNet?
You want to use a pretrained model from torchvision for classifying images into 1000 classes. Which model is designed specifically for this?
Atorchvision.models.segmentation.fcn_resnet50(pretrained=True)
Btorchvision.models.resnet50(pretrained=True)
Ctorchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
Dtorchvision.models.video.r3d_18(pretrained=True)
Attempts:
2 left
💡 Hint
Image classification models output class probabilities for fixed classes.
Metrics
advanced
2:00remaining
How to correctly compute accuracy for a torchvision classification model?
You have model outputs as logits and true labels as integers. Which code snippet correctly computes accuracy?
A
preds = outputs.argmax(dim=1)
accuracy = (preds == labels).sum().item()
B
preds = outputs.max(dim=0)
accuracy = (preds == labels).float().mean().item()
C
preds = outputs.argmax(dim=1)
accuracy = (preds == labels).float().mean().item()
D
preds = outputs.argmax(dim=1)
accuracy = (preds == labels).float().sum().item() / len(labels)
Attempts:
2 left
💡 Hint
Accuracy is the fraction of correct predictions over total samples.
🔧 Debug
advanced
2:00remaining
Why does this PIL image conversion code raise an error?
Code snippet: from PIL import Image img = Image.open('photo.png') img = img.convert('HSV')
Computer Vision
from PIL import Image
img = Image.open('photo.png')
img = img.convert('HSV')
ANo error, image converts successfully
BFileNotFoundError because 'photo.png' does not exist
CValueError because 'HSV' is not a supported mode in PIL
DTypeError because convert expects an integer
Attempts:
2 left
💡 Hint
PIL supports specific modes like 'RGB', 'L', 'RGBA'.
🧠 Conceptual
expert
2:00remaining
What is the main difference between OpenCV and PIL in image processing?
Choose the statement that best describes a key difference between OpenCV and PIL libraries.
APIL is designed for real-time computer vision, OpenCV is not
BPIL supports video processing, OpenCV does not
COpenCV cannot read PNG images, PIL can
DOpenCV uses BGR color order by default, PIL uses RGB
Attempts:
2 left
💡 Hint
Think about default color channel order in each library.