Delete clip_library
Browse filesmoving to spaces repo
- clip_library/LICENSE +0 -21
- clip_library/README.md +0 -102
- clip_library/__init__.py +0 -16
- clip_library/io_paths.py +0 -52
- clip_library/maneuver_decision_tree.md +0 -124
- clip_library/maneuver_labels.py +0 -343
- clip_library/requirements.txt +0 -6
- clip_library/schema.py +0 -164
clip_library/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
MIT License
|
| 2 |
-
|
| 3 |
-
Copyright (c) 2024 Jenna Kline
|
| 4 |
-
|
| 5 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
-
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
-
in the Software without restriction, including without limitation the rights
|
| 8 |
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
-
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
-
furnished to do so, subject to the following conditions:
|
| 11 |
-
|
| 12 |
-
The above copyright notice and this permission notice shall be included in all
|
| 13 |
-
copies or substantial portions of the Software.
|
| 14 |
-
|
| 15 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
-
SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clip_library/README.md
DELETED
|
@@ -1,102 +0,0 @@
|
|
| 1 |
-
# Drone Maneuver Clips — Test-Clip Library + Decision-Tree Replay Harness
|
| 2 |
-
|
| 3 |
-
Dataset: **[imageomics/drone-maneuver-clips](https://huggingface.co/datasets/imageomics/drone-maneuver-clips)**
|
| 4 |
-
|
| 5 |
-
A benchmark of **six-second aerial drone clips** (180 frames @ 30 fps), each
|
| 6 |
-
indexed by the autonomous-flight **maneuver** it can test, plus a small
|
| 7 |
-
**deterministic policy** that replays a formal maneuver decision tree over the
|
| 8 |
-
clips to emit ground-truth drone actions. Together they let a learned navigation
|
| 9 |
-
policy be scored, per maneuver, against an expert-calibrated reference.
|
| 10 |
-
|
| 11 |
-
The initial release is **41 clips cut from the
|
| 12 |
-
[KABR](https://huggingface.co/datasets/imageomics/KABR) wildlife dataset**;
|
| 13 |
-
future releases will add clips from other sources, so the harness and schema are
|
| 14 |
-
deliberately source-agnostic.
|
| 15 |
-
|
| 16 |
-
- **Dataset**: per-frame-per-track labels (bbox, species, behaviour, vigilance,
|
| 17 |
-
track id, ground-truth pose where available, telemetry) —
|
| 18 |
-
`clips/<id>/labels.csv`, plus a `catalog/` of per-video and per-clip indices.
|
| 19 |
-
- **Harness**: the maneuver decision tree
|
| 20 |
-
([`clip_library/maneuver_decision_tree.md`](clip_library/maneuver_decision_tree.md))
|
| 21 |
-
executed deterministically → `clips/<id>/maneuver_labels.csv`.
|
| 22 |
-
|
| 23 |
-
## Quick start
|
| 24 |
-
|
| 25 |
-
Download the released clip library (~6 GB) into `./data/drone-maneuver-clips/`
|
| 26 |
-
(or set `DRONE_CLIPS_ROOT` to wherever you put it), then generate / tweak
|
| 27 |
-
maneuver labels — no raw video and no GPU required:
|
| 28 |
-
|
| 29 |
-
```bash
|
| 30 |
-
pip install -r requirements.txt # pandas, numpy (pyarrow optional)
|
| 31 |
-
|
| 32 |
-
# point the harness at the downloaded dataset (default: ./data/drone-maneuver-clips)
|
| 33 |
-
export DRONE_CLIPS_ROOT=/path/to/drone-maneuver-clips
|
| 34 |
-
|
| 35 |
-
# generate GT actions for every clip and the maneuvers it's tagged for
|
| 36 |
-
python -m clip_library.maneuver_labels --all
|
| 37 |
-
|
| 38 |
-
# tweak inputs: a stricter vigilance threshold, a different SoI, a pixel target
|
| 39 |
-
python -m clip_library.maneuver_labels --clip 12_01_23-DJI_0002_000745 \
|
| 40 |
-
--maneuver behavior_adaptive --theta-s 0.3
|
| 41 |
-
python -m clip_library.maneuver_labels --maneuver soi_aware --soi right --desired-pixels 100
|
| 42 |
-
```
|
| 43 |
-
|
| 44 |
-
Every threshold is reviewer-tunable: `--theta-s` (vigilance), `--desired-pixels`,
|
| 45 |
-
`--soi`, plus the `Params` dataclass and module constants (`SMOOTH_WINDOW`,
|
| 46 |
-
`KEEP_LO/HI`, `POSE_RING`) in [`clip_library/maneuver_labels.py`](clip_library/maneuver_labels.py).
|
| 47 |
-
A tuned or single-maneuver "what-if" run writes a `maneuver_labels.custom.csv`
|
| 48 |
-
sidecar and leaves the canonical `maneuver_labels.csv` untouched, so experiments
|
| 49 |
-
never corrupt the release.
|
| 50 |
-
|
| 51 |
-
## Minimum system & environment requirements
|
| 52 |
-
|
| 53 |
-
| | requirement |
|
| 54 |
-
|---|---|
|
| 55 |
-
| OS | Linux or macOS |
|
| 56 |
-
| Python | 3.9 (3.8+ works) |
|
| 57 |
-
| CPU/GPU | **CPU only — no GPU required** |
|
| 58 |
-
| RAM | ~2 GB (CSVs are small) |
|
| 59 |
-
| Disk | **~6 GB** for the released clip library |
|
| 60 |
-
| Runtime | the harness over all 41 clips: **seconds** |
|
| 61 |
-
| Key deps | `pandas`, `numpy`; `pyarrow` optional (Parquet catalog I/O) |
|
| 62 |
-
|
| 63 |
-
## Dataset layout
|
| 64 |
-
|
| 65 |
-
```
|
| 66 |
-
data/drone-maneuver-clips/ # (DRONE_CLIPS_ROOT)
|
| 67 |
-
├── catalog/
|
| 68 |
-
│ ├── video_index.csv # one row per source video
|
| 69 |
-
│ ├── clip_index.csv # one row per clip
|
| 70 |
-
│ ├── coverage_report.md # species/size/maneuver coverage
|
| 71 |
-
│ └── pose_audit.csv # per-video GT-pose assignment audit
|
| 72 |
-
├── clips/<clip_id>/
|
| 73 |
-
│ ├── clip.mp4 # 6 s, 180 frames
|
| 74 |
-
│ ├── labels.csv # one row per frame per tracked individual
|
| 75 |
-
│ └── maneuver_labels.csv # per-frame GT action set, per maneuver
|
| 76 |
-
└── DATASET_CARD.md
|
| 77 |
-
```
|
| 78 |
-
|
| 79 |
-
The `labels.csv` / `clip_index.csv` columns are documented in
|
| 80 |
-
[`clip_library/schema.py`](clip_library/schema.py); the maneuver decision tree
|
| 81 |
-
is in [`clip_library/maneuver_decision_tree.md`](clip_library/maneuver_decision_tree.md).
|
| 82 |
-
|
| 83 |
-
## Limitations
|
| 84 |
-
|
| 85 |
-
- **Label provenance** is a deliberate methodological position: perception
|
| 86 |
-
labels (detection / behaviour / pose) mirror what an autonomous system
|
| 87 |
-
receives at deployment, with session-level expert oversight — not a fully
|
| 88 |
-
hand-verified corpus.
|
| 89 |
-
- **GT pose is sparse** (only frames with KABR pose crops), so the **SoI-aware**
|
| 90 |
-
maneuver is under-exercised on this initial release; with dense
|
| 91 |
-
model-generated pose it is fully exercised.
|
| 92 |
-
- **Retrospective**, not field-validated closed-loop. The KABR-sourced clips
|
| 93 |
-
were flown lower than ideal tracking altitude, so TRACK range-control labels
|
| 94 |
-
skew toward "back".
|
| 95 |
-
- Single-drone, single-view. Multi-view is future work.
|
| 96 |
-
|
| 97 |
-
## License & citation
|
| 98 |
-
|
| 99 |
-
Dataset: **CC-BY-4.0**. Code: see `LICENSE`. The current clips are derived from
|
| 100 |
-
the KABR dataset (Kholiavchenko et al.) and KABR-poses; please cite those
|
| 101 |
-
alongside this artifact. Clips from other sources in future releases carry their
|
| 102 |
-
own upstream attribution — see the dataset card.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clip_library/__init__.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
| 1 |
-
"""Drone-maneuver test-clip library — deterministic decision-tree replay harness.
|
| 2 |
-
|
| 3 |
-
A benchmark of 6-second, maneuver-indexed aerial drone clips (initially sourced
|
| 4 |
-
from the KABR wildlife dataset; more sources to come), each carrying
|
| 5 |
-
per-frame-per-track labels, plus a small deterministic policy that replays a
|
| 6 |
-
formal maneuver decision tree over the clips to emit ground-truth drone actions.
|
| 7 |
-
|
| 8 |
-
Modules:
|
| 9 |
-
schema -> dataset constants, vocabularies, and column sets
|
| 10 |
-
io_paths -> CSV/Parquet table helpers
|
| 11 |
-
maneuver_labels -> the decision-tree replay harness (entry point)
|
| 12 |
-
|
| 13 |
-
Run the harness with: python -m clip_library.maneuver_labels --all
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
__all__ = ["schema", "io_paths"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clip_library/io_paths.py
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 1 |
-
"""Small table-I/O helpers for the clip library.
|
| 2 |
-
|
| 3 |
-
The released harness only needs to read the catalog tables and write its
|
| 4 |
-
per-clip maneuver labels. CSV is always written; Parquet is added when pyarrow
|
| 5 |
-
is installed, and preferred on read when present.
|
| 6 |
-
|
| 7 |
-
(The raw-video resolution and frame-extraction helpers used to rebuild the
|
| 8 |
-
dataset from the source videos are part of the offline build pipeline and are
|
| 9 |
-
not included in this public release.)
|
| 10 |
-
"""
|
| 11 |
-
|
| 12 |
-
from __future__ import annotations
|
| 13 |
-
|
| 14 |
-
import os
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
# --------------------------------------------------------------------------- #
|
| 18 |
-
# Table I/O (CSV always; Parquet when pyarrow is present)
|
| 19 |
-
# --------------------------------------------------------------------------- #
|
| 20 |
-
def have_parquet() -> bool:
|
| 21 |
-
try:
|
| 22 |
-
import pyarrow # noqa: F401
|
| 23 |
-
|
| 24 |
-
return True
|
| 25 |
-
except Exception:
|
| 26 |
-
return False
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
def write_table(df, path_noext: str) -> list[str]:
|
| 30 |
-
"""Write a DataFrame to `<path_noext>.csv` (+ `.parquet` if available)."""
|
| 31 |
-
os.makedirs(os.path.dirname(path_noext), exist_ok=True)
|
| 32 |
-
written = []
|
| 33 |
-
csv_path = path_noext + ".csv"
|
| 34 |
-
df.to_csv(csv_path, index=False)
|
| 35 |
-
written.append(csv_path)
|
| 36 |
-
if have_parquet():
|
| 37 |
-
pq_path = path_noext + ".parquet"
|
| 38 |
-
try:
|
| 39 |
-
df.to_parquet(pq_path, index=False)
|
| 40 |
-
written.append(pq_path)
|
| 41 |
-
except Exception:
|
| 42 |
-
pass
|
| 43 |
-
return written
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
def read_table(path_noext: str):
|
| 47 |
-
"""Read `<path_noext>.parquet` if present else `.csv`."""
|
| 48 |
-
import pandas as pd
|
| 49 |
-
|
| 50 |
-
if have_parquet() and os.path.exists(path_noext + ".parquet"):
|
| 51 |
-
return pd.read_parquet(path_noext + ".parquet")
|
| 52 |
-
return pd.read_csv(path_noext + ".csv", low_memory=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clip_library/maneuver_decision_tree.md
DELETED
|
@@ -1,124 +0,0 @@
|
|
| 1 |
-
# Maneuver Decision Tree — formal specification
|
| 2 |
-
|
| 3 |
-
This document is both (a) the citable policy specification and (b) the exact
|
| 4 |
-
logic that `maneuver_labels.py` executes deterministically over each clip's
|
| 5 |
-
`labels.csv`. One row per branch: condition → action.
|
| 6 |
-
|
| 7 |
-
---
|
| 8 |
-
|
| 9 |
-
## 0. Action space & output model
|
| 10 |
-
|
| 11 |
-
Nine actions: `up, down, forward, back, left, right, yaw-left, yaw-right, hover`.
|
| 12 |
-
|
| 13 |
-
- Per frame the generator emits a **set** of actions (e.g. `{forward, yaw-left}`);
|
| 14 |
-
`hover` is its own explicit token, emitted when the set is otherwise empty.
|
| 15 |
-
- The raw per-frame sets are **smoothed** into the published action: each set is
|
| 16 |
-
decomposed onto four signed axes — `x ∈ {left −1, right +1}`,
|
| 17 |
-
`y ∈ {down −1, up +1}`, `z ∈ {back −1, forward +1}`, `yaw ∈ {yaw-left −1,
|
| 18 |
-
yaw-right +1}` — averaged with a trailing window of `W = 90` frames (3 s @ 30 fps),
|
| 19 |
-
then re-thresholded. An axis whose smoothed magnitude is within the dead-zone
|
| 20 |
-
(`|mean| ≤ 0.33`) emits no motion; all axes quiet → `hover`.
|
| 21 |
-
|
| 22 |
-
---
|
| 23 |
-
|
| 24 |
-
## 1. Per-frame features
|
| 25 |
-
|
| 26 |
-
**Keep-in zone:** the center 50% of the frame — trim ¼ off each edge →
|
| 27 |
-
x ∈ [0.25, 0.75], y ∈ [0.25, 0.75] (frame 3840×2160). The herd is "centered"
|
| 28 |
-
when its centroid is inside this box; corrections fire when it leaves.
|
| 29 |
-
|
| 30 |
-
### Per-track (from `labels.csv`)
|
| 31 |
-
| field | values (normalized) |
|
| 32 |
-
|---|---|
|
| 33 |
-
| `species` | Giraffe, Plains Zebra, Grevys Zebra (collapse `Grevy`→`Grevys Zebra`) |
|
| 34 |
-
| `behaviour` | Head Up, Walk (collapse `Walking`→`Walk`), Graze, Browsing, Running, Trotting, Auto-Groom |
|
| 35 |
-
| `vigilant` | True if behaviour ∈ {Head Up, Running, Trotting} |
|
| 36 |
-
| `pose` | front, front-left, front-right, left, right, back-left, back-right, back |
|
| 37 |
-
| bbox | `x_c, y_c`, `w, h`, `bbox_area_frac`, `bbox_size_class` ∈ {far, medium, close} |
|
| 38 |
-
| telemetry | `latitude, longitude, altitude` (used by APPROACH only) |
|
| 39 |
-
|
| 40 |
-
### Frame-level aggregates (derived)
|
| 41 |
-
`n_tracks`, `centroid` (mean `x_c, y_c` over the followed animals, normalized),
|
| 42 |
-
`mean_px` (mean longest bbox side over followed animals), `pct_vigilant`,
|
| 43 |
-
`S_t` (trailing 90-frame mean of `pct_vigilant`), `majority_pose`.
|
| 44 |
-
When `n_tracks` exceeds `max_animals`, only the `max_animals` largest bboxes are
|
| 45 |
-
followed (this also subsumes herd fission/fusion: the larger subgroup wins).
|
| 46 |
-
|
| 47 |
-
---
|
| 48 |
-
|
| 49 |
-
## 2. The four maneuvers
|
| 50 |
-
|
| 51 |
-
### Maneuver 1 — APPROACH
|
| 52 |
-
Objective: begin the mission and position the drone without spooking wildlife.
|
| 53 |
-
**User params:** `launch_altitude` (50 m), `end_altitude` (30 m), `target_species`.
|
| 54 |
-
|
| 55 |
-
| # | condition | action | note |
|
| 56 |
-
|---|---|---|---|
|
| 57 |
-
| 1 | target detected, centroid in keep-zone | `hover` | approach complete → handoff |
|
| 58 |
-
| 2 | altitude < launch_altitude − 1 | `up` | climb to launch altitude |
|
| 59 |
-
| 3 | altitude > end_altitude + 1 | `down` | descend toward end altitude |
|
| 60 |
-
| 4 | otherwise (target not yet detected) | `forward` | search forward |
|
| 61 |
-
|
| 62 |
-
### Maneuver 2 — TRACK
|
| 63 |
-
Objective: keep the majority of the herd centroid in the center-50% keep-zone,
|
| 64 |
-
at a desired apparent size. Range control acts in the X–Z plane only (no vertical).
|
| 65 |
-
**User params:** `desired_pixels` (30), `pixel_band` (±0.25), `max_animals` (5).
|
| 66 |
-
|
| 67 |
-
| # | condition | action | note |
|
| 68 |
-
|---|---|---|---|
|
| 69 |
-
| 1 | centroid.x right of keep-zone | `left` | recenter |
|
| 70 |
-
| 2 | centroid.x left of keep-zone | `right` | recenter |
|
| 71 |
-
| 3 | mean_px below `desired_pixels·(1−band)` | `forward` | too small → close in |
|
| 72 |
-
| 4 | mean_px above `desired_pixels·(1+band)` | `back` | too large → back off |
|
| 73 |
-
| – | no detection | `hover` | |
|
| 74 |
-
|
| 75 |
-
### Maneuver 3 — BEHAVIOR-ADAPTIVE FLIGHT (BAF)
|
| 76 |
-
Objective: detect and respond to disturbance. Evaluated as an **override** on the
|
| 77 |
-
smoothed vigilance series `S_t`, with a hover hold after each trigger.
|
| 78 |
-
**User params:** `theta_S` (0.5), `baf_response` ∈ {retreat, hover}.
|
| 79 |
-
|
| 80 |
-
| # | condition | action | note |
|
| 81 |
-
|---|---|---|---|
|
| 82 |
-
| 1 | `S_t` ≥ theta_S | `retreat` = `{back, up}` (or `{hover}`) | override active maneuver |
|
| 83 |
-
| 2 | a trigger fired within the last 150 frames (5 s) | `hover` | hysteresis hold |
|
| 84 |
-
| 3 | otherwise | (no override; defer to active maneuver) | calm |
|
| 85 |
-
|
| 86 |
-
### Maneuver 4 — SoI-AWARE
|
| 87 |
-
Objective: maneuver to capture the desired Surface of Interest (pose) of the
|
| 88 |
-
majority of the herd, then hold at a target apparent size. Two stages.
|
| 89 |
-
**User params:** `soi` (desired pose, default `left`), `desired_pixels`
|
| 90 |
-
(per objective: track 30, behavior 100, re-ID 500).
|
| 91 |
-
|
| 92 |
-
The eight poses form a ring; one `yaw-left` step rotates apparent pose one
|
| 93 |
-
position around it (front → front-right → right → …). To reach the desired pose
|
| 94 |
-
the drone yaws the short way; `yaw-right` rotates the opposite direction.
|
| 95 |
-
|
| 96 |
-
| # | stage | condition | action |
|
| 97 |
-
|---|---|---|---|
|
| 98 |
-
| 1 | rotate | majority_pose ≠ soi | `yaw-left` / `yaw-right` (short way around ring) |
|
| 99 |
-
| 2 | range | majority_pose = soi, mean_px < target | `forward` |
|
| 100 |
-
| 3 | range | majority_pose = soi, mean_px > target | `back` |
|
| 101 |
-
| 4 | hold | majority_pose = soi, mean_px in band | `hover` |
|
| 102 |
-
| – | no pose available | | `hover` |
|
| 103 |
-
|
| 104 |
-
---
|
| 105 |
-
|
| 106 |
-
## 3. Composition (mission)
|
| 107 |
-
A mission may run several maneuvers; the intended override priority is
|
| 108 |
-
**BAF → APPROACH (until handoff) → TRACK → SoI**. This release generates labels
|
| 109 |
-
per `(clip × maneuver × param-set)` independently; cross-maneuver composition is
|
| 110 |
-
left to the consumer.
|
| 111 |
-
|
| 112 |
-
---
|
| 113 |
-
|
| 114 |
-
## 4. Generator output
|
| 115 |
-
Per `(clip × maneuver × param-set)`, long-format `maneuver_labels.csv` columns:
|
| 116 |
-
`clip_id, frame_local, maneuver, action_set_raw, action_set_smoothed,
|
| 117 |
-
triggering_branch, S_t, pct_vigilant, n_tracks, centroid_x, centroid_y, mean_px`.
|
| 118 |
-
|
| 119 |
-
---
|
| 120 |
-
|
| 121 |
-
## 5. Data hygiene
|
| 122 |
-
- Collapse `Walking`→`Walk`, `Grevy`→`Grevys Zebra` (applied at label-load and
|
| 123 |
-
re-emitted in the released dataset).
|
| 124 |
-
- `vigilant` = behaviour ∈ {Head Up, Running, Trotting}.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clip_library/maneuver_labels.py
DELETED
|
@@ -1,343 +0,0 @@
|
|
| 1 |
-
"""Deterministic maneuver-label generator (the ACSOS replay harness).
|
| 2 |
-
|
| 3 |
-
Given a clip's per-frame-per-track ``labels.csv`` and a maneuver + user params,
|
| 4 |
-
this replays the formal decision tree in ``maneuver_decision_tree.md`` (shipped
|
| 5 |
-
alongside this module) and emits one ground-truth drone action per frame. The
|
| 6 |
-
action is a *set* drawn
|
| 7 |
-
from the 9-action space, smoothed by a trailing rolling average so the GT track
|
| 8 |
-
isn't jerky.
|
| 9 |
-
|
| 10 |
-
This is the artifact's headline contribution: a small, inspectable policy
|
| 11 |
-
specification executed deterministically over a labeled benchmark, so a learned
|
| 12 |
-
navigation policy can be scored against an expert-calibrated reference.
|
| 13 |
-
|
| 14 |
-
Action space (per frame, a set; empty -> {hover}):
|
| 15 |
-
up, down, forward, back, left, right, yaw-left, yaw-right, hover
|
| 16 |
-
|
| 17 |
-
Usage:
|
| 18 |
-
# one clip, one maneuver
|
| 19 |
-
python -m clip_library.maneuver_labels --clip 12_01_23-DJI_0002_000745 --maneuver track
|
| 20 |
-
# all extracted clips, each maneuver it's tagged suitable for
|
| 21 |
-
python -m clip_library.maneuver_labels --all
|
| 22 |
-
"""
|
| 23 |
-
from __future__ import annotations
|
| 24 |
-
|
| 25 |
-
import os
|
| 26 |
-
import argparse
|
| 27 |
-
from dataclasses import dataclass, field, asdict
|
| 28 |
-
|
| 29 |
-
import numpy as np
|
| 30 |
-
import pandas as pd
|
| 31 |
-
|
| 32 |
-
from . import schema, io_paths
|
| 33 |
-
|
| 34 |
-
# --------------------------------------------------------------------------- #
|
| 35 |
-
# Frame geometry & the keep-in zone (center 50%)
|
| 36 |
-
# --------------------------------------------------------------------------- #
|
| 37 |
-
FRAME_W, FRAME_H = 3840, 2160
|
| 38 |
-
KEEP_LO, KEEP_HI = 0.25, 0.75 # trim 1/4 off each edge
|
| 39 |
-
|
| 40 |
-
# Smoothing: decompose actions onto signed axes, trailing-average over W frames,
|
| 41 |
-
# then re-threshold. |mean| <= AXIS_DEADZONE -> no motion on that axis.
|
| 42 |
-
SMOOTH_WINDOW = 90 # frames (3 s @ 30 fps)
|
| 43 |
-
AXIS_DEADZONE = 0.33
|
| 44 |
-
|
| 45 |
-
# Behaviour -> vigilance (matches schema.VIGILANCE_BEHAVIOURS)
|
| 46 |
-
VIGILANCE_WINDOW = 90 # frames (3 s) for the smoothed S_t
|
| 47 |
-
HOVER_HOLD = 150 # frames (5 s) BAF hovers after a trigger
|
| 48 |
-
|
| 49 |
-
# Pose ring, ordered so a +1 step == one 'yaw-left' increment of apparent pose
|
| 50 |
-
# (front -> front-right -> right ...). To rotate toward a target SoI we take the
|
| 51 |
-
# shortest signed distance around this ring; sign convention is OPEN ITEM 7.
|
| 52 |
-
POSE_RING = ["front", "front-right", "right", "back-right",
|
| 53 |
-
"back", "back-left", "left", "front-left"]
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
# --------------------------------------------------------------------------- #
|
| 57 |
-
# User parameters (reviewer-tunable; defaults from the spec)
|
| 58 |
-
# --------------------------------------------------------------------------- #
|
| 59 |
-
@dataclass
|
| 60 |
-
class Params:
|
| 61 |
-
# APPROACH
|
| 62 |
-
launch_altitude: float = 50.0
|
| 63 |
-
end_altitude: float = 30.0
|
| 64 |
-
target_species: str | None = None # None = any species counts as "target"
|
| 65 |
-
# TRACK / SoI pixel targets (longest bbox side, px)
|
| 66 |
-
desired_pixels: float = 30.0 # TRACK default; SoI overrides per objective
|
| 67 |
-
pixel_band: float = 0.25 # +/- tolerance around desired_pixels
|
| 68 |
-
max_animals: int = 5 # follow the N largest bboxes
|
| 69 |
-
# BAF
|
| 70 |
-
theta_S: float = 0.5 # vigilance threshold on smoothed S_t
|
| 71 |
-
baf_response: str = "retreat" # 'retreat' -> {back, up} | 'hover'
|
| 72 |
-
# SoI
|
| 73 |
-
soi: str = "left" # desired pose (broadside by default)
|
| 74 |
-
|
| 75 |
-
def with_objective(self, objective: str) -> "Params":
|
| 76 |
-
"""SoI desired-pixel presets by downstream objective (cite prior work)."""
|
| 77 |
-
px = {"track": 30.0, "behavior": 100.0, "reid": 500.0}.get(objective)
|
| 78 |
-
if px is not None:
|
| 79 |
-
self.desired_pixels = px
|
| 80 |
-
return self
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
# axis encoding: (dx, dy, dz, dyaw); +x right, +y up, +z forward, +yaw yaw-right
|
| 84 |
-
_AXIS_TO_TOKENS = {
|
| 85 |
-
("x", +1): "right", ("x", -1): "left",
|
| 86 |
-
("y", +1): "up", ("y", -1): "down",
|
| 87 |
-
("z", +1): "forward", ("z", -1): "back",
|
| 88 |
-
("yaw", +1): "yaw-right", ("yaw", -1): "yaw-left",
|
| 89 |
-
}
|
| 90 |
-
_TOKEN_TO_AXIS = {tok: (ax, s) for (ax, s), tok in _AXIS_TO_TOKENS.items()}
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
def _tokens_to_vec(tokens: set[str]) -> np.ndarray:
|
| 94 |
-
"""{action tokens} -> signed [x, y, z, yaw] vector ('hover' -> zeros)."""
|
| 95 |
-
idx = {"x": 0, "y": 1, "z": 2, "yaw": 3}
|
| 96 |
-
v = np.zeros(4)
|
| 97 |
-
for t in tokens:
|
| 98 |
-
if t in _TOKEN_TO_AXIS:
|
| 99 |
-
ax, s = _TOKEN_TO_AXIS[t]
|
| 100 |
-
v[idx[ax]] = s
|
| 101 |
-
return v
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
def _vec_to_tokens(v: np.ndarray) -> set[str]:
|
| 105 |
-
"""Signed [x, y, z, yaw] -> action token set ('hover' if all zero)."""
|
| 106 |
-
axes = ["x", "y", "z", "yaw"]
|
| 107 |
-
toks = {_AXIS_TO_TOKENS[(ax, int(np.sign(val)))]
|
| 108 |
-
for ax, val in zip(axes, v) if val != 0}
|
| 109 |
-
return toks or {"hover"}
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
# --------------------------------------------------------------------------- #
|
| 113 |
-
# Per-frame features
|
| 114 |
-
# --------------------------------------------------------------------------- #
|
| 115 |
-
@dataclass
|
| 116 |
-
class FrameFeatures:
|
| 117 |
-
frame_local: int
|
| 118 |
-
n_tracks: int
|
| 119 |
-
centroid_x: float # normalized 0..1
|
| 120 |
-
centroid_y: float
|
| 121 |
-
mean_px: float # mean longest-side over followed animals
|
| 122 |
-
pct_vigilant: float
|
| 123 |
-
majority_pose: str
|
| 124 |
-
altitude: float
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
def _bbox_px(row) -> float:
|
| 128 |
-
return float(max(row.w, row.h))
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
def _frame_features(g: pd.DataFrame, params: Params) -> FrameFeatures:
|
| 132 |
-
"""Compute frame-level aggregates from the visible tracks at one frame."""
|
| 133 |
-
vis = g[~g["outside"].astype(str).str.lower().isin(["true", "1"])]
|
| 134 |
-
n = len(vis)
|
| 135 |
-
if n == 0:
|
| 136 |
-
return FrameFeatures(int(g["frame_local"].iloc[0]), 0,
|
| 137 |
-
0.5, 0.5, 0.0, 0.0, "", float("nan"))
|
| 138 |
-
# follow the N largest bboxes (subsumes fission/fusion: larger subgroup wins)
|
| 139 |
-
vis = vis.assign(_area=vis["w"] * vis["h"]).nlargest(params.max_animals, "_area")
|
| 140 |
-
cx = float(vis["x_c"].mean()) / FRAME_W
|
| 141 |
-
cy = float(vis["y_c"].mean()) / FRAME_H
|
| 142 |
-
mean_px = float(vis.apply(_bbox_px, axis=1).mean())
|
| 143 |
-
vig = vis["vigilant"].astype(str).str.lower().isin(["true", "1"]).mean()
|
| 144 |
-
poses = [p for p in vis["pose"].astype(str) if p and p != "nan"]
|
| 145 |
-
majority = max(set(poses), key=poses.count) if poses else ""
|
| 146 |
-
alt = float(vis["altitude"].iloc[0]) if "altitude" in vis else float("nan")
|
| 147 |
-
return FrameFeatures(int(g["frame_local"].iloc[0]), int(n),
|
| 148 |
-
cx, cy, mean_px, float(vig), majority, alt)
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
# --------------------------------------------------------------------------- #
|
| 152 |
-
# Per-maneuver decision functions: features -> (token set, branch id)
|
| 153 |
-
# --------------------------------------------------------------------------- #
|
| 154 |
-
def decide_track(f: FrameFeatures, p: Params) -> tuple[set[str], str]:
|
| 155 |
-
if f.n_tracks == 0:
|
| 156 |
-
return {"hover"}, "no-detection"
|
| 157 |
-
toks: set[str] = set()
|
| 158 |
-
# horizontal recenter (keep herd centroid in center-50%)
|
| 159 |
-
if f.centroid_x > KEEP_HI:
|
| 160 |
-
toks.add("left")
|
| 161 |
-
elif f.centroid_x < KEEP_LO:
|
| 162 |
-
toks.add("right")
|
| 163 |
-
# range control by apparent pixel size (X-Z plane only; no vertical)
|
| 164 |
-
lo, hi = p.desired_pixels * (1 - p.pixel_band), p.desired_pixels * (1 + p.pixel_band)
|
| 165 |
-
if f.mean_px < lo:
|
| 166 |
-
toks.add("forward")
|
| 167 |
-
elif f.mean_px > hi:
|
| 168 |
-
toks.add("back")
|
| 169 |
-
return (toks or {"hover"}), "track"
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
def decide_soi(f: FrameFeatures, p: Params) -> tuple[set[str], str]:
|
| 173 |
-
if f.n_tracks == 0 or not f.majority_pose:
|
| 174 |
-
return {"hover"}, "no-pose"
|
| 175 |
-
if f.majority_pose not in POSE_RING or p.soi not in POSE_RING:
|
| 176 |
-
return {"hover"}, "pose-unknown"
|
| 177 |
-
if f.majority_pose != p.soi:
|
| 178 |
-
# shortest signed rotation around the ring; +step == yaw-left
|
| 179 |
-
i, j = POSE_RING.index(f.majority_pose), POSE_RING.index(p.soi)
|
| 180 |
-
d = (j - i) % len(POSE_RING)
|
| 181 |
-
step = d if d <= len(POSE_RING) - d else d - len(POSE_RING)
|
| 182 |
-
return ({"yaw-left"} if step > 0 else {"yaw-right"}), "soi-rotate"
|
| 183 |
-
# pose achieved -> close/retreat to desired pixels
|
| 184 |
-
lo, hi = p.desired_pixels * (1 - p.pixel_band), p.desired_pixels * (1 + p.pixel_band)
|
| 185 |
-
if f.mean_px < lo:
|
| 186 |
-
return {"forward"}, "soi-range-in"
|
| 187 |
-
if f.mean_px > hi:
|
| 188 |
-
return {"back"}, "soi-range-out"
|
| 189 |
-
return {"hover"}, "soi-hold"
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
def decide_approach(f: FrameFeatures, p: Params) -> tuple[set[str], str]:
|
| 193 |
-
detected = (f.n_tracks > 0 and KEEP_LO <= f.centroid_x <= KEEP_HI
|
| 194 |
-
and KEEP_LO <= f.centroid_y <= KEEP_HI)
|
| 195 |
-
if detected:
|
| 196 |
-
return {"hover"}, "approach-detected" # handoff
|
| 197 |
-
if not np.isnan(f.altitude):
|
| 198 |
-
if f.altitude < p.launch_altitude - 1:
|
| 199 |
-
return {"up"}, "approach-climb"
|
| 200 |
-
if f.altitude > p.end_altitude + 1:
|
| 201 |
-
return {"down"}, "approach-descend"
|
| 202 |
-
return {"forward"}, "approach-search"
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
def decide_baf(series_St: np.ndarray, idx: int, p: Params) -> tuple[set[str], str]:
|
| 206 |
-
"""BAF is an override; evaluated on the smoothed S_t series with a hover hold."""
|
| 207 |
-
if series_St[idx] >= p.theta_S:
|
| 208 |
-
resp = {"back", "up"} if p.baf_response == "retreat" else {"hover"}
|
| 209 |
-
return resp, "baf-trigger"
|
| 210 |
-
# hover-hold: stay hovering for HOVER_HOLD frames after the last trigger
|
| 211 |
-
lo = max(0, idx - HOVER_HOLD)
|
| 212 |
-
if np.any(series_St[lo:idx] >= p.theta_S):
|
| 213 |
-
return {"hover"}, "baf-hold"
|
| 214 |
-
return set(), "baf-calm" # empty -> no override
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
# --------------------------------------------------------------------------- #
|
| 218 |
-
# Driver
|
| 219 |
-
# --------------------------------------------------------------------------- #
|
| 220 |
-
def _smooth(raw_vecs: np.ndarray, window: int) -> np.ndarray:
|
| 221 |
-
"""Trailing rolling-mean each axis, then re-threshold past the dead-zone."""
|
| 222 |
-
df = pd.DataFrame(raw_vecs, columns=["x", "y", "z", "yaw"])
|
| 223 |
-
sm = df.rolling(window, min_periods=1).mean()
|
| 224 |
-
out = np.where(sm.abs() <= AXIS_DEADZONE, 0, np.sign(sm))
|
| 225 |
-
return out
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
def generate(labels_csv: str, maneuver: str, params: Params) -> pd.DataFrame:
|
| 229 |
-
df = pd.read_csv(labels_csv, low_memory=False)
|
| 230 |
-
frames = sorted(df["frame_local"].unique())
|
| 231 |
-
feats = [_frame_features(df[df["frame_local"] == fl], params) for fl in frames]
|
| 232 |
-
|
| 233 |
-
# BAF needs the smoothed S_t series first
|
| 234 |
-
pct_vig = np.array([f.pct_vigilant for f in feats])
|
| 235 |
-
St = pd.Series(pct_vig).rolling(VIGILANCE_WINDOW, min_periods=1).mean().to_numpy()
|
| 236 |
-
|
| 237 |
-
rows, raw_vecs = [], []
|
| 238 |
-
for i, f in enumerate(feats):
|
| 239 |
-
if maneuver == "track":
|
| 240 |
-
toks, branch = decide_track(f, params)
|
| 241 |
-
elif maneuver == "soi_aware":
|
| 242 |
-
toks, branch = decide_soi(f, params)
|
| 243 |
-
elif maneuver == "approach":
|
| 244 |
-
toks, branch = decide_approach(f, params)
|
| 245 |
-
elif maneuver == "behavior_adaptive":
|
| 246 |
-
toks, branch = decide_baf(St, i, params)
|
| 247 |
-
toks = toks or {"hover"}
|
| 248 |
-
else:
|
| 249 |
-
raise ValueError(f"unknown maneuver {maneuver!r}")
|
| 250 |
-
raw_vecs.append(_tokens_to_vec(toks))
|
| 251 |
-
rows.append((f, branch, toks))
|
| 252 |
-
|
| 253 |
-
smoothed = _smooth(np.array(raw_vecs), SMOOTH_WINDOW)
|
| 254 |
-
|
| 255 |
-
out = []
|
| 256 |
-
for (f, branch, raw_toks), sv in zip(rows, smoothed):
|
| 257 |
-
out.append({
|
| 258 |
-
"clip_id": os.path.basename(os.path.dirname(labels_csv)),
|
| 259 |
-
"frame_local": f.frame_local,
|
| 260 |
-
"maneuver": maneuver,
|
| 261 |
-
"action_set_raw": "|".join(sorted(raw_toks)),
|
| 262 |
-
"action_set_smoothed": "|".join(sorted(_vec_to_tokens(sv))),
|
| 263 |
-
"triggering_branch": branch,
|
| 264 |
-
"S_t": round(float(St[f.frame_local]) if f.frame_local < len(St) else 0.0, 3),
|
| 265 |
-
"pct_vigilant": round(f.pct_vigilant, 3),
|
| 266 |
-
"n_tracks": f.n_tracks,
|
| 267 |
-
"centroid_x": round(f.centroid_x, 3),
|
| 268 |
-
"centroid_y": round(f.centroid_y, 3),
|
| 269 |
-
"mean_px": round(f.mean_px, 1),
|
| 270 |
-
})
|
| 271 |
-
return pd.DataFrame(out)
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
def _clip_dirs(out_root: str) -> list[str]:
|
| 275 |
-
clips = os.path.join(out_root, "clips")
|
| 276 |
-
return sorted(
|
| 277 |
-
os.path.join(clips, d) for d in os.listdir(clips)
|
| 278 |
-
if os.path.exists(os.path.join(clips, d, "labels.csv"))
|
| 279 |
-
) if os.path.isdir(clips) else []
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
def main():
|
| 283 |
-
ap = argparse.ArgumentParser(description="Generate deterministic maneuver-action labels")
|
| 284 |
-
ap.add_argument("--out", default=schema.OUTPUT_ROOT)
|
| 285 |
-
ap.add_argument("--clip", default=None, help="clip_id (default: all extracted)")
|
| 286 |
-
ap.add_argument("--maneuver", default=None,
|
| 287 |
-
choices=["approach", "track", "behavior_adaptive", "soi_aware"],
|
| 288 |
-
help="default: each clip's suitable_maneuvers")
|
| 289 |
-
ap.add_argument("--all", action="store_true")
|
| 290 |
-
# a few inline param overrides
|
| 291 |
-
ap.add_argument("--desired-pixels", type=float, default=None)
|
| 292 |
-
ap.add_argument("--theta-s", type=float, default=None)
|
| 293 |
-
ap.add_argument("--soi", default=None)
|
| 294 |
-
args = ap.parse_args()
|
| 295 |
-
|
| 296 |
-
clip_index = io_paths.read_table(os.path.join(args.out, "catalog", "clip_index"))
|
| 297 |
-
suitable = dict(zip(clip_index["clip_id"], clip_index["suitable_maneuvers"].fillna("")))
|
| 298 |
-
# map spec name 'launch' tag -> 'approach' maneuver
|
| 299 |
-
name_map = {"launch": "approach", "follow": "track",
|
| 300 |
-
"behavior_adaptive": "behavior_adaptive", "soi_aware": "soi_aware"}
|
| 301 |
-
|
| 302 |
-
dirs = _clip_dirs(args.out)
|
| 303 |
-
if args.clip:
|
| 304 |
-
dirs = [d for d in dirs if os.path.basename(d) == args.clip]
|
| 305 |
-
if not dirs:
|
| 306 |
-
raise SystemExit(f"no extracted clip {args.clip!r} (run extract_clips first)")
|
| 307 |
-
|
| 308 |
-
# A "what-if" run (maneuver subset or any tuned param) must NOT clobber the
|
| 309 |
-
# canonical, default-param maneuver_labels.csv -- it writes a sidecar instead.
|
| 310 |
-
is_tweak = bool(args.maneuver or args.desired_pixels is not None
|
| 311 |
-
or args.theta_s is not None or args.soi is not None)
|
| 312 |
-
out_name = "maneuver_labels.custom.csv" if is_tweak else "maneuver_labels.csv"
|
| 313 |
-
if is_tweak:
|
| 314 |
-
print(f"[tweak run] writing {out_name} (canonical maneuver_labels.csv untouched)")
|
| 315 |
-
|
| 316 |
-
n_written = 0
|
| 317 |
-
for d in dirs:
|
| 318 |
-
cid = os.path.basename(d)
|
| 319 |
-
tags = [name_map.get(t, t) for t in str(suitable.get(cid, "")).split("|") if t]
|
| 320 |
-
maneuvers = [args.maneuver] if args.maneuver else tags
|
| 321 |
-
parts = []
|
| 322 |
-
for mv in maneuvers:
|
| 323 |
-
p = Params()
|
| 324 |
-
if args.desired_pixels is not None:
|
| 325 |
-
p.desired_pixels = args.desired_pixels
|
| 326 |
-
if args.theta_s is not None:
|
| 327 |
-
p.theta_S = args.theta_s
|
| 328 |
-
if args.soi is not None:
|
| 329 |
-
p.soi = args.soi
|
| 330 |
-
parts.append(generate(os.path.join(d, "labels.csv"), mv, p))
|
| 331 |
-
if not parts:
|
| 332 |
-
continue
|
| 333 |
-
res = pd.concat(parts, ignore_index=True)
|
| 334 |
-
res.to_csv(os.path.join(d, out_name), index=False)
|
| 335 |
-
n_written += 1
|
| 336 |
-
summ = res.groupby("maneuver")["action_set_smoothed"].agg(
|
| 337 |
-
lambda s: s.value_counts().idxmax())
|
| 338 |
-
print(f" {cid}: {', '.join(f'{m}->{a}' for m, a in summ.items())}")
|
| 339 |
-
print(f"\nwrote {out_name} for {n_written} clip(s)")
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
if __name__ == "__main__":
|
| 343 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clip_library/requirements.txt
DELETED
|
@@ -1,6 +0,0 @@
|
|
| 1 |
-
# Runtime dependencies for the drone-maneuver clip library + replay harness.
|
| 2 |
-
# CPU-only; no GPU or deep-learning framework required.
|
| 3 |
-
# pip install -r requirements.txt
|
| 4 |
-
pandas>=2.0
|
| 5 |
-
numpy>=1.23
|
| 6 |
-
pyarrow>=12.0 # optional: enables/prefers Parquet catalog I/O
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clip_library/schema.py
DELETED
|
@@ -1,164 +0,0 @@
|
|
| 1 |
-
"""Shared constants and schema for the drone-maneuver test-clip library.
|
| 2 |
-
|
| 3 |
-
One place for: clip geometry, the label/index column sets, bbox-size and
|
| 4 |
-
vigilance thresholds, the four maneuver-suitability tags, and the pose taxonomy.
|
| 5 |
-
|
| 6 |
-
Nothing here imports heavy deps (no pandas/cv2 at import time) so it can be
|
| 7 |
-
pulled into any consumer cheaply.
|
| 8 |
-
|
| 9 |
-
This is the released ("Mode A") subset: it documents the columns and
|
| 10 |
-
vocabularies of the published dataset and configures where the harness reads
|
| 11 |
-
and writes. The raw-video rebuild pipeline and its source-data paths are not
|
| 12 |
-
part of this public release.
|
| 13 |
-
"""
|
| 14 |
-
|
| 15 |
-
from __future__ import annotations
|
| 16 |
-
|
| 17 |
-
import os
|
| 18 |
-
|
| 19 |
-
# --------------------------------------------------------------------------- #
|
| 20 |
-
# Paths
|
| 21 |
-
# --------------------------------------------------------------------------- #
|
| 22 |
-
# Root of the released clip library (holds catalog/ and clips/). Override with
|
| 23 |
-
# the DRONE_CLIPS_ROOT environment variable; defaults to ./data/drone-maneuver-clips,
|
| 24 |
-
# relative to the current working directory, so it works straight out of a
|
| 25 |
-
# Hugging Face download.
|
| 26 |
-
OUTPUT_ROOT = os.environ.get(
|
| 27 |
-
"DRONE_CLIPS_ROOT", os.path.join("data", "drone-maneuver-clips")
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
# --------------------------------------------------------------------------- #
|
| 31 |
-
# Clip geometry
|
| 32 |
-
# --------------------------------------------------------------------------- #
|
| 33 |
-
FPS = 30 # KABR occurrences are one row per native video frame @ 30 fps
|
| 34 |
-
CLIP_SECONDS = 6
|
| 35 |
-
CLIP_FRAMES = FPS * CLIP_SECONDS # 180
|
| 36 |
-
|
| 37 |
-
# --------------------------------------------------------------------------- #
|
| 38 |
-
# Behaviour vocabulary
|
| 39 |
-
# --------------------------------------------------------------------------- #
|
| 40 |
-
# Behaviours that contribute to a vigilance signal.
|
| 41 |
-
VIGILANCE_BEHAVIOURS = frozenset({"Head Up", "Running", "Trotting"})
|
| 42 |
-
|
| 43 |
-
# Non-animal / non-informative behaviour markers seen in the source labels.
|
| 44 |
-
NON_BEHAVIOUR = frozenset({"Out of Frame", "Out of Focus", "Occluded", ""})
|
| 45 |
-
|
| 46 |
-
# --------------------------------------------------------------------------- #
|
| 47 |
-
# Canonical token collapses (source labels are inconsistent)
|
| 48 |
-
# --------------------------------------------------------------------------- #
|
| 49 |
-
# Applied at label-load so the published dataset + catalog use one token each.
|
| 50 |
-
SPECIES_CANONICAL = {"Grevy": "Grevys Zebra"}
|
| 51 |
-
BEHAVIOUR_CANONICAL = {"Walking": "Walk"}
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
def normalize_species(s) -> str:
|
| 55 |
-
s = ("" if s is None else str(s)).strip()
|
| 56 |
-
return SPECIES_CANONICAL.get(s, s)
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
def normalize_behaviour(b) -> str:
|
| 60 |
-
b = ("" if b is None else str(b)).strip()
|
| 61 |
-
return BEHAVIOUR_CANONICAL.get(b, b)
|
| 62 |
-
|
| 63 |
-
# --------------------------------------------------------------------------- #
|
| 64 |
-
# Bounding-box size classes (fraction of frame area)
|
| 65 |
-
# --------------------------------------------------------------------------- #
|
| 66 |
-
# far : bbox_area_frac < BBOX_FAR_MAX
|
| 67 |
-
# close: bbox_area_frac >= BBOX_CLOSE_MIN
|
| 68 |
-
# medium: in between
|
| 69 |
-
#
|
| 70 |
-
# Thresholds are RELATIVE to this dataset's range. KABR is flown at 20-50 m, so
|
| 71 |
-
# animals occupy a small frame fraction throughout (p99 of bbox area ~= 0.018).
|
| 72 |
-
# These cut points (~p65 / ~p92 of the bbox-area distribution) give a usable
|
| 73 |
-
# far/medium/close split; "close" here means close *for this survey*, not that
|
| 74 |
-
# the animal fills the frame.
|
| 75 |
-
BBOX_FAR_MAX = 0.001
|
| 76 |
-
BBOX_CLOSE_MIN = 0.005
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
def bbox_size_class(area_frac: float) -> str:
|
| 80 |
-
if area_frac < BBOX_FAR_MAX:
|
| 81 |
-
return "far"
|
| 82 |
-
if area_frac >= BBOX_CLOSE_MIN:
|
| 83 |
-
return "close"
|
| 84 |
-
return "medium"
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
# --------------------------------------------------------------------------- #
|
| 88 |
-
# Maneuver-suitability tags
|
| 89 |
-
# --------------------------------------------------------------------------- #
|
| 90 |
-
MANEUVERS = ("launch", "follow", "behavior_adaptive", "soi_aware")
|
| 91 |
-
|
| 92 |
-
# --------------------------------------------------------------------------- #
|
| 93 |
-
# Pose taxonomy (matches the KABR-poses folder names)
|
| 94 |
-
# --------------------------------------------------------------------------- #
|
| 95 |
-
POSE_CLASSES = (
|
| 96 |
-
"front",
|
| 97 |
-
"front-left",
|
| 98 |
-
"front-right",
|
| 99 |
-
"left",
|
| 100 |
-
"right",
|
| 101 |
-
"back-left",
|
| 102 |
-
"back-right",
|
| 103 |
-
"back",
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
-
# --------------------------------------------------------------------------- #
|
| 107 |
-
# Column sets
|
| 108 |
-
# --------------------------------------------------------------------------- #
|
| 109 |
-
# One row per frame per track.
|
| 110 |
-
LABEL_COLUMNS = [
|
| 111 |
-
"clip_id",
|
| 112 |
-
"video_id",
|
| 113 |
-
"session_id",
|
| 114 |
-
"frame_global",
|
| 115 |
-
"frame_local",
|
| 116 |
-
"time_s",
|
| 117 |
-
"track_id",
|
| 118 |
-
"species",
|
| 119 |
-
"behaviour",
|
| 120 |
-
"vigilant",
|
| 121 |
-
"pose",
|
| 122 |
-
"pose_provenance",
|
| 123 |
-
"pose_match_score",
|
| 124 |
-
"individual_id",
|
| 125 |
-
"xtl",
|
| 126 |
-
"ytl",
|
| 127 |
-
"xbr",
|
| 128 |
-
"ybr",
|
| 129 |
-
"x_c",
|
| 130 |
-
"y_c",
|
| 131 |
-
"w",
|
| 132 |
-
"h",
|
| 133 |
-
"bbox_area_frac",
|
| 134 |
-
"bbox_size_class",
|
| 135 |
-
"occluded",
|
| 136 |
-
"outside",
|
| 137 |
-
"latitude",
|
| 138 |
-
"longitude",
|
| 139 |
-
"altitude",
|
| 140 |
-
"date_time",
|
| 141 |
-
]
|
| 142 |
-
|
| 143 |
-
# One row per clip.
|
| 144 |
-
CLIP_INDEX_COLUMNS = [
|
| 145 |
-
"clip_id",
|
| 146 |
-
"video_id",
|
| 147 |
-
"session_id",
|
| 148 |
-
"start_frame",
|
| 149 |
-
"end_frame",
|
| 150 |
-
"start_time",
|
| 151 |
-
"species_set",
|
| 152 |
-
"habitat",
|
| 153 |
-
"herd_size",
|
| 154 |
-
"n_tracks",
|
| 155 |
-
"behaviours_present",
|
| 156 |
-
"has_vigilance",
|
| 157 |
-
"bbox_size_classes",
|
| 158 |
-
"pose_set",
|
| 159 |
-
"suitable_maneuvers",
|
| 160 |
-
"fair2_video_eventID",
|
| 161 |
-
"fair2_session_eventID",
|
| 162 |
-
"source_video_path",
|
| 163 |
-
"label_provenance",
|
| 164 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|