File size: 1,794 Bytes
14d9f17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Shared helpers for ViViD-5k artifact generation scripts."""
from pathlib import Path

# Consistent style for all dataset-card figures (works on HF light + dark themes).
STYLE = {
    "accent": "#6366F1",
    "secondary": "#94A3B8",
    "text": "#334155",
    "grid": "#E2E8F0",
    "dpi": 150,
    "figsize": (8, 4.5),
}

SPLIT_FILES = {"train": "train.txt", "val": "val.txt", "test": "test.txt"}


def parse_bbox(raw):
    """Return (x, y, w, h). COCO bboxes here are flat [x,y,w,h] or nested [[x,y,w,h]]."""
    if isinstance(raw, (list, tuple)) and len(raw) == 1 and isinstance(raw[0], (list, tuple)):
        raw = raw[0]
    if not (isinstance(raw, (list, tuple)) and len(raw) == 4):
        raise ValueError(f"Unrecognized bbox format: {raw!r}")
    return tuple(float(v) for v in raw)


def load_splits(data_dir):
    """Map file_name -> split. Raises if a file appears in more than one split."""
    data_dir = Path(data_dir)
    splits = {}
    for split, fname in SPLIT_FILES.items():
        for line in (data_dir / fname).read_text().splitlines():
            name = line.strip()
            if not name:
                continue
            if name in splits:
                raise ValueError(f"{name} appears in both {splits[name]} and {split}")
            splits[name] = split
    return splits


def apply_style(ax):
    """Apply the shared figure style to a matplotlib Axes."""
    s = STYLE
    ax.spines[["top", "right"]].set_visible(False)
    for spine in ("left", "bottom"):
        ax.spines[spine].set_color(s["text"])
    ax.tick_params(colors=s["text"], labelsize=9)
    ax.yaxis.grid(True, color=s["grid"], linewidth=0.8)
    ax.set_axisbelow(True)
    ax.xaxis.label.set_color(s["text"])
    ax.yaxis.label.set_color(s["text"])
    ax.title.set_color(s["text"])