davanstrien HF Staff commited on
Commit
d8ba40e
·
verified ·
1 Parent(s): 7bd0abb

Sync from GitHub via hub-sync

Browse files
Files changed (1) hide show
  1. SKILL.md +65 -19
SKILL.md CHANGED
@@ -18,9 +18,9 @@ You can use the approach outlined in this skill with or without a human in the l
18
  the right things?" is the highest-value question, and its fix is the cheapest (a better query, about $2 to
19
  re-run the teacher). Then train on a small slice first (500–1k images, about $1) and show 20 rendered
20
  predictions before spending on the full corpus. If corrections are worth collecting at volume, run a
21
- review pass with `review-detections.py` (keyboard accept/reject in the browser, per image or per box;
22
- prints the quotable acceptance + missed rates and pushes a `review` column), fold corrections in and
23
- retrain (about $1). Diff the corrected set against the first pass (`diff-hf-datasets.py`) to measure how
24
  good the zero-shot pass actually was.
25
  - **Autonomously** (headless): don't pause for review — use the numeric proxies, and say **unreviewed**
26
  in the final report and model card.
@@ -53,7 +53,14 @@ Judge the result before scaling up:
53
  - **If you can't**, compare instance counts across candidate queries (`stats-hf-dataset.py` below works
54
  on a pushed check dataset): near-zero instances/image means the class name is wrong for this material —
55
  try a synonym (`photograph` / `illustration` / `figure` / `cartoon`). Suspiciously many (more than about 10/image)
56
- usually means the query is matching layout blocks, not pictures.
 
 
 
 
 
 
 
57
  - **No vision at all?** A vision-capable subagent can judge the previews if you can spawn one;
58
  otherwise tell the user the check ran unviewed.
59
 
@@ -113,7 +120,27 @@ hf jobs uv run --flavor a10g-large --secrets HF_TOKEN --timeout 2h \
113
  **Don't resubmit**: a second copy racing to the same `--out` just doubles the bill. If you do
114
  switch (`hf jobs hardware` for alternatives), cancel the queued copy first (`hf jobs cancel <id>`).
