Skip to content

About

Varroa mite detection on honeybees: fine-tuned YOLO detectors towards a beekeeper hive-scanning app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

varroa-vision

Fine-tuned object detection of Varroa destructor mites on honeybees, built towards an Android app that lets a beekeeper film a comb and get a mite count per 100 bees.

Problem

Varroa treatment decisions are made on a per-100-bee infestation rate, conventionally measured by washing roughly 300 adult bees (alcohol wash or sugar roll) and counting the dislodged mites. The wash is destructive and tedious, so most hobby beekeepers skip it. This project replaces the wash with a camera: film the bees on a comb until about 300 distinct bees have been seen, detect the mites riding on them, and report the rate with a confidence interval.

Two things make this harder than "run a detector on a photo":

  1. Bees move. A video of a comb shows the same bee many times, so bees must be tracked across frames and counted once, and mite evidence must be pooled per bee.
  2. A mite is 1-2 mm on a 12 mm bee. On a frame of a whole comb it is a few pixels wide, so mites are detected on per-bee crops, not on the full frame.

Approach

Two-stage pipeline, each stage a small YOLO model that can run on a phone:

Stage Input Output Training data
1. Bee detector + tracker video frame of a comb bee boxes with persistent track IDs EV2, BEEHIVE (bee boxes on frames)
2. Mite detector crop of one bee mite boxes on that bee VarroaDataset (13,509 single-bee crops, 4,628 mite boxes)

The app then aggregates: unique bees seen, bees with at least one confirmed mite, mites per 100 bees, and a binomial confidence interval on that rate.

Stage 2 is the first priority because it is the hard, data-rich part and it can be validated cleanly on held-out recording sessions. See docs/ for dataset notes, related work and the open sampling-methodology question.

Status

  • Repo scaffold
  • VarroaDataset download and conversion to YOLO format (official and date-grouped splits)
  • EV2 (bee-level cross-domain test) and BEEHIVE (bee boxes) conversion
  • Stage 2 recipe settled over 11 runs: yolo11n, 320 px, mosaic; test mAP50 0.80, bee-level sensitivity 0.84 / specificity 0.96, rate within 5% (docs/results.md)
  • Date-grouped split (honest in-domain): test mAP50 0.70, bee-level sensitivity 0.87 / specificity 0.97
  • Cross-camera test on held-out EV2 videos: 0% sensitivity for VarroaDataset-only models, 14% after adding pseudo-labelled EV2 crops. The domain gap, not the recipe, is the open problem
  • Third domain from internet photos (Roboflow Universe, 1,062 source images) and model selection on a mixed validation set: internet held-out mAP50 0.78, EV2 held-out sensitivity 0.34 at zero false positives, in-domain unchanged
  • Stage 1 on phone comb photos: the in-hive-camera model scores 0.008 mAP50 there; 160 comb photos lift it to 0.30. More comb photos are the lever
  • TFLite export (float32 and INT8, 2.9 MB) with bee-level parity to the PyTorch model, plus a model card with the runtime constants
  • Stage 1 run 1 on BEEHIVE: mAP50 0.95 on test (in-hive cameras, not phone footage)
  • Tracking + per-bee aggregation + stopping rule (unit-tested with fake models; no real comb video yet)
  • Export to TFLite and build the Android app
  • Field calibration of camera counts against alcohol-wash counts

Layout

src/varroa_vision/   library code (data download/conversion, training, evaluation, export)
configs/             training configs (one YAML per experiment)
scripts/             thin CLI entry points
docs/                datasets, related work, sampling methodology, roadmap
tests/               unit tests on synthetic data (no dataset download needed)
data/                raw downloads (gitignored)
datasets/            converted YOLO datasets (gitignored)
runs/                training outputs (gitignored)

Quickstart

uv sync
uv run python -m varroa_vision.data.zenodo varroa_dataset      # 1.2 GB
uv run python -m varroa_vision.data.varroa_dataset             # -> datasets/varroa_mite
uv run python -m varroa_vision.train --config configs/mite_yolo11n.yaml --device 0
uv run python -m varroa_vision.evaluate --weights runs/mite/yolo11n_320_official/weights/best.pt --split val
uv run python -m varroa_vision.evaluate --weights ... --split test --conf <chosen on val>

# cross-domain check on EV2 crops (bee-level only, no mite boxes there)
uv run python -m varroa_vision.data.zenodo ev2                 # 1.1 GB
uv run python -m varroa_vision.data.ev2                        # -> datasets/ev2_bees
uv run python -m varroa_vision.evaluate --weights ... --data datasets/ev2_bees/data.yaml --split all --bee-only

# mobile export: saved_model writes best_float32.tflite and best_float16.tflite via onnx2tf
uv sync --extra export-tflite
uv run python -m varroa_vision.export --weights ... --formats saved_model onnx
uv run python -m varroa_vision.evaluate --weights runs/mite/<run>/weights/best_saved_model/best_float32.tflite --split val   # parity check
# INT8 goes through LiteRT in a separate env (torch < 2.14): sh scripts/make_export_env.sh, then
# .venv-export/bin/python -m varroa_vision.export --weights ... --formats tflite --quantize 8 --data datasets/varroa_mite/data.yaml

# compare runs in one table
uv run python -m varroa_vision.compare runs/mite/* --ev2 datasets/ev2_pseudo/data.yaml --ev2-split test

Training on a machine without git: scripts/deploy_lynx.sh user@host pushes HEAD over ssh.

License

AGPL-3.0. The detectors are built with Ultralytics YOLO, which is AGPL-3.0 licensed, and weights fine-tuned from Ultralytics pretrained checkpoints inherit that license. The app and all code here are open source, so this is compatible with the project's purpose. Datasets keep their own licenses (CC BY 4.0 for VarroaDataset, EV2 and BEEHIVE); see docs/datasets.md for citations.

About

Varroa mite detection on honeybees: fine-tuned YOLO detectors towards a beekeeper hive-scanning app

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages