File size: 1,446 Bytes
d48696a
b080d28
 
 
 
 
b95e7a1
 
b080d28
 
b95e7a1
 
b080d28
b95e7a1
b080d28
 
 
409e8b0
b95e7a1
 
 
b080d28
 
 
 
 
 
 
 
b95e7a1
 
b080d28
 
1fc4f90
b080d28
 
 
 
 
 
 
 
1fc4f90
b080d28
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
VERSION = "0.0.2"
import os, json
from datasets import (
    GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split,
    Features, Value, Sequence, Image
)

class TLPD(GeneratorBasedBuilder):
    VERSION = "0.0.2"          # ← 只要改了版本,Hub 就會重建

    def _info(self):
        return DatasetInfo(
            description="Taiwan License Plate Dataset",
            features=Features({
                "image":  Image(),
                "label":  Value("string"),
                "points": Sequence(Sequence(Value("float32"))),
            }),
        )

    def _split_generators(self, dl_manager):
        data_dir = dl_manager.manual_dir   # = repo 根目錄
        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 file in sorted(os.listdir(labels_dir)):
            if not file.endswith(".json"):
                continue
            with open(os.path.join(labels_dir, file), "r") as f:
                meta = json.load(f)

            shape = meta["shapes"][0]
            yield file[:-5], {
                "image":  os.path.join(images_dir, meta["imagePath"]),
                "label":  shape["label"],
                "points": shape["points"],
            }