The Training Pipeline

This section explains how we turned raw images into a mathematical model (.pt file) capable of detecting drowsiness.

🧬 The Concept: Transfer Learning

We didn’t start training the AI from scratch (which would require millions of images and weeks of computing power). Instead, we used Transfer Learning.

How it Works

We started with yolo11m-cls.pt, a model already trained on the ImageNet dataset (millions of general images like dogs, cars, and trees). This model already knows how to recognize edges, circles, and textures. We then “fine-tuned” it to forget about dogs and cars and focus specifically on Open vs. Closed eyes.

graph LR
    Pre[Pre-trained YOLOv11 Weights] --> Freeze[Freeze Early Layers]
    Freeze --> FineTune[Fine-tune on MRL Eye Dataset]
    FineTune --> Val[Validation on Test Set]
    Val --> Export[Best.pt Weights]

⚙️ Training Execution

The training is managed by train_yolo.py. The process follows these strict technical phases:

1. Setup Phase

The model is loaded and the data.yaml is read. The images are resized to and normalized to ensure the math remains stable.

2. The Training Loop (The Epochs)

We ran the model for 75 Epochs. An epoch is one complete pass through the entire training dataset.

  • Forward Pass: Model predicts “Open” or “Closed.”
  • Loss Calculation: Model checks if it was wrong.
  • Backpropagation: Model adjusts its internal weights to be more accurate next time.

3. Validation & Early Stopping

To prevent Overfitting (where the model just memorizes the images instead of learning patterns), we used a patience setting of 100. If the validation accuracy doesn’t improve for 100 checks, training stops automatically.

📊 Training Hyperparameters

ParameterValuePurposeBeginner’s Explanation
Epochs75DurationHow many times the AI “reads” the whole book.
Batch Size8MemoryHow many images the AI looks at before updating its brain.
imgsz224ResolutionThe “glasses” the AI wears; everything is seen as .
Device0 (GPU)SpeedUsing a graphics card makes training faster than a CPU.

Usage

To initiate the pipeline:

python train_yolo.py

Last Updated: 2026-05-03