Skip to main content
COMPUTER VISION & EDGE AISTATUS: VALIDATED PROTOTYPE

GrazeAI — Livestock Posture & Behavior Computer Vision

Ultralytics YOLO11s and ByteTrack livestock behavior classification engine (Eating, Lying, Standing) with Behavior Engine V3 temporal smoothing.

Current Implementation Status: Working FastAPI + YOLO11s (best.pt) image and asynchronous video inference service with Behavior Engine V3; live continuous RTSP barn deployment staged for pilot hardware installation.

GrazeAI YOLO11s cattle posture detection and livestock behavior computer vision interface

Industry Context & Problem Statement

Commercial dairy and beef feedlot operators rely on early observation of feeding drop-offs and abnormal lying duration to catch metabolic or lameness issues early. Manual round-the-clock pen observation across large herds is labor-intensive and inconsistent.

Observing herd feeding and resting patterns manually is intermittent and misses nighttime behavioral changes. Sending continuous multi-camera RTSP video to cloud GPUs is prohibitively expensive and unreliable on rural broadband links.

Proposed Solution & Technical Challenge

CASDO Technologies trained a dedicated Ultralytics YOLO11s livestock behavior model (best.pt) and built the GrazeAI FastAPI Vision Service. Combined with ByteTrack and Behavior Engine V3 temporal smoothing, GrazeAI processes barn images and video feeds locally, counts animals per behavioral state (Eating, Lying, Standing), generates annotated bounding-box video outputs, and logs structured behavioral summaries into FarmOS.

Core Architectural Challenge

Detecting and persistently tracking multiple cattle under dusty barn optics, shifting natural sunlight, and frequent animal-to-animal occlusions while suppressing frame-to-frame classification flicker without requiring raw HD video uploads over rural internet connections.

SYSTEM ARCHITECTURE

Architecture Breakdown

  • Detection Core: Ultralytics YOLO11s single-stage detector (19.18 MB weights) outputting per-animal bounding boxes, class labels, and confidence scores.
  • Behavior Engine V3: Stateful track manager applying ByteTrack association, 15-frame track confirmation, 9-frame rolling smoothing windows, and 7-frame behavior transition confirmation to filter occlusion noise.
  • Asynchronous Job Worker: Background thread pool processing uploaded MP4/AVI/MOV streams into annotated H.264/MP4V videos with per-frame behavior timelines.
  • FarmOS Vision Bridge: In-process or HTTP proxy adapter saving inference artifacts into multi-tenant vision_jobs tables tagged with LIVE_INFERENCE provenance.
VERIFIED STACK

Implemented Technology Stack

  • Vision Model: Custom-trained Ultralytics YOLO11s weights (cattle_behavior_v1, best.pt, 19.18 MB) classifying 3 posture classes: Eating, Lying, Standing
  • Tracking & Smoothing: ByteTrack multi-object tracking paired with Behavior Engine V3 (MIN_CONFIRM_FRAMES=15, SMOOTHING_WINDOW=9, BEHAVIOR_CONFIRM_FRAMES=7)
  • Inference Microservice: Python FastAPI (v3.0.0), PyTorch, OpenCV, Pillow, asynchronous video processing job queue (/jobs/video, /detect, /detect-video, /model)
  • Integration Workspace: GrazeAI Studio canvas UI integrated into FarmOS with persistent VisionJob database records and annotated MP4 playback
Ultralytics YOLO11sPyTorchByteTrackOpenCVFastAPIPythonNext.js / Canvas UI
EXECUTION METHODOLOGY

Implementation Methodology

  1. Curated annotated cattle posture datasets spanning Eating, Lying, and Standing states across varied camera angles.
  2. Trained and benchmarked YOLO11s (best.pt) and logged transparent precision, recall, and mAP@50/mAP@50-95 metrics directly on the /model API endpoint.
  3. Engineered Behavior Engine V3 to resolve transient ID switches and posture flicker during dense feedbunk occlusions.
  4. Integrated the standalone FastAPI microservice into the FarmOS workspace with automated pytest verification.
TRADE-OFFS & RATIONALE

Key Engineering Decisions

  • Selected YOLO11s over heavier two-stage detectors to balance detection accuracy with local edge hardware feasibility (19.18 MB model footprint).
  • Exposed historical validation metrics (Precision 0.793, Recall 0.666, mAP@50 0.797) directly in the /model API response so engineering teams and pilot farms inspect realistic accuracy bounds rather than inflated claims.
  • Separated asynchronous video job execution (/jobs/video) from synchronous image inference (/detect) to prevent request thread starvation.

Measured & Verified Outcomes

  • Trained and evaluated custom YOLO11s weights (cattle_behavior_v1 / best.pt) with recorded validation metrics: Precision 79.3% (0.793), Recall 66.6% (0.666), mAP@50 79.7% (0.797), and mAP@50-95 54.4% (0.544).
  • Eliminated single-frame class oscillation in video analytics through Behavior Engine V3 temporal confirmation windows and track stability thresholds.
  • Engineered non-blocking asynchronous video job orchestration with MIME/size validation (25 MB image / 600 MB video limits) and persistent farm/herd linkage.
  • Preserved 100% backward-compatible REST endpoints (/detect, /detect-video, /model) alongside multi-tenant FarmOS API routes.

Known Limitations & Scope Boundaries

  • •Current status is a Validated Prototype operating on uploaded barn imagery and video recordings; continuous 24/7 live RTSP barn camera arrays are architected and staged pending on-farm camera mounting and edge GPU provisioning.
  • •Recall (66.6% on cattle_behavior_v1) drops under severe nighttime IR glare or extreme multi-animal overlap; expanding training data across local Pakistani dairy breeds (Cholistani, Sahiwal, Nili-Ravi) and low-light IR feeds is scheduled for v2 model retraining.
  • •Clinical early-warning lead times (e.g., illness alerts hours before symptoms) require longitudinal multi-month veterinary ground-truth labeling and are not claimed as clinically proven outcomes at this prototype stage.

Planned Roadmap Extensions

  • → Dataset expansion with infrared night-vision barn footage and indigenous South Asian cattle/buffalo breeds to lift recall above 85%.
  • → INT8 TensorRT export for continuous multi-stream RTSP processing on NVIDIA Jetson Orin edge gateways.