YOLOv4-tiny + GA Hyperparameter Optimization for Palm FFB Maturity Detection

Replication and open-source release of:

Salim, F. and Suharjito (2023). Hyperparameter optimization of YOLOv4 tiny for palm oil fresh fruit bunches maturity detection using genetics algorithms. Smart Agricultural Technology 6, 100364. https://doi.org/10.1016/j.atech.2023.100364

Four YOLOv4-tiny variants trained on the Roboflow palm ripeness dataset (6 classes, 14106 images), with the learning rate selected by a Genetic Algorithm (5 generations x 10 individuals, fitness = mAP@0.50 at 3000 iters).

GitHub source: dutaav/yolov4-tiny-hpo-ffb-maturity

Results (test set, mAP@0.50)

Variant mAP Precision Recall F1 Learning rate Stop iter
Baseline 87.99% 0.591 0.842 0.695 0.00261 12000
Baseline + ES 85.94% 0.603 0.861 0.709 0.00261 6430
GA-tuned (best) 89.75% 0.626 0.891 0.735 0.007003 10593
GA + ES 86.23% 0.624 0.847 0.718 0.007003 4258

GA found LR = 0.007003, within 6% of the paper-reported 0.007465, independently validating the search procedure. Plain Early Stopping (patience = 5 mAP evals) underperforms in both configurations because the patience is too tight for the higher LR found by GA.

Per-class AP@0.50 (test set, best GA model)

Class GT AP
abnormal 259 94.61%
janjang kosong 246 95.76%
kurang masak 380 82.02%
masak 213 92.83%
mentah 362 79.09%
terlalu masak 272 94.18%

The two intermediate ripeness classes (kurang masak, mentah) are the hardest; the rest exceed 92% AP.

Repository layout

runs/h100-hankai/
  artifacts/         metrics.json, training_info.json, ga_history.json
  configs/           4 Darknet .cfg files actually used for training
  weights/           4 *_best.weights (model1..model4)
  logs/              training logs + per-split eval outputs

All four .weights files are 23.6 MB each. The best (GA-tuned) model is runs/h100-hankai/weights/model3_ga_best.weights.

How to use (OpenCV DNN, no Darknet build required)

import cv2
import numpy as np
from huggingface_hub import hf_hub_download

REPO = "dutaav/yolov4-tiny-hpo-ffb-maturity"
RUN = "runs/h100-hankai"

cfg = hf_hub_download(REPO, f"{RUN}/configs/model3_ga.cfg")
weights = hf_hub_download(REPO, f"{RUN}/weights/model3_ga_best.weights")

net = cv2.dnn.readNetFromDarknet(cfg, weights)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_OPENCV)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)

CLASSES = ["abnormal", "janjang kosong", "kurang masak",
           "masak", "mentah", "terlalu masak"]

img = cv2.imread("your_image.jpg")
blob = cv2.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False)
net.setInput(blob)
outputs = net.forward(net.getUnconnectedOutLayersNames())
# post-process outputs with NMS (cv2.dnn.NMSBoxes); see scripts/run_inference.py
# in the GitHub repo for the full pipeline.

A complete inference notebook is provided at colab_inference/PalmYOLOv4_Inference.ipynb (runs on free Colab T4, pulls weights from this repo).

Training setup

  • Framework: Darknet (hank-ai fork), CMake build. The AlexeyAB fork has a cuDNN BAD_PARAM crash at iter 1000 during in-training mAP evaluation; hank-ai PR #36 fixes it.
  • Hardware: NVIDIA H100 80GB on Modal cloud.
  • Input size: 416 x 416. Batch 64, subdivisions 16.
  • Schedule: 12000 iterations (Early Stopping variants may stop earlier), steps at 9600 and 10800.
  • Augmentation: mosaic, default Darknet color jittering.

The full pipeline (build + dataset prep + 4 trainings + GA + eval + HF upload) is in modal_training/app.py. End-to-end run cost on H100: roughly USD 8 to 12.

Dataset

Roboflow project tugas-akhir-pybma/palm-ripeness-detection, version 5, Darknet export format. 6 classes, 11614 train / 1657 valid / 835 test images. This is a different dataset version than the one used by Salim and Suharjito (2023), so absolute numbers differ slightly while the qualitative findings (GA > Baseline > GA+ES > ES) are reproduced.

Citation

If you use these weights or the pipeline:

@misc{dutaav2026palmyolov4ga,
  title  = {YOLOv4-tiny with Genetic Algorithm hyperparameter optimization
            for palm oil FFB maturity detection (replication of
            Salim and Suharjito 2023)},
  author = {dutaav},
  year   = {2026},
  url    = {https://huggingface.co/dutaav/yolov4-tiny-hpo-ffb-maturity}
}

@article{salim2023palmyolov4ga,
  title   = {Hyperparameter optimization of YOLOv4 tiny for palm oil fresh
             fruit bunches maturity detection using genetics algorithms},
  author  = {Salim, Faisal and Suharjito},
  journal = {Smart Agricultural Technology},
  volume  = {6},
  pages   = {100364},
  year    = {2023},
  doi     = {10.1016/j.atech.2023.100364}
}

License

MIT for the code and weights. Dataset belongs to its original Roboflow project and is subject to the dataset license. YOLOv4 architecture and Darknet are credited to their respective authors.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support