Skip to main content
COMPUTER VISION & EDGE AI

Edge Computer Vision in Agricultural Barns: Lessons from Training YOLO11s & Behavior Engine V3 for GrazeAI

CASDO Computer Vision Engineering TeamPublished 2026-10-18 (Updated 2026-11-20)8 min read
EXECUTIVE ENGINEERING SUMMARY

Reliable agricultural computer vision requires solving three engineering bottlenecks that lab benchmarks hide: choosing a lightweight edge-compatible backbone (Ultralytics YOLO11s, 19.18 MB weights), suppressing frame-to-frame posture flicker with temporal state machines (ByteTrack + Behavior Engine V3), and reporting honest precision/recall metrics so pilot operators understand real-world operating bounds.

YOLO11s cattle posture bounding boxes and ByteTrack tracking output in GrazeAI

Key Engineering Takeaways

  • Why raw frame-by-frame YOLO inference creates noisy behavior counts under barn occlusion—and how 15-frame track confirmation and 9-frame smoothing windows resolve flicker.
  • Why we expose real model validation metrics (Precision 79.3%, Recall 66.6%, mAP@50 79.7%, mAP@50-95 54.4%) directly in the GrazeAI /model REST endpoint.
  • How decoupling synchronous /detect requests from asynchronous /jobs/video worker queues prevents API thread starvation.

Why Cloud-Only Video Inference Fails on Commercial Farms

Commercial dairy and beef operations in rural regions rarely have symmetrical fiber uplinks. Streaming even four 1080p RTSP barn cameras continuously to cloud GPUs saturates local LTE links and generates recurring egress and GPU compute costs that quickly outstrip per-animal farm economics.

In GrazeAI, we designed the vision service (FastAPI + PyTorch + Ultralytics YOLO11s) to execute locally on site hardware. At 19.18 MB, the custom-trained cattle_behavior_v1 weights (best.pt) fit comfortably inside edge GPU memory while transmitting only compact JSON behavioral counts (Eating, Lying, Standing) upstream to FarmOS.

The Flicker Problem: Solving Occlusion with Behavior Engine V3

A single-stage detector classifying Eating, Lying, and Standing independently on each frame suffers inevitable oscillation when one cow walks behind another at the feedbunk or dips its head for two seconds. Counting raw detections per frame inflates false transitions and triggers alert fatigue.

To stabilize herd analytics, we paired ByteTrack multi-object association with a deterministic state filter—Behavior Engine V3—that enforces three temporal invariants before accepting a track or state transition:

  • →MIN_CONFIRM_FRAMES = 15: A tracked animal ID is only counted in herd summaries after appearing consistently across 15 sampled frames, rejecting transient false positives from dust or shadows.
  • →SMOOTHING_WINDOW = 9: Per-track posture predictions are smoothed over a rolling 9-frame majority window rather than trusting isolated single-frame argmax scores.
  • →BEHAVIOR_CONFIRM_FRAMES = 7: A behavioral transition (e.g., Standing -> Lying) must hold for 7 consecutive smoothed frames before emitting a state-change event.
GrazeAI Model Provenance & Validation Contract (GET /model)json
{
  "model": "cattle_behavior_v1",
  "architecture": "YOLO11s",
  "classes": { "0": "Eating", "1": "Lying", "2": "Standing" },
  "historical_metrics": {
    "precision": 0.793,
    "recall": 0.666,
    "mAP50": 0.797,
    "mAP50_95": 0.544
  }
}

Honest Accuracy Reporting Over Inflated Marketing Claims

Notice our Recall on cattle_behavior_v1 is 66.6% alongside 79.3% Precision and 79.7% mAP@50. In real barns with overlapping animals and harsh midday contrast, claiming 99% blanket accuracy undermines operator trust the first time a partially hidden cow is missed.

By returning actual historical validation metrics directly on the /model endpoint and separating asynchronous video jobs (/jobs/video) from image inference (/detect), engineering teams and farm managers gain an auditable baseline for v2 dataset expansion—specifically targeting low-light IR cameras and indigenous Cholistani, Sahiwal, and Nili-Ravi herds.

AUTHOR ATTRIBUTION
CASDO Computer Vision Engineering Team
Applied AI & Edge Vision Group, CASDO Technologies

More From the CASDO Knowledge Center

Architecting a Similar System?

Discuss this architecture directly with the CASDO engineering leads who built and benchmarked it.