File size: 8,338 Bytes
75b508b
52ffde5
 
 
 
 
 
 
 
 
 
 
 
 
75b508b
52ffde5
 
aba8c17
 
 
 
 
 
 
 
 
 
 
 
52ffde5
4ebd893
 
 
 
52ffde5
4ebd893
 
 
 
52ffde5
e65c852
52ffde5
 
 
e65c852
 
 
 
52ffde5
 
4ebd893
52ffde5
 
 
4ebd893
52ffde5
 
 
 
 
4ebd893
 
 
52ffde5
 
4ebd893
52ffde5
 
 
b48878b
 
 
52ffde5
2b99801
52ffde5
 
 
4ebd893
52ffde5
 
 
 
 
 
 
 
b48878b
52ffde5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b48878b
4ebd893
52ffde5
 
 
4ebd893
52ffde5
b48878b
52ffde5
b48878b
52ffde5
b48878b
 
 
 
 
 
52ffde5
4ebd893
52ffde5
4ebd893
 
 
52ffde5
 
4ebd893
 
 
 
52ffde5
4ebd893
 
52ffde5
 
 
4ebd893
52ffde5
 
 
4ebd893
 
 
 
52ffde5
4ebd893
52ffde5
4ebd893
52ffde5
 
 
 
 
4ebd893
52ffde5
 
 
4ebd893
52ffde5
b48878b
4ebd893
 
 
 
 
 
 
 
52ffde5
 
 
 
 
 
 
4ebd893
 
 
52ffde5
4ebd893
 
 
 
52ffde5
 
 
4ebd893
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
license: agpl-3.0
library_name: ultralytics
pipeline_tag: object-detection
tags:
  - yolo
  - ultralytics
  - object-detection
  - agriculture
  - livestock
  - cattle
  - calving
  - animal-welfare
  - computer-vision
---

# Calvingcatcher
<p align="left">
  <a href="https://jacobsfarm.github.io/website/"><img src="https://img.shields.io/badge/Website-cowcatcherai.com-blue?logo=googlechrome&logoColor=white" alt="Website"></a>
  <a href="https://huggingface.co/spaces/CowcatcherAI/CowCatcherAI"><img src="https://img.shields.io/badge/🤗%20Hugging%20Face-Spaces-yellow" alt="Hugging Face"></a>
  <a href="https://t.me/+SphG4deaWVNkYTQ8"><img src="https://img.shields.io/badge/Telegram-Join%20Chat-2CA5E0?logo=telegram&logoColor=white" alt="Telegram"></a>
  <a href="https://github.com/eschouten/ai-detector"><img src="https://img.shields.io/badge/GitHub-AI--Detector-181717?logo=github&logoColor=white" alt="AI-Detector Repo"></a>
  <a href="https://github.com/CowCatcherAI/CowCatcherAI"><img src="https://img.shields.io/badge/GitHub-CowCatcherAI-181717?logo=github&logoColor=white" alt="CowCatcherAI Repo"></a>
  <a href="https://github.com/CowCatcherAI/CalvingCatcherAI"><img src="https://img.shields.io/badge/GitHub-CalvingCatcherAI-181717?logo=github&logoColor=white" alt="CalvingCatcherAI Repo"></a>
</p>

