File size: 1,872 Bytes
a2feaaf
b95e7a1
1fc4f90
b95e7a1
 
 
 
 
1fc4f90
b95e7a1
409e8b0
 
 
 
b95e7a1
 
 
409e8b0
b95e7a1
 
 
1fc4f90
409e8b0
 
1fc4f90
b95e7a1
 
 
 
 
1fc4f90
 
409e8b0
1fc4f90
 
 
409e8b0
 
1fc4f90
409e8b0
 
 
 
 
 
 
 
 
 
 
1fc4f90
 
 
 
 
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
#ya
import os
import json
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Features, Value, Sequence, Image

class TLPD(GeneratorBasedBuilder):
    def _info(self):
        return DatasetInfo(
            description="Taiwan License Plate Dataset with LabelMe polygon annotations.",
            features=Features({
                "image": Image(),  # auto-decodes to PIL.Image
                "label": Value("string"),  # e.g., 'carplate'
                "points": Sequence(Sequence(Value("float32")))  # list of [x, y] coords
            }),
        )

    def _split_generators(self, dl_manager):
        data_dir = dl_manager.manual_dir
        return [
            SplitGenerator(
                name=Split.TRAIN,
                gen_kwargs={
                    "images_dir": os.path.join(data_dir, "images"),
                    "labels_dir": os.path.join(data_dir, "labels")
                }
            )
        ]

    def _generate_examples(self, images_dir, labels_dir):
        for fname in sorted(os.listdir(labels_dir)):
            if not fname.endswith(".json"):
                continue

            label_path = os.path.join(labels_dir, fname)
            with open(label_path, "r") as f:
                data = json.load(f)

            image_filename = data.get("imagePath")
            image_path = os.path.join(images_dir, image_filename)

            shapes = data.get("shapes", [])
            if not shapes:
                continue  # skip if no annotation

            label = shapes[0].get("label", "unknown")
            points = shapes[0].get("points", [])

            key = os.path.splitext(fname)[0]
            
            print("Yielding:", key, label, points)
            yield key, {
                "image": image_path,
                "label": label,
                "points": points
            }