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.

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.
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.
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
Implementation Methodology
- Curated annotated cattle posture datasets spanning Eating, Lying, and Standing states across varied camera angles.
- Trained and benchmarked YOLO11s (best.pt) and logged transparent precision, recall, and mAP@50/mAP@50-95 metrics directly on the /model API endpoint.
- Engineered Behavior Engine V3 to resolve transient ID switches and posture flicker during dense feedbunk occlusions.
- Integrated the standalone FastAPI microservice into the FarmOS workspace with automated pytest verification.
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.
Related CASDO Engineering Services
Real-time object detection, multi-object tracking, facial vector biometrics, and specialized visual inspection engineered for local edge deployment.
Bespoke AI systems architected around your proprietary workflows, data sovereignty requirements, and deterministic safety boundaries.
First-hand agricultural engineering connecting geospatial PostGIS mapping, FAO-56 irrigation math, YOLO11s livestock computer vision, and BMS plant breeding.
Production-grade statistical and deep learning models engineered for forecasting, anomaly detection, classification, and measurable operational decision support.
Related Engineering Solutions
Explore purpose-built industry and capability architectures engineered by CASDO Technologies.
Edge AI Computer Vision for Agriculture & Livestock
Uniting Ultralytics YOLO11s cattle posture tracking, ByteTrack temporal smoothing, and WGS84 PostGIS farm digital twins for low-bandwidth field estates.
On-Premise Hospital EMR & Clinical AI R&D
Sovereign clinical record deployments engineered for uninterrupted local hospital networks alongside transparent, non-clinical medical imaging research prototypes.
Industrial IoT Telemetry for Solar, Pumps & Generators
OT-isolated Modbus RTU/RS485 edge gateways, store-and-forward MQTT over TLS pipelines, and TimescaleDB fault analytics engineered for harsh field sites.