YOLOv8 Red & Green Object Detection Analysis

5 minute read

Published:

YOLOv8 Red & Green Object Detection

πŸ“Œ Project Overview

This project uses YOLOv8 to detect and classify two object classes:

  • 🟩 greenbox
  • πŸŸ₯ redbox

βš™οΈ Training Configuration

After running

yolo detect train model=yolov8n.pt data=data.yaml imgsz=320 epochs=10 batch=16 device=0
ParameterValue
Modelyolov8n
Image Size320
Epochs10
Batch Size16
DeviceGPU (device=0)

πŸ“ Important Output Files

Inside the training folder (runs/detect/train/), the most important files are:

  • results.png βœ… (main training graph)
  • confusion_matrix.png βœ…
  • PR_curve.png βœ…
  • F1_curve.png βœ…
  • weights/best.pt βœ…

πŸ“Š results.png (Main Graph)

Shows:

  • Training & validation loss
  • Precision and recall
  • mAP50 and mAP50-95

βœ” What to check:

  • Loss decreases over time β†’ model is learning
  • Validation follows training β†’ no overfitting
  • mAP increases β†’ performance improves

Result

Throught the Graph we can analyze

1. TRAINING LOSS ANALYSIS

πŸ”Ή train/box_loss

  • Decreases from ~0.75 β†’ ~0.53
  • Smooth and consistent

    Interpretation:

  • Model is improving bounding box localization

    πŸ”Ή train/cls_loss

  • Drops rapidly from ~1.4 β†’ ~0.28
    Interpretation:
  • Model quickly learns to classify redbox vs greenbox
  • Task is relatively easy (distinct colors)

πŸ”Ή train/dfl_loss

  • Gradual decrease

Interpretation:

  • Model is refining bounding box precision

2. Validation Loss Analysis

πŸ”Ή val/box_loss

  • Smooth decrease

Interpretation:

  • Good generalization to unseen validation data

πŸ”Ή val/cls_loss

  • Spike at early epoch (~3)
  • Then decreases steadily

Interpretation:

  • Early training instability (normal)
  • Model stabilizes afterward

πŸ”Ή val/dfl_loss

  • Smooth decreasing trend

Interpretation:

  • Bounding box quality improves on validation data

🚨 Key Concept: Overfitting Check

Training LossValidation LossMeaning
β†“β†“βœ… Good (your case)
β†“β†‘βŒ Overfitting
β†‘β†‘βŒ Poor training

Conclusion:

  • No overfitting observed
  • Model generalizes well

3. Precision Analysis

  • Starts ~0.94
  • Drops briefly
  • Converges to ~1.0

Interpretation:

  • Very few false positives
  • Temporary fluctuation is normal

4. Recall Analysis

  • Similar behavior to precision
  • Ends near 1.0

Interpretation:

  • Model detects almost all objects
  • Very few missed detections

πŸ“Š 5. mAP Analysis (Most Important Metric)

πŸ”Ή mAP50

  • Final value β‰ˆ 0.995

Interpretation:

  • Nearly perfect detection at IoU = 0.5

πŸ”Ή mAP50-95

  • Improves from ~0.81 β†’ ~0.93

Interpretation:

  • Strong performance under stricter evaluation
  • Indicates robust bounding box quality

⚠️ 6. Early Epoch Instability

Observed at epoch ~3:

  • Drop in precision, recall, and mAP

Reason:

  • Random weight initialization
  • Learning adjustment phase

Important:

  • This is normal behavior in training
  • Focus on overall trend, not individual fluctuations

πŸ“‰ 7. Trend vs Raw Values

  • Blue line: actual values
  • Orange line: smoothed trend

Interpretation:

  • Smoothed curve shows true learning behavior
  • Model trend is stable and improving

πŸ“‰ confusion_matrix.png

Shows classification performance:

True \ Predictedgreenboxredbox
greenboxβœ… correct❌ wrong
redbox❌ wrongβœ… correct

