๐ฏ Advanced Usage โ Custom Objects
This section explains how to change the robot's object detection targets by creating custom datasets, training your own YOLO model, and optimizing detection performance for your LIMO system.
๐ Changing Object Detection Classesโ
Your YOLO detector (object_detector.py) currently loads a custom model:
self.model = YOLO("/home/agilex/krish_ws/runs/detect/mycobot_final2/weights/best.pt")
To change classes:
- Train a new YOLO model with your desired objects.
- Replace the
.ptfile path in the detector node. - Ensure
self.model.namescontains the correct class labels. - Restart the system to load the new model.
๐ก Note: If you only want to filter detections to certain classes, you can check cls_name inside the YOLO callback and ignore others.
๐ธ Custom Dataset Creationโ
1. Collect Imagesโ
Use the LIMO's camera:
ros2 run rqt_image_view rqt_image_view
Take screenshots or record video, then extract frames.
2. Annotateโ
Use LabelImg or Label Studio:
labelImg /path/to/images classes.txt
Export format: YOLO TXT format (one file per image).
3. Organize Datasetโ
dataset/
โโโ images/
โ โโโ train/
โ โโโ val/
โโโ labels/
โ โโโ train/
โ โโโ val/
โโโ data.yaml
Example data.yaml:
train: /absolute/path/to/dataset/images/train
val: /absolute/path/to/dataset/images/val
nc: 3
names: ["objectA", "objectB", "objectC"]
๐ง Model Training Proceduresโ
- Train in Python
- Train via CLI
from ultralytics import YOLO
model = YOLO("yolov8n.pt") # or yolov8s.pt for more accuracy
model.train(
data="/path/to/data.yaml",
epochs=50,
imgsz=640,
batch=16,
device=0 # GPU ID
)
yolo detect train data=/path/to/data.yaml model=yolov8n.pt epochs=50 imgsz=640 batch=16 device=0
After training, your weights will be at:
runs/detect/trainX/weights/best.pt
Update the object_detector.py model path to this file.
โก Detection Optimizationโ
Confidence Threshold (conf)โ
Increase to reduce false positives.
results = self.model.predict(source=color_img, conf=0.6, verbose=False)
Image Sizeโ
Larger sizes improve accuracy, but increase inference time.
Model Variantโ
yolov8n.ptโ fastest, least accurate.yolov8s.ptโ balanced.yolov8m.ptโ most accurate, slower.
GPU Accelerationโ
export CUDA_VISIBLE_DEVICES=0
Class Filteringโ
if cls_name not in ["target_class"]:
return
๐งช Testing Your Modelโ
After swapping the model:
ros2 run object_detector yolo_detector
Look for:
โ
YOLO detector node initialized with synchronized inputs.
[๐ DETECTED] target_class 2D(320,240) 3D(0.42, 0.15, 0.80)
Verify:
- Bounding boxes appear correctly in
/yolo/annotated. /target_posepublishes when your target is detected.
If detection is unstable, collect more diverse training images with different lighting, angles, and distances.
Next: ๐ Customizing Waypoints