We create custom object detection datasets to teach computers how to find specific things in images. This helps computers recognize objects that matter to us.
Custom object detection dataset in Computer Vision
Dataset structure: - Images folder: contains all images (e.g., image1.jpg, image2.jpg) - Annotations folder: contains label files (e.g., image1.txt, image2.txt) Annotation format (YOLO style example): <class_id> <x_center> <y_center> <width> <height> All values are normalized between 0 and 1 relative to image size.
Annotations must match image filenames exactly except for extension.
Coordinates are usually normalized to keep dataset flexible for different image sizes.
Annotations for image1.txt: 0 0.5 0.5 0.2 0.3 1 0.7 0.8 0.1 0.1
Folder structure: /images/image1.jpg /images/image2.jpg /labels/image1.txt /labels/image2.txt
This code loads images and their labels from folders. It reads bounding boxes in normalized form and converts them to pixel values. Then it prints the objects found in each image.
import os from PIL import Image def load_dataset(image_dir, label_dir): dataset = [] for filename in os.listdir(image_dir): if filename.endswith('.jpg') or filename.endswith('.png'): image_path = os.path.join(image_dir, filename) label_path = os.path.join(label_dir, filename.rsplit('.',1)[0] + '.txt') if os.path.exists(label_path): with open(label_path, 'r') as f: labels = [line.strip().split() for line in f.readlines()] image = Image.open(image_path) width, height = image.size objects = [] for label in labels: class_id, x_c, y_c, w, h = label x_c, y_c, w, h = map(float, (x_c, y_c, w, h)) # Convert normalized to pixel coordinates x_center = x_c * width y_center = y_c * height box_width = w * width box_height = h * height objects.append({ 'class_id': int(class_id), 'bbox': [x_center, y_center, box_width, box_height] }) dataset.append({'image': filename, 'objects': objects}) return dataset # Example usage image_dir = 'images' label_dir = 'labels' dataset = load_dataset(image_dir, label_dir) for data in dataset: print(f"Image: {data['image']}") for obj in data['objects']: print(f" Class {obj['class_id']} at {obj['bbox']}")
Make sure your annotation format matches the model you plan to use.
Keep your dataset balanced with enough examples for each class.
Use tools like labelImg or makesense.ai to create annotations easily.
Custom datasets help computers learn to find your special objects.
Annotations link images to object locations using normalized coordinates.
Organize images and labels carefully for smooth training.
Practice
custom object detection dataset?Solution
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.Step 2: Identify the correct purpose
Among the options, only teaching a computer to find specific objects matches the goal of such datasets.Final Answer:
To teach a computer to find specific objects in images -> Option DQuick Check:
Custom dataset purpose = teach detection [OK]
- Confusing dataset purpose with image enhancement
- Thinking dataset creates images instead of labeling
- Assuming dataset compresses images
Solution
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.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.Final Answer:
class_id x_center y_center width height (all normalized between 0 and 1) -> Option AQuick Check:
YOLO labels use normalized center coords [OK]
- Using pixel coordinates instead of normalized
- Confusing bounding box corners with center format
- Mixing class name with class id
2 0.5 0.5 0.25 0.25What are the pixel coordinates of the bounding box corners (x_min, y_min, x_max, y_max)?
Solution
Step 1: Calculate center pixel coordinates
x_center = 0.5 * 640 = 320, y_center = 0.5 * 480 = 240Step 2: Calculate width and height in pixels
width = 0.25 * 640 = 160, height = 0.25 * 480 = 120Step 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 = 300Final Answer:
(240, 180, 400, 300) -> Option CQuick Check:
Center ± half width/height = corners [OK]
- Using width/height as full coordinates instead of half
- Mixing up x and y calculations
- Forgetting to multiply by image dimensions
Solution
Step 1: Understand dataset consistency needs
Training requires each image to have a matching label file with annotations.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.Final Answer:
Remove images without label files from the dataset -> Option AQuick Check:
Dataset must have matching image-label pairs [OK]
- Creating empty label files that confuse training
- Ignoring missing labels causing crashes
- Renaming files without creating labels
Solution
Step 1: Update class list
Add the new object class to your dataset's class list file so the model knows about it.Step 2: Label new images with the new class
Annotate images containing the new object using the new class id in label files.Step 3: Update training configuration
Modify your training config to include the new class count and class names.Final Answer:
Add the new class to the class list, label new images with it, and update training config -> Option BQuick Check:
Update classes, labels, and config for new objects [OK]
- Not updating class list causing training errors
- Forgetting to label new objects
- Ignoring config updates leading to wrong class counts
Ready to prove it?
Pass the test and this pattern moves unknown
