OliseNS commited on
Commit
c4fb7d4
·
1 Parent(s): e13fe63

Add README previews from sample dataset and preview generator script

Browse files

Replace placeholder asset paths with five PNGs built from sample/images and
sample/labels: each composite stitches three frames edge-to-edge with YOLO
boxes and class names. Add scripts/make_readme_preview.py and preview_manifest
for reproducibility. Ignore .venv for local Pillow/PyYAML installs.

Made-with: Cursor

.gitignore CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  # Logs and local upload state (optional to ignore in git).
2
  zip_bigsplit.log
3
  hf_push.log
 
1
+ # Local virtualenv for scripts (e.g. `scripts/make_readme_preview.py`).
2
+ .venv/
3
+
4
  # Logs and local upload state (optional to ignore in git).
5
  zip_bigsplit.log
6
  hf_push.log
README.md CHANGED
@@ -61,26 +61,25 @@ When the full dataset is present, `bigsplit/data.yaml` uses the same `path` / `t
61
 
62
  ## Preview (bounding boxes)
63
 
64
- Five sample images are chosen for dense labels and class variety, drawn with **boxes and class names on the boxes only** (no panel captions). They are stitched **edge-to-edge** at equal height **no white padding** between frames.
65
-
66
- ![Dataset preview — five annotated frames stitched](assets/README_preview.png)
67
-
68
- ### Individual panels (same annotations, stable paths)
69
 
70
  <p align="center">
71
- <img src="assets/preview_panels/panel_01.png" width="19%" alt="Panel 1" />
72
- <img src="assets/preview_panels/panel_02.png" width="19%" alt="Panel 2" />
73
- <img src="assets/preview_panels/panel_03.png" width="19%" alt="Panel 3" />
74
- <img src="assets/preview_panels/panel_04.png" width="19%" alt="Panel 4" />
75
- <img src="assets/preview_panels/panel_05.png" width="19%" alt="Panel 5" />
 
 
76
  </p>
77
 
78
- [panel_01.png](assets/preview_panels/panel_01.png) · [panel_02.png](assets/preview_panels/panel_02.png) · [panel_03.png](assets/preview_panels/panel_03.png) · [panel_04.png](assets/preview_panels/panel_04.png) · [panel_05.png](assets/preview_panels/panel_05.png) · [manifest.txt](assets/preview_panels/manifest.txt) (source stems per panel)
79
 
80
  Regenerate after changing `sample/`:
81
 
82
  ```bash
83
- uv pip install pillow matplotlib pyyaml --python .venv/bin/python # once
 
84
  .venv/bin/python scripts/make_readme_preview.py
