eval-touch-detection 0.5.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.
@@ -0,0 +1,8 @@
1
+ data/train/
2
+ _site/
3
+ __pycache__/
4
+ node_modules/
5
+ .venv/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ dist/
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.5
2
+ Name: eval-touch-detection
3
+ Version: 0.5.0
4
+ Summary: Build touch-detection leaderboard submissions from per-frame predictions
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: numpy
@@ -0,0 +1,89 @@
1
+ {
2
+ "videos": {
3
+ "FS0001_test1": {
4
+ "fps": 30,
5
+ "n_frames": 11550,
6
+ "duration": 385
7
+ },
8
+ "FS0002_test1": {
9
+ "fps": 30,
10
+ "n_frames": 58664,
11
+ "duration": 1957.5
12
+ },
13
+ "FS0003a_test1": {
14
+ "fps": 60,
15
+ "n_frames": 9600,
16
+ "duration": 160
17
+ },
18
+ "FS0003b_test1": {
19
+ "fps": 60,
20
+ "n_frames": 9600,
21
+ "duration": 160
22
+ },
23
+ "FS0004a_test1": {
24
+ "fps": 60,
25
+ "n_frames": 9360,
26
+ "duration": 156
27
+ },
28
+ "FS0004b_test1": {
29
+ "fps": 60,
30
+ "n_frames": 9990,
31
+ "duration": 166.5
32
+ },
33
+ "FS0005a_test1": {
34
+ "fps": 60,
35
+ "n_frames": 5684,
36
+ "duration": 94.733333
37
+ },
38
+ "FS0005b_test1": {
39
+ "fps": 60,
40
+ "n_frames": 5820,
41
+ "duration": 97
42
+ },
43
+ "FS0006a_test1": {
44
+ "fps": 60,
45
+ "n_frames": 11280,
46
+ "duration": 188
47
+ },
48
+ "FS0006b_test1": {
49
+ "fps": 60,
50
+ "n_frames": 10860,
51
+ "duration": 181
52
+ },
53
+ "FS0006c_test1": {
54
+ "fps": 60,
55
+ "n_frames": 10380,
56
+ "duration": 173
57
+ },
58
+ "FS0007a_test1": {
59
+ "fps": 60,
60
+ "n_frames": 9703,
61
+ "duration": 161.716667
62
+ },
63
+ "FS0007b_test1": {
64
+ "fps": 60,
65
+ "n_frames": 9780,
66
+ "duration": 163
67
+ },
68
+ "FS0007c_test1": {
69
+ "fps": 60,
70
+ "n_frames": 9780,
71
+ "duration": 163
72
+ },
73
+ "FS0008a_test1": {
74
+ "fps": 60,
75
+ "n_frames": 11520,
76
+ "duration": 192
77
+ },
78
+ "FS0008b_test1": {
79
+ "fps": 60,
80
+ "n_frames": 11460,
81
+ "duration": 191
82
+ },
83
+ "FS0008c_test1": {
84
+ "fps": 60,
85
+ "n_frames": 11460,
86
+ "duration": 191
87
+ }
88
+ }
89
+ }
@@ -0,0 +1,38 @@
1
+ [project]
2
+ name = "eval-touch-detection"
3
+ dynamic = ["version"]
4
+ description = "Build touch-detection leaderboard submissions from per-frame predictions"
5
+ requires-python = ">=3.10"
6
+ dependencies = ["numpy"]
7
+
8
+ [project.scripts]
9
+ eval-touch-detection = "eval_touch_detection.make_submission:main"
10
+
11
+ [build-system]
12
+ requires = ["hatchling", "hatch-vcs"]
13
+ build-backend = "hatchling.build"
14
+
15
+ [tool.hatch.version]
16
+ source = "vcs"
17
+
18
+ [tool.hatch.build.targets.wheel]
19
+ packages = ["src/eval_touch_detection"]
20
+
21
+ [tool.hatch.build.targets.wheel.force-include]
22
+ "data/test/meta.json" = "eval_touch_detection/meta.json"
23
+
24
+ [tool.hatch.build.targets.sdist]
25
+ include = ["src", "data/test/meta.json"]
26
+
27
+ [dependency-groups]
28
+ dev = ["pytest", "ruff"]
29
+
30
+ [tool.pytest.ini_options]
31
+ testpaths = ["tests/py"]
32
+ pythonpath = ["tools", "src"]
33
+
34
+ [tool.ruff]
35
+ line-length = 120
36
+
37
+ [tool.ruff.lint]
38
+ select = ["E", "F", "I", "B"]
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env python3
2
+ """Build a submission JSON from per-frame predictions.
3
+
4
+ Input: a directory with one <video>.npy per test video, 1-D, length = n_frames.
5
+ - float in [0,1] -> probabilities (binary = prob >= --threshold; probs are stored too)
6
+ - bool / 0-1 int -> binary only
7
+ Usage: uvx eval-touch-detection preds_dir <name>.json [--threshold 0.5] [--no-probs]
8
+ """
9
+
10
+ import argparse
11
+ import base64
12
+ import json
13
+ from importlib import resources
14
+ from pathlib import Path
15
+
16
+ import numpy as np
17
+
18
+
19
+ def rle(b):
20
+ """Alternating run lengths, starting with a (possibly zero) run of 0s."""
21
+ b = np.asarray(b).astype(np.uint8)
22
+ if b.size == 0:
23
+ return []
24
+ edges = np.flatnonzero(np.diff(b)) + 1
25
+ bounds = np.concatenate([[0], edges, [b.size]])
26
+ runs = np.diff(bounds).tolist()
27
+ return ([0] if b[0] == 1 else []) + runs
28
+
29
+
30
+ def load_meta(path=None):
31
+ """Load video metadata: explicit path, else bundled copy, else the dev-checkout copy."""
32
+ if path:
33
+ return json.loads(Path(path).read_text())["videos"]
34
+ bundled = resources.files(__package__).joinpath("meta.json")
35
+ if bundled.is_file():
36
+ return json.loads(bundled.read_text())["videos"]
37
+ dev = Path(__file__).resolve().parents[2] / "data" / "test" / "meta.json"
38
+ if dev.is_file():
39
+ return json.loads(dev.read_text())["videos"]
40
+ raise SystemExit("meta.json not found; pass --meta")
41
+
42
+
43
+ def main():
44
+ ap = argparse.ArgumentParser()
45
+ ap.add_argument("pred_dir")
46
+ ap.add_argument("out")
47
+ ap.add_argument("--meta", help="override the bundled test meta.json")
48
+ ap.add_argument("--threshold", type=float, default=0.5)
49
+ ap.add_argument("--model", default="")
50
+ ap.add_argument("--notes", default="")
51
+ ap.add_argument("--no-probs", action="store_true")
52
+ a = ap.parse_args()
53
+
54
+ meta = load_meta(a.meta)
55
+ out = {"model": a.model, "notes": a.notes, "videos": {}}
56
+ for v, m in meta.items():
57
+ x = np.load(Path(a.pred_dir) / f"{v}.npy").reshape(-1)
58
+ if x.size != m["n_frames"]:
59
+ raise SystemExit(f"{v}: got {x.size} frames, expected {m['n_frames']}")
60
+ is_prob = x.dtype.kind == "f"
61
+ entry = {"n_frames": int(x.size), "rle": rle(x >= a.threshold if is_prob else x > 0)}
62
+ if is_prob and not a.no_probs:
63
+ entry["probs"] = base64.b64encode(np.clip(np.round(x * 255), 0, 255).astype(np.uint8).tobytes()).decode()
64
+ out["videos"][v] = entry
65
+ Path(a.out).write_text(json.dumps(out, separators=(",", ":")))
66
+ print(f"wrote {a.out}")
67
+
68
+
69
+ if __name__ == "__main__":
70
+ main()