Train a small detector on a supplied dataset
Generate labeled images, fine-tune YOLO11n locally, and save a checkpoint you can evaluate.
Opening the Python editor…
Requirements and learning goals
Before you start
- The labeling and splitting lesson
- Python 3.11 or 3.12 on a laptop or desktop
- Internet for packages and initial model weights; no GPU or Wendy device
You will be able to
- Create separate labeled image splits
- Run an actual detector training job
- Locate and preserve the trained checkpoint
Train a model you can inspect
This lesson fine-tunes YOLO11n on two custom classes, block and disk. It uses generated images so the first run does not depend on a camera, annotation account, or private dataset. You will later replace these images with photos of your own objects.
Training changes the model's weights. Moving a confidence slider does not train anything; it only changes which predictions you accept. Keep that distinction in mind when comparing the browser exercise with this command-line project.
The images are deliberately simple. Good scores on them show that the training and evaluation workflow runs. They do not show that the model recognizes real workshop parts. Set aside time for installation and downloads; training time depends on your computer.
Prepare the environment
Download the custom detector starter, extract it, and open a terminal in its custom-detector directory. It contains workshop.py, requirements.txt, and a README. Check python3 --version on macOS or Linux, or py -3.12 --version on Windows. Use Python 3.11 or 3.12 for this project.
On macOS or Linux:
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
python -m pip freeze > requirements-resolved.txtOn Windows PowerShell:
py -3.12 -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
python -m pip freeze > requirements-resolved.txtIf using Python 3.11 on Windows, replace -3.12 with -3.11. Keep the resolved requirements with your experiment. Dependencies include PyTorch, so the download is larger than the starter ZIP.
Generate and inspect the data
python workshop.py prepare
python workshop.py validateExpect 80 training, 20 validation, and 20 test images. Every fifth image is an empty negative. The generator creates a label text file for every image, a data.yaml with class names and paths, and a manifest containing image hashes. Separate random seeds generate each split. Do not edit the test set while choosing training settings.
Open dataset/images/train/train-001.png and its file in dataset/labels/train. Check the box format using the preceding lesson. Open train-000.png and confirm that its label file is empty.
Train and preserve the result
python workshop.py train --epochs 20 --name baselineThe first run downloads pretrained weights. The script then trains on the CPU with images resized to 160 pixels, batches of eight, and a fixed seed. Each epoch is another pass through the training data. The validation split helps select the saved best checkpoint. The test split is not used by training.
Check the expected result
The run produces runs/baseline/weights/best.pt, last.pt, and results.csv beneath the run directory. The printed checkpoint path should match the file you see. Losses and evaluation scores need not match another computer exactly. A completed run with poor validation performance is still something to investigate, not a reason to discard inconvenient results.
You are done when you can identify the training images, validation images, and saved checkpoint. Keep the dataset, manifest, run configuration, and resolved requirements together so the following lesson evaluates the same experiment.
Troubleshooting
For a missing module, activate .venv and reinstall requirements. If the weights download fails, restore internet access and retry. If baseline already exists, use a new name such as baseline-2; the script preserves earlier runs. If you move the dataset, update the absolute path in data.yaml before validation. If your computer cannot run PyTorch, the browser lesson still works, but this training step requires a supported Python environment.
Reference: Ultralytics training API.
Before you move on
Can you do each of these?
- Create separate labeled image splits
- Run an actual detector training job
- Locate and preserve the trained checkpoint
0 of 2 checkpoints solved. Try checkpoint 1