85
  ```
86
 
 
61
 
62
  ## Preview (bounding boxes)
63
 
64
+ Five PNGs are generated from the checked-in **`sample/`** images and YOLO labels. Each file stitches **three** frames **edge-to-edge** at equal height (**no padding** between panels). Boxes and class names are drawn from the corresponding `sample/labels/*.txt` files.
 
 
 
 
65
 
66
  <p align="center">
67
+ <img src="assets/preview_01.png" width="32%" alt="Sample preview 1 — three stitched frames" />
68
+ <img src="assets/preview_02.png" width="32%" alt="Sample preview 2 — three stitched frames" />
69
+ <img src="assets/preview_03.png" width="32%" alt="Sample preview 3 — three stitched frames" />
70
+ </p>
71
+ <p align="center">
72
+ <img src="assets/preview_04.png" width="32%" alt="Sample preview 4 — three stitched frames" />
73
+ <img src="assets/preview_05.png" width="32%" alt="Sample preview 5 — three stitched frames" />
74
  </p>
75
 
76
+ [preview_01.png](assets/preview_01.png) · [preview_02.png](assets/preview_02.png) · [preview_03.png](assets/preview_03.png) · [preview_04.png](assets/preview_04.png) · [preview_05.png](assets/preview_05.png) · [preview_manifest.txt](assets/preview_manifest.txt) (source filenames per composite)
77
 
78
  Regenerate after changing `sample/`:
79
 
80
  ```bash
81
+ python3 -m venv .venv # once
82
+ .venv/bin/pip install pillow pyyaml
83
  .venv/bin/python scripts/make_readme_preview.py
84
  ```
85
 
assets/preview_01.png ADDED

Git LFS Details

  • SHA256: 5662084a4b2645ab1e20dfd98d54ada2ad5b2026eb7d98bfd436f616a745744c
  • Pointer size: 132 Bytes
  • Size of remote file: 1.55 MB
assets/preview_02.png ADDED

Git LFS Details

  • SHA256: 5f16b114163b5558a76bbc692b43a1dfab28598302ca8c95a9486e5b201cbbda
  • Pointer size: 132 Bytes
  • Size of remote file: 1.35 MB
assets/preview_03.png ADDED

Git LFS Details

  • SHA256: 1d80aefb3369abb6b0cfc2b1fb6b64bc88766ae1ac18b4b3cf572041f03eb258
  • Pointer size: 131 Bytes
  • Size of remote file: 981 kB
assets/preview_04.png ADDED

Git LFS Details

  • SHA256: 99087770e20b0c11b7ecfb37c62a069e11933a5f2d5797a2f646fdfa3faf309b
  • Pointer size: 132 Bytes
  • Size of remote file: 1.23 MB
assets/preview_05.png ADDED

Git LFS Details

  • SHA256: f6e54cc50fd1c2eebd9c960dba49120566b19fb071ab09fbfe32741b355721ec
  • Pointer size: 131 Bytes
  • Size of remote file: 802 kB
assets/preview_manifest.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ preview_01.png: train_images_design_1380_2_jpg.rf.a085cfddcac9b3bf7f05885498364bff.jpg + 000000546983_copy2.jpg + wider_2136.jpg
2
+ preview_02.png: 000000053900.jpg + 000000356330_copy1.jpg + wider_2880.jpg
3
+ preview_03.png: damagedfoodpackagingbox51_jpeg.rf.ca5fa9969495ada8fbb1922aba118445_fb8d6882.jpg + 00e9054afa5b4121.jpg + 4dfac268-175Packageeee_jpg.rf.1e33a72a2942f428c84e6c7ae40557d0_b498a222.jpg
4
+ preview_04.png: 000000160974.jpg + N0915A42ABEX_jpg.rf.0cde92af55966ae6ac742b28930c98b3_bf12b7a7.jpg + 000000379246.jpg
5
+ preview_05.png: 000000439141_copy1.jpg + 000032_jpg.rf.75f30b98ee2798bf1357eadb7e563345_af985b55.jpg + 000000302026.jpg
scripts/make_readme_preview.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Build README preview assets: five PNGs, each stitching three `sample/` images
4
+ edge-to-edge at equal height with YOLO boxes and class names.
5
+
6
+ Run from repo root:
7
+ .venv/bin/python scripts/make_readme_preview.py
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from pathlib import Path
13
+
14
+ import yaml
15
+ from PIL import Image, ImageDraw, ImageFont
16
+
17
+ REPO_ROOT = Path(__file__).resolve().parents[1]
18
+ SAMPLE = REPO_ROOT / "sample"
19
+ IMAGES_DIR = SAMPLE / "images"
20
+ LABELS_DIR = SAMPLE / "labels"
21
+ DATA_YAML = SAMPLE / "data.yaml"
22
+ ASSETS_DIR = REPO_ROOT / "assets"
23
+
24
+ PANEL_HEIGHT = 480
25
+ NUM_STRIPS = 5
26
+ PANELS_PER_STRIP = 3
27
+
28
+ # Distinct colors per class index (BGR-ish order tuned for visibility on photos)
29
+ CLASS_COLORS = [
30
+ (255, 99, 71),
31
+ (50, 205, 50),
32
+ (30, 144, 255),
33
+ (255, 215, 0),
34
+ (238, 130, 238),
35
+ (255, 140, 0),
36
+ (0, 206, 209),
37
+ (255, 20, 147),
38
+ (173, 255, 47),
39
+ ]
40
+
41
+
42
+ def load_class_names() -> list[str]:
43
+ data = yaml.safe_load(DATA_YAML.read_text())
44
+ return list(data["names"])
45
+
46
+
47
+ def parse_yolo_labels(label_path: Path) -> list[tuple[int, float, float, float, float]]:
48
+ out: list[tuple[int, float, float, float, float]] = []
49
+ if not label_path.is_file():
50
+ return out
51
+ for line in label_path.read_text().splitlines():
52
+ line = line.strip()
53
+ if not line:
54
+ continue
55
+ parts = line.split()
56
+ if len(parts) < 5:
57
+ continue
58
+ c = int(parts[0])
59
+ xc, yc, w, h = map(float, parts[1:5])
60
+ out.append((c, xc, yc, w, h))
61
+ return out
62
+
63
+
64
+ def score_stem(stem: str) -> tuple[float, int, int]:
65
+ """Higher is better: prefer class variety and moderate box counts."""
66
+ labels = parse_yolo_labels(LABELS_DIR / f"{stem}.txt")
67
+ if not labels:
68
+ return (-1.0, 0, 0)
69
+ classes = {b[0] for b in labels}
70
+ n = len(labels)
71
+ uc = len(classes)
72
+ penalty = max(0, n - 25) * 3
73
+ score = uc * 50 + min(n, 20) - penalty
74
+ return (score, uc, n)
75
+
76
+
77
+ def find_image_path(stem: str) -> Path | None:
78
+ for ext in (".jpg", ".jpeg", ".png", ".webp"):
79
+ p = IMAGES_DIR / f"{stem}{ext}"
80
+ if p.is_file():
81
+ return p
82
+ return None
83
+
84
+
85
+ def font_or_default(size: int) -> ImageFont.FreeTypeFont | ImageFont.ImageFont:
86
+ for path in (
87
+ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
88
+ "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
89
+ ):
90
+ fp = Path(path)
91
+ if fp.is_file():
92
+ return ImageFont.truetype(str(fp), size=size)
93
+ return ImageFont.load_default()
94
+
95
+
96
+ def draw_panel(img_path: Path, label_path: Path, names: list[str]) -> Image.Image:
97
+ img = Image.open(img_path).convert("RGB")
98
+ w0, h0 = img.size
99
+ labels = parse_yolo_labels(label_path)
100
+ draw = ImageDraw.Draw(img)
101
+ font = font_or_default(13)
102
+
103
+ for cls_id, xc, yc, bw, bh in labels:
104
+ if cls_id < 0 or cls_id >= len(names):
105
+ continue
106
+ x1 = (xc - bw / 2) * w0
107
+ y1 = (yc - bh / 2) * h0
108
+ x2 = (xc + bw / 2) * w0
109
+ y2 = (yc + bh / 2) * h0
110
+ color = CLASS_COLORS[cls_id % len(CLASS_COLORS)]
111
+ draw.rectangle([x1, y1, x2, y2], outline=color, width=2)
112
+ name = names[cls_id]
113
+ ty = max(0, y1 - 14)
114
+ draw.text(
115
+ (x1 + 1, ty),
116
+ name,
117
+ fill=color,
118
+ font=font,
119
+ stroke_width=1,
120
+ stroke_fill=(0, 0, 0),
121
+ )
122
+
123
+ # Resize to panel height
124
+ scale = PANEL_HEIGHT / h0
125
+ new_w = max(1, int(round(w0 * scale)))
126
+ return img.resize((new_w, PANEL_HEIGHT), Image.Resampling.LANCZOS)
127
+
128
+
129
+ def stitch_horizontal(panels: list[Image.Image]) -> Image.Image:
130
+ total_w = sum(p.size[0] for p in panels)
131
+ h = panels[0].size[1]
132
+ out = Image.new("RGB", (total_w, h))
133
+ x = 0
134
+ for p in panels:
135
+ out.paste(p, (x, 0))
136
+ x += p.size[0]
137
+ return out
138
+
139
+
140
+ def select_stems() -> list[str]:
141
+ stems: list[str] = []
142
+ for p in LABELS_DIR.glob("*.txt"):
143
+ stems.append(p.stem)
144
+
145
+ scored: list[tuple[float, int, int, str]] = []
146
+ for stem in stems:
147
+ sc, uc, n = score_stem(stem)
148
+ if sc < 0:
149
+ continue
150
+ if find_image_path(stem) is None:
151
+ continue
152
+ scored.append((sc, uc, n, stem))
153
+
154
+ scored.sort(key=lambda t: (t[0], t[1], t[2]), reverse=True)
155
+
156
+ # Spread selection across the ranked list so strips are not identical.
157
+ need = NUM_STRIPS * PANELS_PER_STRIP
158
+ picked: list[str] = []
159
+ n_ranked = len(scored)
160
+ if n_ranked == 0:
161
+ raise SystemExit("No labeled images found under sample/.")
162
+
163
+ step = max(1, n_ranked // need)
164
+ i = 0
165
+ for _ in range(need):
166
+ _, _, _, stem = scored[i % n_ranked]
167
+ picked.append(stem)
168
+ i += step
169
+
170
+ # Deduplicate while preserving order; back-fill from top scores
171
+ seen: set[str] = set()
172
+ unique: list[str] = []
173
+ for s in picked:
174
+ if s not in seen:
175
+ seen.add(s)
176
+ unique.append(s)
177
+
178
+ for _, _, _, stem in scored:
179
+ if len(unique) >= need:
180
+ break
181
+ if stem not in seen:
182
+ seen.add(stem)
183
+ unique.append(stem)
184
+
185
+ if len(unique) < need:
186
+ raise SystemExit(f"Need {need} distinct images; only found {len(unique)}.")
187
+
188
+ return unique[:need]
189
+
190
+
191
+ def main() -> None:
192
+ names = load_class_names()
193
+ stems = select_stems()
194
+ ASSETS_DIR.mkdir(parents=True, exist_ok=True)
195
+
196
+ manifest_lines: list[str] = []
197
+
198
+ for strip_idx in range(NUM_STRIPS):
199
+ chunk = stems[strip_idx * PANELS_PER_STRIP : (strip_idx + 1) * PANELS_PER_STRIP]
200
+ panels: list[Image.Image] = []
201
+ for stem in chunk:
202
+ img_p = find_image_path(stem)
203
+ assert img_p is not None
204
+ lbl_p = LABELS_DIR / f"{stem}.txt"
205
+ panels.append(draw_panel(img_p, lbl_p, names))
206
+
207
+ strip = stitch_horizontal(panels)
208
+ out_path = ASSETS_DIR / f"preview_{strip_idx + 1:02d}.png"
209
+ strip.save(out_path, optimize=True)
210
+ parts = []
211
+ for s in chunk:
212
+ ip = find_image_path(s)
213
+ assert ip is not None
214
+ parts.append(ip.name)
215
+ manifest_lines.append(f"{out_path.name}: {' + '.join(parts)}")
216
+
217
+ (ASSETS_DIR / "preview_manifest.txt").write_text("\n".join(manifest_lines) + "\n")
218
+ print(f"Wrote {NUM_STRIPS} previews to {ASSETS_DIR}/")
219
+
220
+
221
+ if __name__ == "__main__":
222
+ main()