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

Sync from GitHub via hub-sync

Browse files
Files changed (4) hide show
  1. README.md +7 -4
  2. SKILL.md +37 -8
  3. falcon-perception-bucket.py +13 -7
  4. falcon-perception.py +11 -6
README.md CHANGED
@@ -311,14 +311,17 @@ Anything ending `.json`, `.jsonl` or `.parquet` is written locally; anything els
311
  `falcon-perception-bucket.py` reads images from an HF bucket and writes resumable parquet parts back to a bucket — kill it and re-run the same command, done keys are skipped. Publish once at the end to use the rest of this directory:
312
 
313
  ```python
314
- from datasets import load_dataset
315
- load_dataset("parquet", data_files="hf://buckets/you/bl-masks/part-*.parquet",
316
- split="train").push_to_hub("you/bl-masks")
 
 
 
317
  ```
318
 
319
  ### Output columns
320
 
321
- `objects.bbox` (`yolo`), `objects.category`, `objects.area`, `objects.rectangularity`, plus `image`, `image_id` (int64 — COCO-style trainers require an integer id), `source_id` (the original key), `width`, `height`, `n_instances`, and `masks_rle` (COCO RLE — segmentation rides along; the bbox scripts ignore it).
322
 
323
  ### Train on the output
324
 
 
311
  `falcon-perception-bucket.py` reads images from an HF bucket and writes resumable parquet parts back to a bucket — kill it and re-run the same command, done keys are skipped. Publish once at the end to use the rest of this directory:
312
 
313
  ```python
314
+ from datasets import ClassLabel, Sequence, load_dataset
315
+ ds = load_dataset("parquet", data_files="hf://buckets/<namespace>/<bucket>/part-*.parquet",
316
+ split="train")
317
+ feats = ds.features.copy() # parquet stores category as bare ints; name the class
318
+ feats["objects"]["category"] = Sequence(ClassLabel(names=[ds[0]["query"]]))
319
+ ds.cast(feats).push_to_hub("<namespace>/<dataset>") # a dataset repo, distinct from the bucket
320
  ```
321
 
322
  ### Output columns
323
 
324
+ `objects.bbox` (`yolo`), `objects.category` (a `ClassLabel` named after the query), `objects.area`, `objects.rectangularity`, plus `image`, `image_id` (int64 — COCO-style trainers require an integer id), `source_id` (the original key), `width`, `height`, `n_instances`, and `masks_rle` (COCO RLE — segmentation rides along; the bbox scripts ignore it).
325
 
326
  ### Train on the output
327
 
SKILL.md CHANGED
@@ -40,8 +40,9 @@ or plain CPU (slow, but fine for 3 images). Run the check wherever is practical
40
  uv run https://huggingface.co/datasets/uv-scripts/object-detection/raw/main/falcon-perception.py \
41
  --dataset <USER>/<IMAGES> --limit 3 --query photograph --preview
42
 
43
- # or the same check as a small job (previews don't persist on Jobs — push a tiny dataset instead):
44
- hf jobs uv run --flavor t4-small --secrets HF_TOKEN \
 
45
  https://huggingface.co/datasets/uv-scripts/object-detection/raw/main/falcon-perception.py \
46
  --dataset <USER>/<IMAGES> --limit 3 --query photograph --out <USER>/<NAME>-check --private
47
  ```
@@ -69,12 +70,40 @@ hf jobs uv run --flavor a10g-large --secrets HF_TOKEN --timeout 2h \
69
  --dataset <USER>/<IMAGES> --query photograph --out <USER>/<NAME>-photograph --private
70
  ```
71
 
