File size: 1,650 Bytes
d2b92b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
#!/usr/bin/env python3

from __future__ import annotations

from datasets import load_dataset
from PIL import ImageDraw


REPO_ID = "Yannik019/llm_pack_detection"


def draw_first_item_location(row: dict):
    image = row["image"].copy()
    first_label = row["labels"][0]
    x = row["annotation_x"][0]
    y = row["annotation_y"][0]

    draw = ImageDraw.Draw(image)
    radius = 18
    draw.ellipse((x - radius, y - radius, x + radius, y + radius), outline="red", width=6)
    draw.line((x - 28, y, x + 28, y), fill="red", width=4)
    draw.line((x, y - 28, x, y + 28), fill="red", width=4)
    draw.text((x + 24, y - 32), first_label, fill="red")

    return image, first_label, x, y


def summarize_row(row: dict, index: int) -> None:
    image, first_label, first_x, first_y = draw_first_item_location(row)
    image_size = getattr(image, "size", None)
    labels = ", ".join(row["labels"])

    print(f"Row {index}")
    print(f"  caption: {row['caption']}")
    print(f"  bucket: {row['bucket']}")
    print(f"  sample_id: {row['sample_id']}")
    print(f"  annotation_count: {row['annotation_count']}")
    print(f"  labels: {labels}")
    print(f"  first_item: {first_label} @ ({first_x}, {first_y})")
    print(f"  image_type: {type(image).__name__}")
    print(f"  image_size: {image_size}")
    image.show()


def main() -> int:
    dataset = load_dataset(REPO_ID, split="train")

    print(dataset)
    print(f"Loaded {len(dataset)} rows from {REPO_ID}")

    limit = min(3, len(dataset))
    for index in range(limit):
        summarize_row(dataset[index], index)

    return 0


if __name__ == "__main__":
    raise SystemExit(main())