0
0
Computer Visionml~20 mins

Custom object detection dataset in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Custom Object Detection Dataset Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
data_output
intermediate
2:00remaining
Understanding dataset structure for object detection

You have a custom object detection dataset with images and annotations in COCO format. What is the number of unique object categories in the dataset?

Computer Vision
import json

with open('annotations.json') as f:
    data = json.load(f)

categories = data['categories']
num_categories = len(categories)
print(num_categories)
A5
B15
C10
D20
Attempts:
2 left
💡 Hint

Look at the 'categories' key in the COCO annotation file. Count how many category entries it has.

Predict Output
intermediate
2:00remaining
Output of bounding box extraction code

Given the following code snippet that extracts bounding boxes from annotations, what is the output?

Computer Vision
annotations = [
    {'bbox': [10, 20, 30, 40], 'category_id': 1},
    {'bbox': [15, 25, 35, 45], 'category_id': 2},
    {'bbox': [50, 60, 70, 80], 'category_id': 1}
]

bboxes = [ann['bbox'] for ann in annotations if ann['category_id'] == 1]
print(bboxes)
A[[10, 20, 30, 40], [50, 60, 70, 80]]
B[]
C[[10, 20, 30, 40]]
D[[15, 25, 35, 45]]
Attempts:
2 left
💡 Hint

Filter bounding boxes where category_id equals 1.

visualization
advanced
3:00remaining
Visualizing bounding boxes on an image

Which option correctly draws bounding boxes on an image using OpenCV for a given list of boxes?

Computer Vision
import cv2
import numpy as np

image = np.zeros((100, 100, 3), dtype=np.uint8)
bboxes = [[10, 10, 30, 30], [50, 50, 20, 20]]

for box in bboxes:
    x, y, w, h = box
    cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 0), 2)

cv2.imwrite('output.png', image)
ADraw rectangles using cv2.rectangle with top-left and bottom-right corners calculated correctly.
BDraw rectangles using cv2.circle at (x, y) with radius w.
CDraw rectangles using cv2.line connecting (x, y) to (x+w, y+h) only.
DDraw rectangles using cv2.rectangle with (x, y) and (w, h) as corners directly.
Attempts:
2 left
💡 Hint

Bounding boxes are defined by top-left corner (x, y) and width and height (w, h). Use these to find corners.

🔧 Debug
advanced
2:00remaining
Identify the error in dataset loading code

What error will this code raise when loading a custom object detection dataset?

Computer Vision
import json

with open('annotations.json') as f:
    data = json.load(f)

images = data['images']
annotations = data['annotations']

image_id = images[0]['id']
image_annotations = [ann for ann in annotations if ann['image_id'] == image_id]

print(len(image_annotations))
AKeyError because 'images' key is missing in JSON
BTypeError because 'annotations' is not iterable
CIndexError because images list is empty
DNo error, prints the number of annotations for the first image
Attempts:
2 left
💡 Hint

Check if the JSON file has 'images' and 'annotations' keys and they contain lists.

🚀 Application
expert
3:00remaining
Calculate average bounding box area per category

Given a dataset with annotations, which option correctly computes the average bounding box area for each category?

Computer Vision
annotations = [
    {'bbox': [10, 20, 30, 40], 'category_id': 1},
    {'bbox': [15, 25, 35, 45], 'category_id': 2},
    {'bbox': [50, 60, 70, 80], 'category_id': 1},
    {'bbox': [5, 10, 15, 20], 'category_id': 2}
]

from collections import defaultdict

area_sum = defaultdict(float)
count = defaultdict(int)

for ann in annotations:
    _, _, w, h = ann['bbox']
    area = w * h
    area_sum[ann['category_id']] += area
    count[ann['category_id']] += 1

avg_area = {cat: area_sum[cat]/count[cat] for cat in area_sum}
print(avg_area)
A{1: 3500.0, 2: 1200.0}
B{1: 3400.0, 2: 937.5}
C{1: 2500.0, 2: 1200.0}
D{1: 3500.0, 2: 975.0}
Attempts:
2 left
💡 Hint

Calculate area as width * height for each bbox, sum by category, then divide by count.