Use your own objects and keep an honest final test

Replace the sample data with labeled photographs, train a candidate, and preserve a checkpoint with evidence of its limits.

Guided walkthrough·Intermediate·6 min read
Requirements and learning goals

Before you start

  • The working training project from lessons 2 and 3
  • Photographs of two chosen object classes for the own-object exercise
  • A way to inspect pixel coordinates or export YOLO box labels

You will be able to

  • Prepare and validate a custom image dataset
  • Train and evaluate a model without tuning on its test set
  • Run a saved checkpoint on a separate image

Replace the sample with a real task

The block-and-disk checkpoint does not recognize arbitrary objects. To teach washers and bolts, collect and label washers and bolts, change the class names, and train again. Use the synthetic run as a working reference while preparing your own data.

Capture separate sessions for training, validation, and test. Vary backgrounds, distance, lighting, orientation, and object count within each session. Include empty scenes and visually similar non-target objects. Keep the whole session in one split. There is no image count that guarantees a reliable detector; start with a manageable collection, inspect its errors, and add representative examples. Each split should contain examples of both classes so you can assess both.

Reserve one additional image for trying the final saved model. Do not use it for training or to select the threshold.

Create the dataset structure

Beside workshop.py, create my-objects/images/train, my-objects/images/val, and my-objects/images/test, plus matching folders under my-objects/labels. Place PNG or JPEG photographs in the image folders. Each needs a same-stem .txt label, including empty files for intentionally empty scenes. Use distinct filenames within each split.

You can export boxes from an annotation tool, or write the text files manually from measured pixel boxes. Use class 0 for washer and class 1 for bolt. For example, a washer box spanning (100, 60) to (180, 140) in a 400 by 200 image has center (140, 100) and size (80, 80), giving:

0 0.35 0.5 0.2 0.4

Write one line for every target object. Inspect labels overlaid on images in your annotation tool, or verify several corners by converting normalized coordinates back into pixels. Check small and partly occluded objects using the labeling rule you wrote in lesson 1.

Generate the configuration and check the data:

python workshop.py configure --dataset my-objects --classes washer bolt
python workshop.py validate --dataset my-objects

The validator checks missing labels, class IDs, box bounds, and exact duplicate image bytes across splits. It cannot detect differently encoded copies or near-duplicate frames, so you still need the capture-session rule. The configuration uses an absolute path; update it if you move the directory.

Checkpoint 1 of 2

You save one photograph as a PNG in the training folder and as a JPEG in the test folder. The validate command passes. Is the split clean?

Commit to an answer. Every choice explains itself.

Train and choose on validation data

python workshop.py train --dataset my-objects --epochs 20 --name own-objects
python workshop.py evaluate --dataset my-objects --model runs/own-objects/weights/best.pt --split val --confidence 0.25 --output reports/own-val-025

Inspect the mistakes. Add new training captures of conditions that are missing, correct inconsistent labels, and train another run under a different name. Use validation data to compare candidates and select a threshold. The 160-pixel training resolution is intentionally small for the workshop and may lose small objects; this first model is a baseline, not a promised production result.

Freeze a choice and run the final test

After choosing the checkpoint and threshold, record both and evaluate the untouched test split once. The command below uses 0.25 as an example; replace it with the threshold you selected on validation data.

python workshop.py evaluate --dataset my-objects --model runs/own-objects/weights/best.pt --split test --confidence 0.25 --output reports/own-final-test
python workshop.py predict --model runs/own-objects/weights/best.pt --image separate-photo.jpg --confidence 0.25 --output predictions/own-photo

Place your separate image at separate-photo.jpg before the prediction command.

Finish the supplied example without a camera

If you only have the generated dataset today, save this as make_scene.py. It draws a new scene independently of the fixed-seed dataset generator. Re-running prepare would reproduce the old images, not make a new test.

from PIL import Image, ImageDraw
 
image = Image.new("RGB", (160, 160), (65, 75, 80))
ImageDraw.Draw(image).ellipse((45, 55, 115, 125), fill=(230, 190, 170))
image.save("new-scene.png")

After choosing the baseline and threshold on validation data, run:

python workshop.py evaluate --split test --confidence 0.25 --output reports/sample-final-test
python make_scene.py
python workshop.py predict --image new-scene.png --confidence 0.25 --output predictions/new-scene

Inspect whether the prediction identifies the one disk and whether its box fits. Record a miss or false alarm if one occurs. This completes the sample workflow, not the own-object project.

Check the expected result

Keep the checkpoint, class mapping, dataset manifest or capture inventory, resolved requirements, chosen threshold, and final report together. Prediction produces prediction.jpg with boxes and prediction.json with class IDs, names, confidence, and pixel coordinates. An empty JSON list means no accepted detections, not a successful recognition.

The own-object project is complete when the model has been trained on your labeled photographs, evaluated on held-out sessions, and run on the separate photograph. State its observed failures alongside its scores. If you change the model because of the final test result, that test has become development feedback; reserve new data for a future independent assessment.

Checkpoint 2 of 2

The final test shows many missed bolts. You add training photographs of bolts, retrain, and evaluate the same test split again. How should you treat the new test score?

Commit to an answer. Every choice explains itself.

Troubleshooting

For malformed labels, check five fields per line, integer class IDs, positive box sizes, and normalized boxes entirely inside the image. If the class names still say block and disk, you selected the synthetic checkpoint. If training appears good but new scenes fail, inspect leakage, missing conditions, and labeling consistency before simply increasing epochs. A perfect score on a tiny test set is weak evidence about unfamiliar environments.

For device deployment after local evaluation, continue with vision and edge inference. A saved checkpoint alone does not verify speed or accuracy on your target device.

Can you do each of these?

  • Prepare and validate a custom image dataset
  • Train and evaluate a model without tuning on its test set
  • Run a saved checkpoint on a separate image

0 of 2 checkpoints solved. Try checkpoint 1

Previous: Measure mistakes on unseen scenes
All lessons in this topic
  1. 1. Choose objects, label boxes, and split scenes
  2. 2. Train a small detector on a supplied dataset
  3. 3. Measure mistakes on unseen scenes
  4. 4. Use your own objects and keep an honest final test

Ask Wendy

Answers about Wendy and WendyOS

What would you like to know?

Ask about devices, development, and deployment.

Check linked docs for technical details.