Varroa Object Detection Notes
Data
Repo data is already split as:
train|val|test/
videos/<video-id>/*.png
labels/<video-id>/*.txt
Each label file starts with an object count, then one or more boxes in absolute
pixel x1 y1 x2 y2 format. Class 0 is varroa.
All current images are 160x280 pixels. The custom LMNet detector defaults to
input_width=160, input_height=288, so it preserves width and only pads height
to a stride-16 friendly size. YOLO baselines can still use larger imgsz values
because Ultralytics handles resizing internally.
YOLOv8 Breakdown
YOLOv8 detection is usually organized as:
image
-> Backbone: Conv/C2f/SPPF feature extractor
-> Neck: PAN-FPN feature fusion, typically P3/P4/P5
-> Head: decoupled anchor-free box/class branches
-> Loss: bbox regression + classification + DFL
For this dataset, the useful hook points are:
- Backbone replacement: try LMNet encoder features instead of YOLO C2f stages.
- Neck replacement: keep PAN/FPN behavior because Varroa is small and multi-scale fusion matters.
- Head replacement: easiest to test outside Ultralytics first with a small anchor-free head.
YOLOv10 Breakdown
YOLOv10 keeps the YOLO-style backbone/neck/head split, but its training/inference design focuses on NMS-free detection via dual assignment:
image
-> Backbone: efficient CSP/C2f-style stages
-> Neck: PAN-FPN
-> Head: one-to-many branch for training signal + one-to-one branch for final prediction
-> Inference: designed to avoid NMS
This makes YOLOv10 less convenient to partially rewire unless you are editing the detector internals. Use it first as a baseline through Ultralytics, then compare with the standalone LMNet detector.
LMNet Detector In This Folder
Implemented path:
image
-> LMNetBackbone
stem: stride 1
stage2: stride 2
stage3: stride 4 -> P3
stage4: stride 8 -> P4
p5: stride 16 -> P5, optional PyramidPool + GFT
optional NATTEN local attention on P3/P4/P5
-> YOLOPANNeck
upsample + concat top-down
downsample + concat bottom-up
-> FCOSHead
class logit
l/t/r/b box distances
centerness
-> FCOSLoss
Files:
architectures/lmnet_backbone.py: LMNet encoder adapted from the segmentation model.architectures/common.py: FPN/PAN neck blocks and feature location helpers.architectures/fcos_head.py: detection head.architectures/lmnet_fcos.py: full model and prediction decode.losses.py: FCOS-style assignment/loss.metrics.py: IoU, NMS, precision/recall/F1.data/varroa_detection_dataset.py: direct loader for current data layout.
Commands
Prepare YOLO-format data:
python object_detection_related/prepare_yolo_dataset.py --root . --out-dir yolo_varroa_dataset
Train YOLOv8 baseline:
python object_detection_related/train_yolo_varroa.py train \
--root . \
--weights yolov8n.pt \
--epochs 100 \
--imgsz 640 \
--batch-size 8 \
--name yolov8n_varroa
Train YOLOv10 baseline, if your Ultralytics install has YOLOv10 weights:
python object_detection_related/train_yolo_varroa.py train \
--root . \
--weights yolov10n.pt \
--epochs 100 \
--imgsz 640 \
--batch-size 8 \
--name yolov10n_varroa
Evaluate a YOLO checkpoint:
python object_detection_related/train_yolo_varroa.py eval \
--root . \
--split test \
--weights runs_yolo_varroa/yolov8n_varroa/weights/best.pt
Evaluation logs fixed-threshold precision/recall/F1 at --conf and COCO-style
single-class mAP50 / mAP50_95. AP candidates are collected with
--map-conf 0.001 by default, then fixed-threshold metrics are filtered back to
--conf.
Train LMNet + detection head:
python object_detection_related/train_lmnet_detector_varroa.py \
--root . \
--input-height 288 \
--input-width 160 \
--batch-size 4 \
--epochs 100 \
--gft-kind global \
--gft-bottleneck 128 \
--checkpoint checkpoints/lmnet_fcos_varroa_best.pt
Train LMNet + YOLO-style PAN neck + NATTEN local attention:
python object_detection_related/train_lmnet_detector_varroa.py \
--root . \
--input-height 288 \
--input-width 160 \
--batch-size 4 \
--epochs 100 \
--neck pan \
--local-attention natten \
--local-attention-kernel 3 \
--gft-kind global \
--gft-bottleneck 128 \
--checkpoint checkpoints/lmnet_pan_natten_varroa_best.pt
Cheap ablation without PyramidPool/GFT:
python object_detection_related/train_lmnet_detector_varroa.py \
--root . \
--input-height 288 \
--input-width 160 \
--batch-size 4 \
--epochs 100 \
--neck pan \
--no-pyramid \
--local-attention none
Evaluate LMNet + detection head:
python object_detection_related/eval_lmnet_detector_varroa.py \
--root . \
--split test \
--checkpoint checkpoints/lmnet_fcos_varroa_best.pt
Training CSV columns include val_map50, val_map50_95, val_ap50,
val_ap55, ..., val_ap95. The best checkpoint defaults to
--best-metric map50_95.
Suggested Experiment Order
yolov8n.ptbaseline.yolov10n.ptbaseline if available in your environment.LMNetBackbone + YOLOPANNeck + FCOSHeadwith--no-pyramid --local-attention none.LMNetBackbone + YOLOPANNeck + FCOSHeadwith--gft-kind global.- Add
--local-attention nattenafter the non-attention variant trains cleanly. - Compare F1/precision/recall on the same
testsplit and same confidence threshold.