Bird
Raised Fist0
Computer Visionml~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of creating a custom object detection dataset?
easy
A. To compress images for faster loading
B. To improve image resolution automatically
C. To generate random images for testing
D. To teach a computer to find specific objects in images

Solution

  1. Step 1: Understand the goal of object detection datasets

    Custom object detection datasets are made to help computers learn to recognize and locate specific objects in images.
  2. Step 2: Identify the correct purpose

    Among the options, only teaching a computer to find specific objects matches the goal of such datasets.
  3. Final Answer:

    To teach a computer to find specific objects in images -> Option D
  4. Quick Check:

    Custom dataset purpose = teach detection [OK]
Hint: Custom datasets train models to detect your objects [OK]
Common Mistakes:
  • Confusing dataset purpose with image enhancement
  • Thinking dataset creates images instead of labeling
  • Assuming dataset compresses images
2. Which of the following is the correct format for an annotation line in a YOLO custom dataset label file?
easy
A. class_id x_center y_center width height (all normalized between 0 and 1)
B. image_width image_height class_id x y (pixel values)
C. class_name x_min y_min x_max y_max (absolute pixel coordinates)
D. class_id x_min y_min width height (normalized coordinates)

Solution

  1. Step 1: Recall YOLO annotation format

    YOLO uses normalized coordinates with class_id, x_center, y_center, width, and height all between 0 and 1.
  2. Step 2: Match options to YOLO format

    class_id x_center y_center width height (all normalized between 0 and 1) matches this format exactly; others use pixel values or different coordinate types.
  3. Final Answer:

    class_id x_center y_center width height (all normalized between 0 and 1) -> Option A
  4. Quick Check:

    YOLO labels use normalized center coords [OK]
Hint: YOLO labels use normalized center coordinates [OK]
Common Mistakes:
  • Using pixel coordinates instead of normalized
  • Confusing bounding box corners with center format
  • Mixing class name with class id
3. Given this label file line for an image of size 640x480:
2 0.5 0.5 0.25 0.25
What are the pixel coordinates of the bounding box corners (x_min, y_min, x_max, y_max)?
medium
A. (200, 150, 360, 270)
B. (160, 120, 320, 240)
C. (240, 180, 400, 300)
D. (320, 240, 480, 360)

Solution

  1. Step 1: Calculate center pixel coordinates

    x_center = 0.5 * 640 = 320, y_center = 0.5 * 480 = 240
  2. Step 2: Calculate width and height in pixels

    width = 0.25 * 640 = 160, height = 0.25 * 480 = 120
  3. Step 3: Calculate bounding box corners

    x_min = 320 - 160/2 = 240, y_min = 240 - 120/2 = 180
    x_max = 320 + 160/2 = 400, y_max = 240 + 120/2 = 300
  4. Final Answer:

    (240, 180, 400, 300) -> Option C
  5. Quick Check:

    Center ± half width/height = corners [OK]
Hint: Multiply normalized by image size, then subtract/add half box [OK]
Common Mistakes:
  • Using width/height as full coordinates instead of half
  • Mixing up x and y calculations
  • Forgetting to multiply by image dimensions
4. You have a dataset folder with images and label files. The labels are missing for some images. What is the best way to fix this before training?
medium
A. Remove images without label files from the dataset
B. Create empty label files for those images
C. Rename images to match existing label files
D. Ignore missing labels and train anyway

Solution

  1. Step 1: Understand dataset consistency needs

    Training requires each image to have a matching label file with annotations.
  2. Step 2: Choose the best fix

    Removing images without labels avoids errors and ensures clean training data. Creating empty labels may confuse the model, renaming won't help if labels don't exist, ignoring missing labels causes errors.
  3. Final Answer:

    Remove images without label files from the dataset -> Option A
  4. Quick Check:

    Dataset must have matching image-label pairs [OK]
Hint: Keep only images with labels to avoid training errors [OK]
Common Mistakes:
  • Creating empty label files that confuse training
  • Ignoring missing labels causing crashes
  • Renaming files without creating labels
5. You want to add a new object class to your existing custom dataset. Which steps should you follow to update your dataset correctly?
hard
A. Only add new images with the new class, no config changes needed
B. Add the new class to the class list, label new images with it, and update training config
C. Replace old class labels with the new class in all files
D. Add new class images but keep old labels unchanged without config update

Solution

  1. Step 1: Update class list

    Add the new object class to your dataset's class list file so the model knows about it.
  2. Step 2: Label new images with the new class

    Annotate images containing the new object using the new class id in label files.
  3. Step 3: Update training configuration

    Modify your training config to include the new class count and class names.
  4. Final Answer:

    Add the new class to the class list, label new images with it, and update training config -> Option B
  5. Quick Check:

    Update classes, labels, and config for new objects [OK]
Hint: Update classes, label new data, and config for new objects [OK]
Common Mistakes:
  • Not updating class list causing training errors
  • Forgetting to label new objects
  • Ignoring config updates leading to wrong class counts
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