The pre-trained COCO model detects everyday objects. In this tutorial you will train your own model to detect the specific defects or objects that matter for your use case — scratches, cracks, missing components, or anything else you need to find.
What you will learn
- How to collect and annotate your own image dataset
- How to structure a YOLOv8 training dataset (YAML format)
- How to train on Google Colab (free GPU) and export to TensorRT
- How to deploy your custom model on Jetson and run inference
- How to evaluate model accuracy with mAP metrics
Step 1 — Collect your images
Aim for at least 200 images per defect class. Use the included capture script to take photos with the Jetson camera and save them automatically:
cd ~/tutorials/02-custom-defect-detection
python3 capture_images.py --output ./dataset/images/train --count 200
Step 2 — Annotate with Label Studio (pre-installed)
# Start Label Studio annotation tool (pre-installed on your kit)
label-studio start --port 8080
Open http://localhost:8080 in your browser. Import your images, draw bounding boxes around each defect, label them, and export in YOLO format.
Step 3 — Create your dataset config
# dataset/data.yaml
path: /home/user/tutorials/02-custom-defect-detection/dataset
train: images/train
val: images/val
nc: 2 # number of classes
names: ['scratch', 'crack'] # your class names
Step 4 — Train on Google Colab (free GPU)
# Run this in Google Colab (free T4 GPU)
!pip install ultralytics
from ultralytics import YOLO
model = YOLO("yolov8s.pt") # start from pretrained weights
model.train(
data = "data.yaml",
epochs = 100,
imgsz = 640,
batch = 16,
device = 0
)
# Best weights saved to: runs/detect/train/weights/best.pt
Step 5 — Export to TensorRT and copy to Jetson
# In Colab — export to TensorRT engine
model.export(format="engine", half=True, imgsz=640)
# Downloads: best.engine
# On Jetson — copy and run
python3 detect.py --model ~/my_models/best.engine --source 0 --show