### 
Check out the website for all the information: [cowcatcherai.com](https://jacobsfarm.github.io/website/)
**The website is available in multiple languages such as Deutsch, Français, Nederlands, and Español.**

We built Calvingcatcher to keep an eye on the maternity pen so we don't have to walk out to the barn
every hour through the night. It is a vision model that detect the visual signs of **calving**
in cattle from ordinary barn cameras, and it forms the vision core of our CalvingCatcher system — an
extra pair of eyes that watches 24/7.

We are farmers, and we trained these models on our own barn footage. Instead of predicting a single
"calving" label, we detect the individual signs we would look for ourselves — the water bag, protruding
legs, a head coming through. That way the system around the model can reason about *how far along* a cow
is, not just whether something is happening.

**Our latest and best model is `CalvingcatcherV11.pt`.** It is what we run ourselves.

More about the full system: [jacobsfarm.github.io/website/projects/calvingcatcher](https://jacobsfarm.github.io/website/projects/calvingcatcher/)

Results on a test set
![5947127158079688394](https://cdn-uploads.huggingface.co/production/uploads/698125f7a72f8b306c9ffa52/1BYCwvQ7TgMzGBF1kyrCe.jpeg)


---

## What we detect

| ID | Class | What it marks |
|---|---|---|
| 1 | `waterbag` | Visible amniotic sac — the first hard evidence of active calving |
| 2 | `legs` | Calf legs protruding |
| 3 | `head` | Calf head visible |
| 4 | `body` | Calf body emerging |
| 5 | `calf` | Newborn calf on the ground |

The detection head carries one further class from an earlier experiment that we no longer use in
production. Ignore anything outside the five classes above.

---

## The models

| File | Base | Train imgsz / epochs | Size | Notes |
|---|---|---|---|---|
| **`CalvingcatcherV10.pt`** | `yolo26m` | 1024 / 150 | 44 MB | **What we recommend.** Best precision and recall we have |
| `CalvingcatcherV9.pt` | `yolo26m` | 1024 / 150 | 44 MB | Our previous main model |
| `calvingcatcherV8.pt` | `yolo26m` | 1024 / 150 | 44 MB | An older, reliable model |

All three are Ultralytics 8.4.14 `yolo26m` detection models. 

---

## Getting started

```bash
pip install ultralytics
```

```python
from ultralytics import YOLO

model = YOLO("CalvingcatcherV10.pt")

results = model.predict("pen_frame.jpg", imgsz=1024, conf=0.40)

for r in results:
    for box in r.boxes:
        print(r.names[int(box.cls)], float(box.conf), box.xyxy.tolist())
```

```python
# Live camera / RTSP stream
for result in model.predict(source="rtsp://camera/stream", stream=True, imgsz=1024, conf=0.40):
    labels = {result.names[int(b.cls)] for b in result.boxes}
    if "waterbag" in labels or "legs" in labels:
        print("Possible calving in progress:", labels)
```

Run V10, V9 and V8 at **`imgsz=1024`** — that is what we trained them at. Dropping
back to the 640 default costs a noticeable amount of recall on small, distant subjects.

---

## How our models compare

The following metrics are based on a recent standardized test set of 360 images across our newer model generations.

| Version | Training Images | Precision % | Recall % | Total FP |
|---|---|---|---|---|
| **V10** | **18,258** | **94.8** | **54.1** | **8** |
| V9 | 11,500 | 76.2 | 52.8 | 79 |
| V8 | 8,700 | 84.7 | 47.8 | 33 |
| V7 | 6,900 | 78.2 | 35.6 | 49 |

V10 comes out significantly ahead on both precision and recall. Thanks to a much larger training set (over 18,000 images), our recall has climbed to 54.1%, and precision reached an impressive 94.8% with drastically reduced false positives (only 8 in our test set).

### How to read those numbers

The recall looks low next to a typical single-class detector, and we want to be upfront about why. This
is a hard problem: the things we look for are small, often partly hidden by the cow herself, and some of
them — a water bag, a pair of legs — are only visible from certain angles and for a limited window.
Every individual object in every individual frame counts against recall.

In daily use we don't need to catch every object in every frame. The camera watches the pen
continuously, and one confident detection is enough to start recording. A calving lasts long enough that
~50% per-frame recall still catches the event reliably. What matters far more to us is precision — we
don't want to be woken for nothing.

If you run these weights standalone, the confidence threshold is your main dial: raise it to cut false
alarms, lower it to catch earlier and weaker signs.

---

## How we use them

1. An IP camera streams the maternity pen over RTSP.
2. The model analyses a frame every few seconds.
3. On a reliable detection we start collecting frames and record several seconds of footage, so we have
   enough material to pick good imagery from.
4. The clearest images go straight to our phones through **Telegram** or **Home Assistant**, with the
   confidence score, so we can judge the situation before pulling on our boots.

Everything runs locally on the farm. No footage leaves the premises.

### What you need to run it

- A consumer-grade PC, preferably with an NVIDIA GPU (GTX 1000-series or newer)
- One or more IP/WiFi cameras reachable over RTSP
- A PoE switch to power the wired cameras
- LAN cabling for a stable connection
- An internet connection to send the alerts

---

## What it won't do

- **It will occasionally raise a false alarm.** Precision is very good now, but not perfect.
- **It does not read ear tags.** It tells you something is happening in the pen, not which animal it is.
- **It does not replace walking the barn.** We treat it as a monitoring aid; physical checks stay
  essential and a stockman's judgement is still indispensable.
- Detection quality depends on camera placement, lighting and how much of the cow you can see. Heavy
  occlusion, awkward angles and very distant views are the hard cases.
- The machine has to stay powered and online, or no alert arrives.
- We trained on our own barns only — there is no imagery from other farms in here. Good for privacy, but
  a barn that looks very different from ours may need extra data.

---

## License

**AGPL-3.0.**

We train these weights with [Ultralytics](https://github.com/ultralytics/ultralytics), which is licensed
under AGPL-3.0. Every checkpoint here carries the Ultralytics AGPL-3.0 notice in its metadata, so the
derived weights inherit that license.

In practice: if you use these models in a network-accessible service, AGPL-3.0 requires you to make the
corresponding source of that service available to its users. If that doesn't work for your deployment,
Ultralytics sells a commercial Enterprise License that removes the copyleft obligation — see
[ultralytics.com/license](https://www.ultralytics.com/license).

---

See also: [**Cowcatcher**](https://huggingface.co/CowcatcherAI/Cowcatcher) — our sibling model family
that detects mounting behaviour for heat detection.