TLPD / dataset.py
starpig's picture
add dataset loader
b080d28
raw
history blame
1.45 kB
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"],
}