Train Your Object Detection Model

Train Your Object Detection Model

Train a model to detect and locate objects in new images.

Training Configuration

Monitor Training Progress

Object Detection Metrics

MetricDescriptionTarget
mAP@0.5Average precision at 50% IoU> 0.7
mAP@0.5:0.95Average across IoU thresholds> 0.5
PrecisionHow many detections are correct> 0.8
RecallHow many objects are found> 0.8
F1 ScoreBalance of precision/recall> 0.75

IoU (Intersection over Union)

Predicted box: ┌──────┐
               │ ████ │ ← Overlap (intersection)
Actual box:    │ ████ ┐
               └──────┘ │
                        │
               └────────┘

IoU = Intersection Area / Union Area

Training Results

View Results

# Get trained model
model = client.get_model(job.model_id)

# View per-class performance
for cls in model.class_metrics:
    print(f"{cls['name']}: AP={cls['ap']:.3f}")

# View confusion matrix
confusion = model.confusion_matrix

Test on Sample Images

# Run inference on test images
results = client.predict(
    model_id=model.id,
    item="./test_image.jpg"
)

for detection in results.inference_items:
    print(f"Found {detection.prediction} at ({detection.x}, {detection.y})")
    print(f"  Size: {detection.width}x{detection.height}")
    print(f"  Confidence: {detection.confidence:.2%}")

Hyperparameter Tuning

Key Parameters

ParameterEffectTypical Range
Learning rateTraining speed/stability0.0001 - 0.01
Batch sizeGPU utilization, generalization8-64
Image sizeDetail vs speed320-1280
Confidence thresholdPrecision vs recall0.25-0.7
NMS thresholdDuplicate filtering0.3-0.6

Auto-Tune

# Run hyperparameter search
search = client.create_hyperparam_search(
    dataset_id=dataset.id,
    search_space={
        "learning_rate": [0.001, 0.0001, 0.00001],
        "batch_size": [8, 16, 32],
        "image_size": [416, 640]
    },
    metric="map_50",
    max_trials=10
)

Best Practices

  1. Start with pre-trained weights - Faster convergence
  2. Use augmentation - Especially mosaic for detection
  3. Monitor mAP, not just loss - Loss can decrease while mAP plateaus
  4. Balance classes - Oversample rare classes if needed
  5. Test early - Run inference after 50% training to catch issues

Troubleshooting

ProblemLikely CauseSolution
Low mAPInsufficient dataAdd more images, use augmentation
High loss, no improvementLearning rate too highReduce learning rate
Detects wrong classesLabel inconsistencyReview and fix annotations
Misses small objectsImage size too smallIncrease image_size
Many false positivesLow quality annotationsReview annotation quality

Next Step

4. Deploy →