What to check:

  • Strong diagonal β†’ good model
  • Off-diagonal β†’ classification errors

Below is the confusing matrix we get after the training

confusion matrix

βœ… Correct Predictions (Diagonal)

  • greenbox β†’ greenbox = 573
  • redbox β†’ redbox = 427

🎯 Interpretation:

  • Model correctly classifies almost all objects
  • Very strong diagonal β†’ excellent performance

❌ Errors (Off-Diagonal)

πŸ”Ή False Positives (FP)

  • 1 background detected as redbox

πŸ‘‰ Meaning:

  • Model detected an object where there is none

πŸ”Ή False Negatives (FN)

  • 1 greenbox missed (predicted as background)
  • 1 redbox missed (predicted as background)

πŸ‘‰ Meaning:

  • Model failed to detect some objects

πŸ“Š Error Summary

Error TypeCount
False Positive1
False Negative2

πŸ‘‰ Total errors = 3 (very low)


πŸ“ˆ Performance Interpretation

βœ… Strengths

  • Nearly perfect classification between red and green
  • Almost no confusion between classes
  • Extremely high accuracy

πŸ“ˆ PR_curve.png (Precision–Recall Curve)

Shows tradeoff between precision and recall.

What to check:

  • Curve near top-right β†’ excellent model
  • Large area under curve β†’ high performance

βœ… 1. Precision–Recall (PR) Curve

Purpose:

  • Shows overall model performance
  • Combines:
    • Precision (accuracy)
    • Recall (completeness)

Why important:

  • Used to compute mAP (main YOLO metric)
  • Best indicator of model quality

PR Curve

Result:

  • Curve near top-right
  • mAP β‰ˆ 0.995

πŸ‘‰ Conclusion: Excellent model


πŸ“ˆ 2. Precision–Confidence Curve (P Curve)

Purpose:

  • Shows how precision changes with confidence threshold

Interpretation:

  • Higher confidence β†’ fewer false positives
  • Model becomes more strict

P Curve

Result:

  • Precision quickly reaches ~1.0
  • Very stable

πŸ‘‰ Conclusion: Predictions are highly accurate


πŸ“‰ 3. Recall–Confidence Curve (R Curve)

Purpose:

  • Shows how many objects are detected as threshold changes

Interpretation:

  • Higher confidence β†’ more missed detections

R Curve

Result:

  • Recall β‰ˆ 1.0 at low confidence
  • Drops sharply after ~0.9

πŸ‘‰ Conclusion: High confidence may miss objects


πŸ“Š F1_curve.png

Shows best balance between precision and recall.

What to check:

  • Peak value β†’ best performance
  • Confidence at peak β†’ optimal threshold

πŸ‘‰ It represents the best balance between Precision and Recall

F1 Curve

πŸ”Ή Shape:

  • F1 is very high (~1.0) across a wide range
  • Drops sharply after ~0.9 confidence

πŸ”Ή Key point:

  • Best F1 β‰ˆ 1.00 at confidence β‰ˆ 0.799

βœ… 1. Excellent Performance

  • F1 β‰ˆ 1.0 β†’ almost perfect balance
  • Means:
    • Very few false positives
    • Very few missed detections

πŸ‘‰ Model is extremely strong


βš–οΈ 2. Optimal Threshold

  • Best confidence β‰ˆ 0.8

πŸ‘‰ This is the ideal operating point

At this point:

  • Precision is high
  • Recall is high
  • Overall performance is maximized

🧠 weights/best.pt

The final trained model.

Use it for inference:

yolo detect predict model=weights/best.pt source=your_image.jpg conf=0.8

1. Detection Output

For example:

 yolo detect predict model=best.pt source=test/images/greenbox_0_jpg.rf.b7606581a957e3d3d3b8a36e5a4d82cb.jpg conf=0.8

Detection

Model detected:

  • 1 object
  • Class = greenbox
  • Inference time = 12.8 ms