khoroos 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- khoroos-0.1.0/LICENSE +73 -0
- khoroos-0.1.0/PKG-INFO +186 -0
- khoroos-0.1.0/README.md +146 -0
- khoroos-0.1.0/pyproject.toml +74 -0
- khoroos-0.1.0/src/khoroos/__init__.py +110 -0
- khoroos-0.1.0/src/khoroos/annotations/__init__.py +6 -0
- khoroos-0.1.0/src/khoroos/annotations/codecs.py +164 -0
- khoroos-0.1.0/src/khoroos/annotations/detections.py +94 -0
- khoroos-0.1.0/src/khoroos/cli.py +306 -0
- khoroos-0.1.0/src/khoroos/config.py +337 -0
- khoroos-0.1.0/src/khoroos/environment.py +75 -0
- khoroos-0.1.0/src/khoroos/interfaces.py +166 -0
- khoroos-0.1.0/src/khoroos/models/__init__.py +1 -0
- khoroos-0.1.0/src/khoroos/models/action.py +116 -0
- khoroos-0.1.0/src/khoroos/models/card.py +71 -0
- khoroos-0.1.0/src/khoroos/models/detector.py +168 -0
- khoroos-0.1.0/src/khoroos/models/metadata.py +30 -0
- khoroos-0.1.0/src/khoroos/models/registry.py +138 -0
- khoroos-0.1.0/src/khoroos/models/selection.py +82 -0
- khoroos-0.1.0/src/khoroos/pipeline/__init__.py +1 -0
- khoroos-0.1.0/src/khoroos/pipeline/analyze.py +438 -0
- khoroos-0.1.0/src/khoroos/pipeline/components.py +92 -0
- khoroos-0.1.0/src/khoroos/pipeline/jobs.py +311 -0
- khoroos-0.1.0/src/khoroos/pipeline/runner.py +144 -0
- khoroos-0.1.0/src/khoroos/pipeline/types.py +236 -0
- khoroos-0.1.0/src/khoroos/py.typed +0 -0
- khoroos-0.1.0/src/khoroos/statistics/__init__.py +1 -0
- khoroos-0.1.0/src/khoroos/statistics/export.py +122 -0
- khoroos-0.1.0/src/khoroos/statistics/metrics.py +300 -0
- khoroos-0.1.0/src/khoroos/tracking/__init__.py +1 -0
- khoroos-0.1.0/src/khoroos/tracking/kalman.py +84 -0
- khoroos-0.1.0/src/khoroos/tracking/tracker.py +176 -0
- khoroos-0.1.0/src/khoroos/tracking/tracklets.py +266 -0
- khoroos-0.1.0/src/khoroos/video/__init__.py +1 -0
- khoroos-0.1.0/src/khoroos/video/reader.py +148 -0
- khoroos-0.1.0/src/khoroos/video/writer.py +251 -0
- khoroos-0.1.0/src/khoroos/web/__init__.py +1 -0
- khoroos-0.1.0/src/khoroos/web/app.py +51 -0
- khoroos-0.1.0/src/khoroos/web/routes.py +312 -0
- khoroos-0.1.0/src/khoroos/web/static/Khoroos-transparent.png +0 -0
- khoroos-0.1.0/src/khoroos/web/static/app.js +1566 -0
- khoroos-0.1.0/src/khoroos/web/static/index.html +311 -0
- khoroos-0.1.0/src/khoroos/web/static/khoroos.png +0 -0
- khoroos-0.1.0/src/khoroos/web/static/styles.css +1135 -0
khoroos-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# PolyForm Noncommercial License 1.0.0
|
|
2
|
+
|
|
3
|
+
<https://polyformproject.org/licenses/noncommercial/1.0.0>
|
|
4
|
+
|
|
5
|
+
## Acceptance
|
|
6
|
+
|
|
7
|
+
In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
|
|
8
|
+
|
|
9
|
+
## Copyright License
|
|
10
|
+
|
|
11
|
+
The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
|
|
12
|
+
|
|
13
|
+
## Distribution License
|
|
14
|
+
|
|
15
|
+
The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
|
|
16
|
+
|
|
17
|
+
## Notices
|
|
18
|
+
|
|
19
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
|
|
20
|
+
|
|
21
|
+
> Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
|
|
22
|
+
|
|
23
|
+
## Changes and New Works License
|
|
24
|
+
|
|
25
|
+
The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
|
|
26
|
+
|
|
27
|
+
## Patent License
|
|
28
|
+
|
|
29
|
+
The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
|
|
30
|
+
|
|
31
|
+
## Noncommercial Purposes
|
|
32
|
+
|
|
33
|
+
Any noncommercial purpose is a permitted purpose.
|
|
34
|
+
|
|
35
|
+
## Personal Uses
|
|
36
|
+
|
|
37
|
+
Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
|
|
38
|
+
|
|
39
|
+
## Noncommercial Organizations
|
|
40
|
+
|
|
41
|
+
Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
|
|
42
|
+
|
|
43
|
+
## Fair Use
|
|
44
|
+
|
|
45
|
+
You may have "fair use" rights for the software under the law. These terms do not limit them.
|
|
46
|
+
|
|
47
|
+
## No Other Rights
|
|
48
|
+
|
|
49
|
+
These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
|
|
50
|
+
|
|
51
|
+
## Patent Defense
|
|
52
|
+
|
|
53
|
+
If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
54
|
+
|
|
55
|
+
## Violations
|
|
56
|
+
|
|
57
|
+
The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
|
|
58
|
+
|
|
59
|
+
## No Liability
|
|
60
|
+
|
|
61
|
+
***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
|
|
62
|
+
|
|
63
|
+
## Definitions
|
|
64
|
+
|
|
65
|
+
The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
|
|
66
|
+
|
|
67
|
+
**You** refers to the individual or entity agreeing to these terms.
|
|
68
|
+
|
|
69
|
+
**Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
70
|
+
|
|
71
|
+
**Your licenses** are all the licenses granted to you for the software under these terms.
|
|
72
|
+
|
|
73
|
+
**Use** means anything you do with the software requiring one of your licenses.
|
khoroos-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: khoroos
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A toolkit for poultry behavior analysis.
|
|
5
|
+
Keywords: poultry,behavior-statistics,animal-science,action-recognition,computer-vision
|
|
6
|
+
Author: Ahmad Amirivojdan
|
|
7
|
+
Author-email: Ahmad Amirivojdan <amirivojdan@gmail.com>
|
|
8
|
+
License-Expression: PolyForm-Noncommercial-1.0.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
14
|
+
Requires-Dist: torch>=2.4
|
|
15
|
+
Requires-Dist: torchvision>=0.19
|
|
16
|
+
Requires-Dist: transformers>=4.53.2
|
|
17
|
+
Requires-Dist: torchcodec>=0.1
|
|
18
|
+
Requires-Dist: av>=12
|
|
19
|
+
Requires-Dist: numpy>=2.1
|
|
20
|
+
Requires-Dist: scipy>=1.13
|
|
21
|
+
Requires-Dist: pillow>=10
|
|
22
|
+
Requires-Dist: typer>=0.12
|
|
23
|
+
Requires-Dist: huggingface-hub>=0.25
|
|
24
|
+
Requires-Dist: pydantic>=2.7
|
|
25
|
+
Requires-Dist: pydantic-settings>=2.3
|
|
26
|
+
Requires-Dist: pytest>=8 ; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.6 ; extra == 'dev'
|
|
28
|
+
Requires-Dist: mkdocs-material>=9.6 ; extra == 'docs'
|
|
29
|
+
Requires-Dist: mkdocstrings[python]>=0.29 ; extra == 'docs'
|
|
30
|
+
Requires-Dist: fastapi>=0.115 ; extra == 'web'
|
|
31
|
+
Requires-Dist: uvicorn[standard]>=0.30 ; extra == 'web'
|
|
32
|
+
Requires-Dist: python-multipart>=0.0.9 ; extra == 'web'
|
|
33
|
+
Requires-Python: >=3.12
|
|
34
|
+
Project-URL: Homepage, https://github.com/amirivojdan/khoroos
|
|
35
|
+
Project-URL: Issues, https://github.com/amirivojdan/khoroos/issues
|
|
36
|
+
Provides-Extra: dev
|
|
37
|
+
Provides-Extra: docs
|
|
38
|
+
Provides-Extra: web
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<img src="https://raw.githubusercontent.com/amirivojdan/khoroos/main/khoroos_banner.png" alt="Khoroos: poultry behavior analysis" width="100%">
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
Khoroos turns poultry videos into bird tracks, behavior timelines, and descriptive statistics.
|
|
46
|
+
Use it to measure how observed birds spend their time, compare activity across a recording,
|
|
47
|
+
and export data for further analysis.
|
|
48
|
+
|
|
49
|
+
Developed at the [UT Smart Agriculture Lab](https://www.ut-smartagriculture.com/).
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- **Detection and tracking:** locate chickens and follow their trajectories across frames.
|
|
54
|
+
- **Behavior recognition:** classify single-bird clips into 15 behaviors, or select a subset
|
|
55
|
+
such as feeding and drinking.
|
|
56
|
+
- **Descriptive statistics:** time budgets, behavior bouts, detection counts, spatial summaries,
|
|
57
|
+
and per-track measurements.
|
|
58
|
+
- **Interactive review:** inspect tracks and behavior timelines alongside the video in a browser.
|
|
59
|
+
- **Exports:** save JSON, CSV tables, and an optional annotated video.
|
|
60
|
+
- **Replaceable components:** bring your own detector, classifier, tracker, or statistics
|
|
61
|
+
functions. Convert bounding-box annotations between YOLO and COCO formats.
|
|
62
|
+
|
|
63
|
+
## Get started
|
|
64
|
+
|
|
65
|
+
Requires Python 3.12+ and FFmpeg. A GPU is recommended for inference.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/amirivojdan/khoroos.git
|
|
69
|
+
cd khoroos
|
|
70
|
+
python3 -m venv .venv
|
|
71
|
+
source .venv/bin/activate
|
|
72
|
+
python -m pip install ".[web]"
|
|
73
|
+
khoroos models download
|
|
74
|
+
khoroos ui
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The default models are public; no Hugging Face login is required. Downloads are cached for
|
|
78
|
+
later runs, including offline use.
|
|
79
|
+
|
|
80
|
+
Open `http://127.0.0.1:8000`, select a video, choose a detail level, and start the analysis.
|
|
81
|
+
Use the timeline to seek through the recording, select a track to follow one bird, and download
|
|
82
|
+
the results when the run finishes.
|
|
83
|
+
|
|
84
|
+
### Docker
|
|
85
|
+
|
|
86
|
+
With Docker and the NVIDIA Container Toolkit installed:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
docker compose up --build
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Open `http://localhost:8000`. Startup downloads the models automatically and reuses them on
|
|
93
|
+
later starts. Model files and results persist in a volume; the web job list resets on restart.
|
|
94
|
+
See the [Docker guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/docker.md) for requirements and storage details.
|
|
95
|
+
|
|
96
|
+
## Command line
|
|
97
|
+
|
|
98
|
+
Start with a short section of video:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
khoroos analyze farm.mp4 -o results/ --max-seconds 60
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Analyze a full recording and save an annotated video:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
khoroos analyze farm.mp4 -o results/ --overlay
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Report selected behaviors:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
khoroos analyze farm.mp4 -o results/ --set action_classes=feeding,drinking
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Choose `--preset fast`, `balanced` (default), or `thorough` to adjust sampling detail.
|
|
117
|
+
If GPU memory runs out, reduce `--action-batch-size` first. See the
|
|
118
|
+
[CLI guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/command-line.md) for all options.
|
|
119
|
+
|
|
120
|
+
## Python
|
|
121
|
+
|
|
122
|
+
Analyze a video directly:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from khoroos import analyze_video
|
|
126
|
+
|
|
127
|
+
result = analyze_video("farm.mp4", preset="balanced")
|
|
128
|
+
print(result.metrics["time_budget"])
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Reuse the models across recordings and save each export bundle:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from pathlib import Path
|
|
135
|
+
from khoroos import AnalysisRunner
|
|
136
|
+
|
|
137
|
+
runner = AnalysisRunner()
|
|
138
|
+
for video in Path("videos").glob("*.mp4"):
|
|
139
|
+
runner.run(video, output_dir=Path("results") / video.stem)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
See the [Python guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/python-api.md) for parameters and progress callbacks.
|
|
143
|
+
|
|
144
|
+
## Results
|
|
145
|
+
|
|
146
|
+
Each exported analysis includes:
|
|
147
|
+
|
|
148
|
+
| File | Contents |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| `result.json` | Tracks, predictions, run parameters, and metadata |
|
|
151
|
+
| `metrics.json` | Behavior budgets, bouts, detection counts, spatial summaries, and timelines |
|
|
152
|
+
| `predictions.csv` | One row per classified clip |
|
|
153
|
+
| `time_budget.csv` | Duration and proportion per behavior |
|
|
154
|
+
| `per_bird.csv` | Statistics per track |
|
|
155
|
+
| `annotated.mp4` | Video with boxes and labels, when `--overlay` is enabled |
|
|
156
|
+
|
|
157
|
+
Statistics describe model-assigned labels. Uncertain predictions are reported separately,
|
|
158
|
+
and track IDs represent trajectories rather than verified animal identities.
|
|
159
|
+
See [Outputs](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/outputs.md) for field definitions and duration calculations.
|
|
160
|
+
|
|
161
|
+
## Extend Khoroos
|
|
162
|
+
|
|
163
|
+
Subclass `Detector`, `VideoClassifier`, or `Tracker` to use your own algorithms.
|
|
164
|
+
`VideoAnalyzer` accepts custom models, and `PipelineComponents` configures the reader, tracker,
|
|
165
|
+
cropper, and metrics. Class labels and behavior groups are configurable.
|
|
166
|
+
|
|
167
|
+
Follow the [extension guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/extending.md) for working examples, or the
|
|
168
|
+
[configuration guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/configuration.md) for devices, model sources, and cache paths.
|
|
169
|
+
|
|
170
|
+
## Development
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
uv sync --locked --extra web --extra dev --extra docs
|
|
174
|
+
uv run pytest
|
|
175
|
+
uv run ruff check src tests
|
|
176
|
+
uv run mkdocs serve
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Tests use stub models and generated videos; no model download is needed.
|
|
180
|
+
|
|
181
|
+
## Resources and licenses
|
|
182
|
+
|
|
183
|
+
- [Documentation](https://github.com/amirivojdan/khoroos/blob/main/docs/index.md)
|
|
184
|
+
- [ChickenAct dataset](https://zenodo.org/records/20672799) and [training notebook](https://github.com/amirivojdan/khoroos/blob/main/notebooks/vjepa2_chicken_action_recognition.ipynb)
|
|
185
|
+
- Public models: [chicken detector](https://huggingface.co/amirivojdan/chicken_rtdetrv2) and [action classifier](https://huggingface.co/amirivojdan/chicken_vjepa2_action), licensed under CC BY-NC-SA 4.0.
|
|
186
|
+
- Code: [PolyForm Noncommercial License 1.0.0](https://github.com/amirivojdan/khoroos/blob/main/LICENSE).
|
khoroos-0.1.0/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/amirivojdan/khoroos/main/khoroos_banner.png" alt="Khoroos: poultry behavior analysis" width="100%">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
Khoroos turns poultry videos into bird tracks, behavior timelines, and descriptive statistics.
|
|
6
|
+
Use it to measure how observed birds spend their time, compare activity across a recording,
|
|
7
|
+
and export data for further analysis.
|
|
8
|
+
|
|
9
|
+
Developed at the [UT Smart Agriculture Lab](https://www.ut-smartagriculture.com/).
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Detection and tracking:** locate chickens and follow their trajectories across frames.
|
|
14
|
+
- **Behavior recognition:** classify single-bird clips into 15 behaviors, or select a subset
|
|
15
|
+
such as feeding and drinking.
|
|
16
|
+
- **Descriptive statistics:** time budgets, behavior bouts, detection counts, spatial summaries,
|
|
17
|
+
and per-track measurements.
|
|
18
|
+
- **Interactive review:** inspect tracks and behavior timelines alongside the video in a browser.
|
|
19
|
+
- **Exports:** save JSON, CSV tables, and an optional annotated video.
|
|
20
|
+
- **Replaceable components:** bring your own detector, classifier, tracker, or statistics
|
|
21
|
+
functions. Convert bounding-box annotations between YOLO and COCO formats.
|
|
22
|
+
|
|
23
|
+
## Get started
|
|
24
|
+
|
|
25
|
+
Requires Python 3.12+ and FFmpeg. A GPU is recommended for inference.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone https://github.com/amirivojdan/khoroos.git
|
|
29
|
+
cd khoroos
|
|
30
|
+
python3 -m venv .venv
|
|
31
|
+
source .venv/bin/activate
|
|
32
|
+
python -m pip install ".[web]"
|
|
33
|
+
khoroos models download
|
|
34
|
+
khoroos ui
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The default models are public; no Hugging Face login is required. Downloads are cached for
|
|
38
|
+
later runs, including offline use.
|
|
39
|
+
|
|
40
|
+
Open `http://127.0.0.1:8000`, select a video, choose a detail level, and start the analysis.
|
|
41
|
+
Use the timeline to seek through the recording, select a track to follow one bird, and download
|
|
42
|
+
the results when the run finishes.
|
|
43
|
+
|
|
44
|
+
### Docker
|
|
45
|
+
|
|
46
|
+
With Docker and the NVIDIA Container Toolkit installed:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
docker compose up --build
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Open `http://localhost:8000`. Startup downloads the models automatically and reuses them on
|
|
53
|
+
later starts. Model files and results persist in a volume; the web job list resets on restart.
|
|
54
|
+
See the [Docker guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/docker.md) for requirements and storage details.
|
|
55
|
+
|
|
56
|
+
## Command line
|
|
57
|
+
|
|
58
|
+
Start with a short section of video:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
khoroos analyze farm.mp4 -o results/ --max-seconds 60
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Analyze a full recording and save an annotated video:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
khoroos analyze farm.mp4 -o results/ --overlay
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Report selected behaviors:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
khoroos analyze farm.mp4 -o results/ --set action_classes=feeding,drinking
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Choose `--preset fast`, `balanced` (default), or `thorough` to adjust sampling detail.
|
|
77
|
+
If GPU memory runs out, reduce `--action-batch-size` first. See the
|
|
78
|
+
[CLI guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/command-line.md) for all options.
|
|
79
|
+
|
|
80
|
+
## Python
|
|
81
|
+
|
|
82
|
+
Analyze a video directly:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from khoroos import analyze_video
|
|
86
|
+
|
|
87
|
+
result = analyze_video("farm.mp4", preset="balanced")
|
|
88
|
+
print(result.metrics["time_budget"])
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Reuse the models across recordings and save each export bundle:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from pathlib import Path
|
|
95
|
+
from khoroos import AnalysisRunner
|
|
96
|
+
|
|
97
|
+
runner = AnalysisRunner()
|
|
98
|
+
for video in Path("videos").glob("*.mp4"):
|
|
99
|
+
runner.run(video, output_dir=Path("results") / video.stem)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See the [Python guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/python-api.md) for parameters and progress callbacks.
|
|
103
|
+
|
|
104
|
+
## Results
|
|
105
|
+
|
|
106
|
+
Each exported analysis includes:
|
|
107
|
+
|
|
108
|
+
| File | Contents |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `result.json` | Tracks, predictions, run parameters, and metadata |
|
|
111
|
+
| `metrics.json` | Behavior budgets, bouts, detection counts, spatial summaries, and timelines |
|
|
112
|
+
| `predictions.csv` | One row per classified clip |
|
|
113
|
+
| `time_budget.csv` | Duration and proportion per behavior |
|
|
114
|
+
| `per_bird.csv` | Statistics per track |
|
|
115
|
+
| `annotated.mp4` | Video with boxes and labels, when `--overlay` is enabled |
|
|
116
|
+
|
|
117
|
+
Statistics describe model-assigned labels. Uncertain predictions are reported separately,
|
|
118
|
+
and track IDs represent trajectories rather than verified animal identities.
|
|
119
|
+
See [Outputs](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/outputs.md) for field definitions and duration calculations.
|
|
120
|
+
|
|
121
|
+
## Extend Khoroos
|
|
122
|
+
|
|
123
|
+
Subclass `Detector`, `VideoClassifier`, or `Tracker` to use your own algorithms.
|
|
124
|
+
`VideoAnalyzer` accepts custom models, and `PipelineComponents` configures the reader, tracker,
|
|
125
|
+
cropper, and metrics. Class labels and behavior groups are configurable.
|
|
126
|
+
|
|
127
|
+
Follow the [extension guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/extending.md) for working examples, or the
|
|
128
|
+
[configuration guide](https://github.com/amirivojdan/khoroos/blob/main/docs/guide/configuration.md) for devices, model sources, and cache paths.
|
|
129
|
+
|
|
130
|
+
## Development
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
uv sync --locked --extra web --extra dev --extra docs
|
|
134
|
+
uv run pytest
|
|
135
|
+
uv run ruff check src tests
|
|
136
|
+
uv run mkdocs serve
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Tests use stub models and generated videos; no model download is needed.
|
|
140
|
+
|
|
141
|
+
## Resources and licenses
|
|
142
|
+
|
|
143
|
+
- [Documentation](https://github.com/amirivojdan/khoroos/blob/main/docs/index.md)
|
|
144
|
+
- [ChickenAct dataset](https://zenodo.org/records/20672799) and [training notebook](https://github.com/amirivojdan/khoroos/blob/main/notebooks/vjepa2_chicken_action_recognition.ipynb)
|
|
145
|
+
- Public models: [chicken detector](https://huggingface.co/amirivojdan/chicken_rtdetrv2) and [action classifier](https://huggingface.co/amirivojdan/chicken_vjepa2_action), licensed under CC BY-NC-SA 4.0.
|
|
146
|
+
- Code: [PolyForm Noncommercial License 1.0.0](https://github.com/amirivojdan/khoroos/blob/main/LICENSE).
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "khoroos"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A toolkit for poultry behavior analysis."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "PolyForm-Noncommercial-1.0.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = "Ahmad Amirivojdan", email = "amirivojdan@gmail.com" }
|
|
10
|
+
]
|
|
11
|
+
keywords = ["poultry", "behavior-statistics", "animal-science", "action-recognition", "computer-vision"]
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Development Status :: 3 - Alpha",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
17
|
+
]
|
|
18
|
+
requires-python = ">=3.12"
|
|
19
|
+
dependencies = [
|
|
20
|
+
"torch>=2.4",
|
|
21
|
+
"torchvision>=0.19",
|
|
22
|
+
"transformers>=4.53.2",
|
|
23
|
+
"torchcodec>=0.1",
|
|
24
|
+
"av>=12",
|
|
25
|
+
"numpy>=2.1",
|
|
26
|
+
"scipy>=1.13",
|
|
27
|
+
"pillow>=10",
|
|
28
|
+
"typer>=0.12",
|
|
29
|
+
"huggingface-hub>=0.25",
|
|
30
|
+
"pydantic>=2.7",
|
|
31
|
+
"pydantic-settings>=2.3",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
web = [
|
|
36
|
+
"fastapi>=0.115",
|
|
37
|
+
"uvicorn[standard]>=0.30",
|
|
38
|
+
"python-multipart>=0.0.9",
|
|
39
|
+
]
|
|
40
|
+
dev = [
|
|
41
|
+
"pytest>=8",
|
|
42
|
+
"ruff>=0.6",
|
|
43
|
+
]
|
|
44
|
+
docs = [
|
|
45
|
+
"mkdocs-material>=9.6",
|
|
46
|
+
"mkdocstrings[python]>=0.29",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[project.scripts]
|
|
50
|
+
khoroos = "khoroos.cli:app"
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/amirivojdan/khoroos"
|
|
54
|
+
Issues = "https://github.com/amirivojdan/khoroos/issues"
|
|
55
|
+
|
|
56
|
+
[build-system]
|
|
57
|
+
requires = ["uv_build>=0.9.11,<0.10.0"]
|
|
58
|
+
build-backend = "uv_build"
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 100
|
|
62
|
+
target-version = "py312"
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
66
|
+
ignore = ["B008"]
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint.per-file-ignores]
|
|
69
|
+
# Test fixtures read better on one line than wrapped.
|
|
70
|
+
"tests/*" = ["E501"]
|
|
71
|
+
|
|
72
|
+
[tool.pytest.ini_options]
|
|
73
|
+
testpaths = ["tests"]
|
|
74
|
+
filterwarnings = ["ignore::DeprecationWarning"]
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Khoroos — a toolkit for poultry behavior analysis.
|
|
2
|
+
|
|
3
|
+
Typical use::
|
|
4
|
+
|
|
5
|
+
from khoroos import analyze_video
|
|
6
|
+
|
|
7
|
+
result = analyze_video("farm.mp4", preset="balanced")
|
|
8
|
+
print(result.metrics["time_budget"])
|
|
9
|
+
|
|
10
|
+
Or from the command line::
|
|
11
|
+
|
|
12
|
+
khoroos ui # web interface
|
|
13
|
+
khoroos analyze farm.mp4 -o out # batch analysis
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from khoroos.config import (
|
|
17
|
+
ACTION_CLASSES,
|
|
18
|
+
BEHAVIOUR_GROUPS,
|
|
19
|
+
PRESETS,
|
|
20
|
+
UNCERTAIN_LABEL,
|
|
21
|
+
AnalysisParams,
|
|
22
|
+
Settings,
|
|
23
|
+
get_settings,
|
|
24
|
+
params_for_preset,
|
|
25
|
+
)
|
|
26
|
+
from khoroos.pipeline.types import (
|
|
27
|
+
ActionPrediction,
|
|
28
|
+
AnalysisResult,
|
|
29
|
+
ProgressEvent,
|
|
30
|
+
Track,
|
|
31
|
+
Tracklet,
|
|
32
|
+
VideoInfo,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _installed_version() -> str:
|
|
37
|
+
"""Read the version from package metadata, so pyproject.toml stays its one source."""
|
|
38
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
return version("khoroos")
|
|
42
|
+
except PackageNotFoundError: # running from a source tree that was never installed
|
|
43
|
+
return "0.0.0+unknown"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
__version__ = _installed_version()
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"ACTION_CLASSES",
|
|
50
|
+
"BEHAVIOUR_GROUPS",
|
|
51
|
+
"PRESETS",
|
|
52
|
+
"UNCERTAIN_LABEL",
|
|
53
|
+
"ActionPrediction",
|
|
54
|
+
"Detector",
|
|
55
|
+
"VideoClassifier",
|
|
56
|
+
"Tracker",
|
|
57
|
+
"VideoReader",
|
|
58
|
+
"PipelineComponents",
|
|
59
|
+
"SelectedClasses",
|
|
60
|
+
"AnalysisParams",
|
|
61
|
+
"AnalysisResult",
|
|
62
|
+
"AnalysisRunner",
|
|
63
|
+
"ProgressEvent",
|
|
64
|
+
"RunArtifacts",
|
|
65
|
+
"Settings",
|
|
66
|
+
"Track",
|
|
67
|
+
"Tracklet",
|
|
68
|
+
"VideoAnalyzer",
|
|
69
|
+
"VideoInfo",
|
|
70
|
+
"__version__",
|
|
71
|
+
"analyze_video",
|
|
72
|
+
"describe_environment",
|
|
73
|
+
"get_settings",
|
|
74
|
+
"params_for_preset",
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
#: Names served lazily, and the module each comes from. Everything here transitively
|
|
78
|
+
#: imports torch.
|
|
79
|
+
_LAZY = {
|
|
80
|
+
"Detector": "khoroos.interfaces",
|
|
81
|
+
"VideoClassifier": "khoroos.interfaces",
|
|
82
|
+
"Tracker": "khoroos.interfaces",
|
|
83
|
+
"VideoReader": "khoroos.interfaces",
|
|
84
|
+
"PipelineComponents": "khoroos.pipeline.components",
|
|
85
|
+
"SelectedClasses": "khoroos.models.selection",
|
|
86
|
+
"AnalysisRunner": "khoroos.pipeline.runner",
|
|
87
|
+
"RunArtifacts": "khoroos.pipeline.runner",
|
|
88
|
+
"VideoAnalyzer": "khoroos.pipeline.analyze",
|
|
89
|
+
"analyze_video": "khoroos.pipeline.analyze",
|
|
90
|
+
"describe_environment": "khoroos.environment",
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def __getattr__(name: str):
|
|
95
|
+
"""Defer the heavy pipeline import until something actually needs it.
|
|
96
|
+
|
|
97
|
+
Importing :mod:`khoroos` must stay cheap — the CLI touches it just to print a
|
|
98
|
+
version, and pulling in torch and transformers for that costs seconds.
|
|
99
|
+
"""
|
|
100
|
+
module_name = _LAZY.get(name)
|
|
101
|
+
if module_name is None:
|
|
102
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
103
|
+
|
|
104
|
+
from importlib import import_module
|
|
105
|
+
|
|
106
|
+
return getattr(import_module(module_name), name)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def __dir__() -> list[str]:
|
|
110
|
+
return sorted(__all__)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Interchangeable per-image bounding-box annotation codecs."""
|
|
2
|
+
|
|
3
|
+
from khoroos.annotations.codecs import AnnotationCodec, CocoCodec, YoloCodec, annotation_codec
|
|
4
|
+
from khoroos.annotations.detections import Detections
|
|
5
|
+
|
|
6
|
+
__all__ = ["AnnotationCodec", "CocoCodec", "Detections", "YoloCodec", "annotation_codec"]
|