115
  - For images in a [storage bucket](https://huggingface.co/docs/hub/storage-buckets) instead of a
116
- dataset, use `falcon-perception-bucket.py` from the same repo (resumable).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
  ## 3. Validate the labels (free, local)
119
 
@@ -140,22 +167,28 @@ uv run https://huggingface.co/datasets/uv-scripts/object-detection/raw/main/conv
140
 
141
  ## 5. Train a small detector
142
 
143
- Good starting points: [D-FINE](https://huggingface.co/ustc-community/dfine-small-coco) or
144
- [RT-DETRv2](https://huggingface.co/PekingU/rtdetr_v2_r18vd) — compact, Apache-2.0, in `transformers`
145
- (boxes only; for masks see the RF-DETR note below). Check the license fits the use —
146
- `hf models card <id>` shows it; flag restrictive licenses (e.g. ultralytics/YOLO is AGPL) to the user
147
- rather than deciding for them. Explore further:
148
- [transformers object-detection models](https://huggingface.co/models?pipeline_tag=object-detection&library=transformers&sort=trending) ·
149
- [ultralytics-library models](https://huggingface.co/models?library=ultralytics).
150
 
151
- The **`huggingface-vision-trainer`** skill covers the training end to end (dataset validation,
 
152
  augmentation, mAP eval, Hub persistence) — install it with `hf skills add huggingface-vision-trainer`
153
- if you don't have it, and follow its object-detection path with the `<USER>/<NAME>-coco` dataset from
154
- step 4. Before training, decide a pragmatic validation split and never train on it.
 
 
 
 
 
 
 
 
 
155
 
156
- Other trainers work too — the dataset is plain COCO. [RF-DETR](https://github.com/roboflow/rf-detr)
157
- (Apache-2.0, DINOv2 backbone) is a good starter, and its Seg variant can learn from the teacher's
158
- `masks_rle` masks. Decode them like this — each RLE lives in its own frame, which never matches the
159
  recorded width/height:
160
 
161
  ```python
@@ -172,10 +205,23 @@ for rle in json.loads(row["masks_rle"]):
172
  ## 6. Evaluate honestly
173
 
174
  - Report mAP on the held-out slice. Be clear about what it measures: **agreement with the teacher**,
175
- not accuracy against human truth — no human labels exist in this loop.
 
 
 
 
 
 
 
 
176
  - The student can at best match its teacher (measured on a comparable loop: student 97.4% vs teacher
177
  95.0% human-acceptable on the same sample). The point of distilling is **throughput and cost**
178
  (10–100× cheaper per image than the teacher), not accuracy gains.
 
 
 
 
 
179
  - Spot-check 20 or so predictions visually before calling it done — or, if running without a human and you
180
  cannot view images, state prominently in the report that the model is **unreviewed**.
181
  - It can make sense to run this process in a loop: predict → review (a human, or a vision-capable
 
18
  the right things?" is the highest-value question, and its fix is the cheapest (a better query, about $2 to
19
  re-run the teacher). Then train on a small slice first (500–1k images, about $1) and show 20 rendered
20
  predictions before spending on the full corpus. If corrections are worth collecting at volume, run a
21
+ review pass with `review-detections.py` (keyboard accept/reject in the browser — quick mode for
22
+ whole-image verdicts in random order with quotable rates, boxes mode for per-box rejects; pushes a
23
+ `review` column), fold corrections in and retrain (about $1). Diff the corrected set against the first pass (`diff-hf-datasets.py`) to measure how
24
  good the zero-shot pass actually was.
25
  - **Autonomously** (headless): don't pause for review — use the numeric proxies, and say **unreviewed**
26
  in the final report and model card.
 
53
  - **If you can't**, compare instance counts across candidate queries (`stats-hf-dataset.py` below works
54
  on a pushed check dataset): near-zero instances/image means the class name is wrong for this material —
55
  try a synonym (`photograph` / `illustration` / `figure` / `cartoon`). Suspiciously many (more than about 10/image)
56
+ *can* mean the query is matching layout blocks — but dense plates genuinely carry 10–20 figures,
57
+ so counts are a fallback signal only; previews are the judge.
58
+ - Measured on real material, previews judged:
59
+
60
+ | material | worked | partial | dud |
61
+ |---|---|---|---|
62
+ | historic newspaper pages (b/w scans) | `photograph`, `illustration` | | |
63
+ | book / encyclopaedia plates | `illustration` (incl. dense multi-figure plates) | `caption` (good on true plates, grabs whole text columns on text-heavy pages) | `figure` (0 hits on the same pages) |
64
  - **No vision at all?** A vision-capable subagent can judge the previews if you can spawn one;
65
  otherwise tell the user the check ran unviewed.
66
 
 
120
  **Don't resubmit**: a second copy racing to the same `--out` just doubles the bill. If you do
121
  switch (`hf jobs hardware` for alternatives), cancel the queued copy first (`hf jobs cancel <id>`).
122
  - For images in a [storage bucket](https://huggingface.co/docs/hub/storage-buckets) instead of a
123
+ dataset, use `falcon-perception-bucket.py` — it writes resumable parquet parts back to a bucket
124
+ (kill and re-run the same command; done keys are skipped):
125
+
126
+ ```
127
+ hf jobs uv run --flavor a10g-large --secrets HF_TOKEN --timeout 2h --detach \
128
+ https://huggingface.co/datasets/uv-scripts/object-detection/raw/main/falcon-perception-bucket.py \
129
+ --src <namespace>/<bucket> --prefix <path/under/bucket> \
130
+ --out <namespace>/<out-bucket> --query illustration
131
+ ```
132
+
133
+ Publish once at the end so the parts feed the rest of this loop (parquet stores `category` as
134
+ bare ints; the cast attaches the class name):
135
+
136
+ ```python
137
+ from datasets import ClassLabel, Sequence, load_dataset
138
+ ds = load_dataset("parquet", data_files="hf://buckets/<namespace>/<out-bucket>/part-*.parquet",
139
+ split="train")
140
+ feats = ds.features.copy()
141
+ feats["objects"]["category"] = Sequence(ClassLabel(names=[ds[0]["query"]]))
142
+ ds.cast(feats).push_to_hub("<namespace>/<dataset>")
143
+ ```
144
 
145
  ## 3. Validate the labels (free, local)
146
 
 
167
 
168
  ## 5. Train a small detector
169
 
170
+ A known-good default: fine-tune
171
+ [`ustc-community/dfine-small-coco`](https://huggingface.co/ustc-community/dfine-small-coco)
172
+ (D-FINE small, 10.4M params, Apache-2.0, in `transformers`) on the step-4 COCO dataset —
173
+ 800 images, 30 epochs, `t4-medium`, about 48 min and $0.35. Training needs only a T4:
174
+ step 2's 24 GB-VRAM rule is the teacher's engine, not the student's.
 
 
175
 
176
+ The [**`huggingface-vision-trainer`**](https://github.com/huggingface/skills/tree/main/skills/huggingface-vision-trainer)
177
+ skill runs the training end to end (dataset validation,
178
  augmentation, mAP eval, Hub persistence) — install it with `hf skills add huggingface-vision-trainer`
179
+ if you don't have it, and follow its object-detection path with the `<USER>/<NAME>-coco` dataset and
180
+ the settings above. Hold out the validation split — and the step-6 gold slice — BEFORE training,
181
+ and never train on either.
182
+
183
+ Other trainers work — the dataset is plain COCO. [RT-DETRv2](https://huggingface.co/PekingU/rtdetr_v2_r18vd)
184
+ is a comparable compact Apache-2.0 pick; [RF-DETR](https://github.com/roboflow/rf-detr) (Apache-2.0,
185
+ DINOv2 backbone) is a good starter, and its Seg variant can learn from the teacher's `masks_rle`
186
+ masks. Check the license fits the use — `hf models card <id>` shows it; flag restrictive licenses
187
+ (e.g. ultralytics/YOLO is AGPL) to the user rather than deciding for them. Explore further:
188
+ [transformers object-detection models](https://huggingface.co/models?pipeline_tag=object-detection&library=transformers&sort=trending) ·
189
+ [ultralytics-library models](https://huggingface.co/models?library=ultralytics).
190
 
191
+ Decode `masks_rle` like this — each RLE lives in its own frame, which never matches the
 
 
192
  recorded width/height:
193
 
194
  ```python
 
205
  ## 6. Evaluate honestly
206
 
207
  - Report mAP on the held-out slice. Be clear about what it measures: **agreement with the teacher**,
208
+ not accuracy against human truth — no human labels exist in this loop unless you make some (next
209
+ bullet).
210
+ - **Gold slice** (with a human in the loop): hold out about 100 random images BEFORE training, and have
211
+ the human verify every box on them with `review-detections.py --mode boxes --order random`, then
212
+ correct any misses (the tool flags them with M; drawing the missing boxes is manual for now).
213
+ Then report TWO numbers: mAP vs teacher labels AND mAP vs the human gold. They
214
+ differ, and the gap is the finding — in the validation run of this skill: 0.84 vs teacher labels
215
+ but 0.44 vs human gold, both mAP@50 on held-out pages. That gap is the teacher's systematic
216
+ divergence from human annotators, which teacher-agreement alone cannot see.
217
  - The student can at best match its teacher (measured on a comparable loop: student 97.4% vs teacher
218
  95.0% human-acceptable on the same sample). The point of distilling is **throughput and cost**
219
  (10–100× cheaper per image than the teacher), not accuracy gains.
220
+ - Evaluate with the model card's decode contract, and write that contract INTO the card (input
221
+ padding, score handling — with one class use the raw logit/sigmoid, never softmax). This is
222
+ load-bearing: a standard decode against a padded-square model measured 0.03 mAP where the
223
+ documented decode measured 10× higher. (Evaluating locally on Apple Silicon: pass the trainer's
224
+ eval a CPU device — the COCO eval path uses float64, which MPS lacks.)
225
  - Spot-check 20 or so predictions visually before calling it done — or, if running without a human and you
226
  cannot view images, state prominently in the report that the model is **unreviewed**.
227
  - It can make sense to run this process in a loop: predict → review (a human, or a vision-capable