echoctx commited on
Commit
3483eb1
·
verified ·
1 Parent(s): 4334d91

scorevision: push artifact

Browse files
Files changed (1) hide show
  1. miner.py +98 -0
miner.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Scaffold miner for manak0/Detect-fire (specialized public package).
2
+
3
+ Required chute contract:
4
+ - class named Miner
5
+ - method predict_batch(batch_images, offset, n_keypoints) -> list[TVFrameResult]
6
+ - this file lives at the root of the HF model repo
7
+
8
+ This scaffold is intentionally element-specialized (object labels,
9
+ element metadata). Weights are placeholder; distill/train fills real
10
+ ONNX/PT artifacts under the 30 MB hard cap.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ from pathlib import Path
16
+ from typing import Any
17
+
18
+ from pydantic import BaseModel
19
+
20
+
21
+ class BoundingBox(BaseModel):
22
+ x1: int
23
+ y1: int
24
+ x2: int
25
+ y2: int
26
+ cls_id: int
27
+ conf: float
28
+
29
+
30
+ class Polygon(BaseModel):
31
+ cls_id: int
32
+ conf: float
33
+ points: list[tuple[int, int]]
34
+
35
+
36
+ class TVFrameResult(BaseModel):
37
+ frame_id: int
38
+ boxes: list[BoundingBox] | None = None
39
+ polygons: list[Polygon] | None = None
40
+ keypoints: list[tuple[int, int]] | None = None
41
+
42
+
43
+ ELEMENT_ID = 'manak0/Detect-fire'
44
+ SHORT_NAME = 'fire'
45
+ OBJECT_LABELS = (
46
+ 'fire',
47
+ 'smoke',
48
+ 'flame',
49
+ 'ember',
50
+ 'torch',
51
+ )
52
+
53
+
54
+ class Miner:
55
+ """Specialist detector package for manak0/Detect-fire."""
56
+
57
+ def __init__(self, path_hf_repo: Path) -> None:
58
+ self.path_hf_repo = Path(path_hf_repo)
59
+ self.element_id = ELEMENT_ID
60
+ self.object_labels = list(OBJECT_LABELS)
61
+ self._weights = self._discover_weights()
62
+
63
+ def _discover_weights(self) -> Path | None:
64
+ for name in ("model.onnx", "weights.onnx", "model.pt", "weights.pt"):
65
+ cand = self.path_hf_repo / name
66
+ if cand.is_file():
67
+ return cand
68
+ return None
69
+
70
+ def __repr__(self) -> str:
71
+ wname = self._weights.name if self._weights else None
72
+ return (
73
+ "Miner(element=%r, labels=%d, weights=%s)"
74
+ % (self.element_id, len(self.object_labels), wname)
75
+ )
76
+
77
+ def predict_batch(
78
+ self,
79
+ batch_images: list[Any],
80
+ offset: int,
81
+ n_keypoints: int,
82
+ ) -> list[TVFrameResult]:
83
+ """Return frame results. Scaffold emits empty boxes (schema-valid).
84
+
85
+ Live distillation replaces this with a tiny specialist detector.
86
+ """
87
+ results: list[TVFrameResult] = []
88
+ kps = [(0, 0) for _ in range(max(0, int(n_keypoints)))]
89
+ for i in range(len(batch_images)):
90
+ results.append(
91
+ TVFrameResult(
92
+ frame_id=offset + i,
93
+ boxes=[],
94
+ polygons=[],
95
+ keypoints=list(kps),
96
+ )
97
+ )
98
+ return results