72
- - Avoid `a10g-small` the engine sizes itself from the GPU and ignores host RAM, so it gets
73
- OOM-killed. `hf jobs hardware` lists current options and prices.
74
- - One job per class (step 1's rule). Merge per-class outputs by concatenating the `objects` entries of
75
- rows with the same `image_id`.
76
- - Output schema: `objects.bbox` in **YOLO format** (normalized center x, y, w, h), `objects.category`,
77
- `objects.area`, `objects.rectangularity`, plus `image`, `image_id`, `width`, `height`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  - There are **no confidence scores** (the model has none). `rectangularity` (mask area ÷ box area) is the
79
  triage proxy: values near 0 are usually junk, 0.785 is a circle, 1.0 a full rectangle.
80
  - Submit with `--detach` (returns the job id immediately), then block on completion with
 
40
  uv run https://huggingface.co/datasets/uv-scripts/object-detection/raw/main/falcon-perception.py \
41
  --dataset <USER>/<IMAGES> --limit 3 --query photograph --preview
42
 
43
+ # or the same check as a small job (previews don't persist on Jobs — push a tiny dataset instead).
44
+ # l4x1 is the cheapest flavor that fits the engine (see step 2's flavor rule):
45
+ hf jobs uv run --flavor l4x1 --secrets HF_TOKEN \
46
  https://huggingface.co/datasets/uv-scripts/object-detection/raw/main/falcon-perception.py \
47
  --dataset <USER>/<IMAGES> --limit 3 --query photograph --out <USER>/<NAME>-check --private
48
  ```
 
70
  --dataset <USER>/<IMAGES> --query photograph --out <USER>/<NAME>-photograph --private
71
  ```
72
 
73
+ - Flavor rule (all three failures measured): the engine needs a **24 GB-VRAM GPU** (16 GB T4s
74
+ CUDA-OOM during prefill) and **more than 15 GB host RAM** (the engine sizes itself from the GPU
75
+ and ignores host RAM, so `t4-small` and `a10g-small` are OOMKilled before the first image).
76
+ `hf jobs hardware --json` lists every flavor's `ram`, accelerator and price — `l4x1` is the
77
+ cheapest fit (fine for the step-1 check); `a10g-large` is faster for a corpus pass.
78
+ - One job per class (step 1's rule). Every run labels its boxes `category` 0 in a single-name
79
+ `ClassLabel`, so a naive concat collapses the classes — renumber each run to its index in a
80
+ combined `ClassLabel` when merging. Rows align on `image_id` (every run contains every image):
81
+
82
+ ```python
83
+ from datasets import ClassLabel, Sequence, load_dataset
84
+
85
+ names = ["illustration", "map"]
86
+ parts = [load_dataset(f"<USER>/<NAME>-{n}", split="train") for n in names]
87
+ extra = [dict(zip(ds["image_id"], ds["objects"])) for ds in parts[1:]]
88
+
89
+ def merge(row):
90
+ o = {k: list(v) for k, v in row["objects"].items()}
91
+ for i, run in enumerate(extra, start=1):
92
+ r = run[row["image_id"]]
93
+ o["bbox"] += r["bbox"]; o["area"] += r["area"]
94
+ o["rectangularity"] += r["rectangularity"]
95
+ o["category"] += [i] * len(r["bbox"])
96
+ return {"objects": o, "n_instances": len(o["bbox"])}
97
+
98
+ feats = parts[0].features.copy()
99
+ feats["objects"]["category"] = Sequence(ClassLabel(names=names))
100
+ merged = parts[0].map(merge, features=feats)
101
+ ```
102
+
103
+ (`masks_rle` concatenates the same way if you need the masks.)
104
+ - Output schema: `objects.bbox` in **YOLO format** (normalized center x, y, w, h), `objects.category`
105
+ (a `ClassLabel` named after the query), `objects.area`, `objects.rectangularity`, plus `image`,
106
+ `image_id`, `width`, `height`.
107
  - There are **no confidence scores** (the model has none). `rectangularity` (mask area ÷ box area) is the
108
  triage proxy: values near 0 are usually junk, 0.785 is a circle, 1.0 a full rectangle.
109
  - Submit with `--detach` (returns the job id immediately), then block on completion with
falcon-perception-bucket.py CHANGED
@@ -26,11 +26,14 @@ Output is parquet parts in a BUCKET, not a dataset repo — that is what makes t
26
  run resumable (`completed_keys` reads the done-set back from `__source_key`).
27
  To hand the result to the rest of this directory, publish it once at the end:
28
 
29
- from datasets import load_dataset
30
- load_dataset("parquet", data_files="hf://buckets/you/bl-masks/part-*.parquet",
31
- split="train").push_to_hub("you/bl-masks")
 
 
 
32
 
33
- uv run validate-hf-dataset.py you/bl-masks --bbox-format yolo
34
 
35
  Note the parts carry `width`/`height` but no `image` column (the images stay in
36
  the source bucket), so pass --image-column accordingly if a downstream script
@@ -40,8 +43,9 @@ GOTCHAS (all measured, none in the model card):
40
  * --query is a CLASS NAME. "illustration" works; "the illustration, excluding
41
  captions" returns nothing.
42
  * torch.compile breaks on per-image dynamic shapes -> compile is OFF here.
43
- * engine_config_for_gpu() sizes from the GPU and ignores host RAM; on
44
- a10g-small it gets OOMKilled (exit 137) before processing anything.
 
45
  cudagraph is off by default here for the same reason.
46
  * xy in the output is the NORMALISED CENTRE, not a corner.
47
  """
@@ -73,7 +77,9 @@ SCHEMA = pa.schema([
73
  ("height", pa.int32()),
74
  ("objects", pa.struct([
75
  ("bbox", pa.list_(pa.list_(pa.float32()))), # yolo: cx, cy, w, h normalised
76
- ("category", pa.list_(pa.int64())), # single class per run, by design
 
 
77
  ("area", pa.list_(pa.float32())),
78
  ("rectangularity", pa.list_(pa.float32())), # triage proxy — no confidence score exists
79
  ])),
 
26
  run resumable (`completed_keys` reads the done-set back from `__source_key`).
27
  To hand the result to the rest of this directory, publish it once at the end:
28
 
29
+ from datasets import ClassLabel, Sequence, load_dataset
30
+ ds = load_dataset("parquet", data_files="hf://buckets/<namespace>/<bucket>/part-*.parquet",
31
+ split="train")
32
+ feats = ds.features.copy() # parquet stores category as bare ints; name the class
33
+ feats["objects"]["category"] = Sequence(ClassLabel(names=[ds[0]["query"]]))
34
+ ds.cast(feats).push_to_hub("<namespace>/<dataset>") # a dataset repo, distinct from the bucket
35
 
36
+ uv run validate-hf-dataset.py <namespace>/<dataset> --bbox-format yolo
37
 
38
  Note the parts carry `width`/`height` but no `image` column (the images stay in
39
  the source bucket), so pass --image-column accordingly if a downstream script
 
43
  * --query is a CLASS NAME. "illustration" works; "the illustration, excluding
44
  captions" returns nothing.
45
  * torch.compile breaks on per-image dynamic shapes -> compile is OFF here.
46
+ * engine_config_for_gpu() sizes from the GPU and ignores host RAM; the 15 GB
47
+ flavors (t4-small, a10g-small) get OOMKilled (exit 137) before processing
48
+ anything -- pick >15 GB `ram` from `hf jobs hardware --json`.
49
  cudagraph is off by default here for the same reason.
50
  * xy in the output is the NORMALISED CENTRE, not a corner.
51
  """
 
77
  ("height", pa.int32()),
78
  ("objects", pa.struct([
79
  ("bbox", pa.list_(pa.list_(pa.float32()))), # yolo: cx, cy, w, h normalised
80
+ ("category", pa.list_(pa.int64())), # single class per run; the class NAME
81
+ # is the `query` column — cast to
82
+ # ClassLabel at publish (see docstring)
83
  ("area", pa.list_(pa.float32())),
84
  ("rectangularity", pa.list_(pa.float32())), # triage proxy — no confidence score exists
85
  ])),
falcon-perception.py CHANGED
@@ -65,8 +65,10 @@ MEASURED LIMITS -- not guesses; each one cost a failed run:
65
  * torch.compile is OFF. Per-image dynamic shapes break Inductor
66
  ("ValueError: Exponent must be non-negative" after symbolic-shape recursion).
67
  * CUDA graphs are OFF by default. engine_config_for_gpu() sizes itself from the
68
- GPU and ignores host RAM; on a10g-small the container is OOMKilled (exit 137)
69
- before one image is processed. Use a10g-large, or pass --cudagraph knowingly.
 
 
70
  """
71
 
72
  import argparse
@@ -250,8 +252,9 @@ tags:
250
  {counters["images"]} images, {counters["instances"]} instances. Labels are **zero-shot weak
251
  labels** from [Falcon-Perception](https://huggingface.co/tiiuae/Falcon-Perception) -- no human
252
  annotated anything, and recall against human truth is unmeasured. `objects.bbox` is `yolo`
253
- format (normalised centre x, y, w, h); `objects.rectangularity` (mask area / box area) is the
254
- triage proxy -- the model emits no confidence scores.
 
255
 
256
  ## Reproduction
257
 
@@ -461,13 +464,15 @@ def main():
461
  hub_out = args.out and not args.out.endswith((".json", ".jsonl", ".parquet"))
462
 
463
  if hub_out:
464
- from datasets import Dataset, Features, Image as ImageFeat, Sequence as SeqFeat, Value
465
 
466
  feats = Features({
467
  "image": ImageFeat(), "image_id": Value("int64"), "source_id": Value("string"),
468
  "width": Value("int32"), "height": Value("int32"),
 
 
469
  "objects": {"bbox": SeqFeat(SeqFeat(Value("float32"))),
470
- "category": SeqFeat(Value("int64")),
471
  "area": SeqFeat(Value("float32")),
472
  "rectangularity": SeqFeat(Value("float32"))},
473
  "n_instances": Value("int32"), "masks_rle": Value("string"),
 
65
  * torch.compile is OFF. Per-image dynamic shapes break Inductor
66
  ("ValueError: Exponent must be non-negative" after symbolic-shape recursion).
67
  * CUDA graphs are OFF by default. engine_config_for_gpu() sizes itself from the
68
+ GPU and ignores host RAM; on the 15 GB-host-RAM flavors (t4-small, a10g-small
69
+ -- both measured) the container is OOMKilled (exit 137) before one image is
70
+ processed. Pick a flavor with >15 GB `ram` from `hf jobs hardware --json`,
71
+ or pass --cudagraph knowingly.
72
  """
73
 
74
  import argparse
 
252
  {counters["images"]} images, {counters["instances"]} instances. Labels are **zero-shot weak
253
  labels** from [Falcon-Perception](https://huggingface.co/tiiuae/Falcon-Perception) -- no human
254
  annotated anything, and recall against human truth is unmeasured. `objects.bbox` is `yolo`
255
+ format (normalised centre x, y, w, h); `objects.category` is a `ClassLabel` named `{query}`;
256
+ `objects.rectangularity` (mask area / box area) is the triage proxy -- the model emits no
257
+ confidence scores.
258
 
259
  ## Reproduction
260
 
 
464
  hub_out = args.out and not args.out.endswith((".json", ".jsonl", ".parquet"))
465
 
466
  if hub_out:
467
+ from datasets import ClassLabel, Dataset, Features, Image as ImageFeat, Sequence as SeqFeat, Value
468
 
469
  feats = Features({
470
  "image": ImageFeat(), "image_id": Value("int64"), "source_id": Value("string"),
471
  "width": Value("int32"), "height": Value("int32"),
472
+ # category is a ClassLabel named after the query, so the class name travels
473
+ # with the dataset (viewer, trainers, id2label) instead of a bare 0.
474
  "objects": {"bbox": SeqFeat(SeqFeat(Value("float32"))),
475
+ "category": SeqFeat(ClassLabel(names=[args.query])),
476
  "area": SeqFeat(Value("float32")),
477
  "rectangularity": SeqFeat(Value("float32"))},
478
  "n_instances": Value("int32"), "masks_rle": Value("string"),