Datasets:
fix: correct VERSION type and stringify points
Browse files- dataset.py +23 -28
dataset.py
CHANGED
|
@@ -1,48 +1,43 @@
|
|
| 1 |
-
VERSION = "0.0.2"
|
| 2 |
-
import os, json
|
| 3 |
from datasets import (
|
| 4 |
GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split,
|
| 5 |
-
Features, Value, Sequence, Image
|
| 6 |
)
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
class TLPD(GeneratorBasedBuilder):
|
| 11 |
-
VERSION = "0.0.
|
| 12 |
|
| 13 |
def _info(self):
|
| 14 |
return DatasetInfo(
|
| 15 |
-
description="Taiwan License Plate Dataset",
|
| 16 |
features=Features({
|
| 17 |
-
"image":
|
| 18 |
-
"label":
|
| 19 |
-
|
|
|
|
| 20 |
}),
|
| 21 |
)
|
| 22 |
|
| 23 |
def _split_generators(self, dl_manager):
|
| 24 |
-
|
| 25 |
-
return [
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
)
|
| 33 |
-
]
|
| 34 |
|
| 35 |
def _generate_examples(self, images_dir, labels_dir):
|
| 36 |
-
for
|
| 37 |
-
if not
|
| 38 |
continue
|
| 39 |
-
with open(os.path.join(labels_dir,
|
| 40 |
meta = json.load(f)
|
| 41 |
|
| 42 |
-
shape
|
| 43 |
-
yield
|
| 44 |
"image": os.path.join(images_dir, meta["imagePath"]),
|
| 45 |
-
"label": shape["label"],
|
| 46 |
-
"points": shape["points"],
|
| 47 |
}
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 1 |
from datasets import (
|
| 2 |
GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split,
|
| 3 |
+
Features, Value, Sequence, Image, Version # ← 多了 Version
|
| 4 |
)
|
| 5 |
+
import os, json
|
|
|
|
| 6 |
|
| 7 |
class TLPD(GeneratorBasedBuilder):
|
| 8 |
+
VERSION = Version("0.0.3") # ✔ 正確型別
|
| 9 |
|
| 10 |
def _info(self):
|
| 11 |
return DatasetInfo(
|
| 12 |
+
description="Taiwan License Plate Dataset with LabelMe polygon annotations.",
|
| 13 |
features=Features({
|
| 14 |
+
"image": Image(), # 顯示在 Viewer
|
| 15 |
+
"label": Value("string"), # 顯示在 Viewer
|
| 16 |
+
# ↓➜ 轉成字串,Viewer 就能看;模型端再 json.loads() 還原即可
|
| 17 |
+
"points": Value("string"),
|
| 18 |
}),
|
| 19 |
)
|
| 20 |
|
| 21 |
def _split_generators(self, dl_manager):
|
| 22 |
+
root = dl_manager.manual_dir or dl_manager.download_and_extract({})
|
| 23 |
+
return [SplitGenerator(
|
| 24 |
+
name=Split.TRAIN,
|
| 25 |
+
gen_kwargs={
|
| 26 |
+
"images_dir": os.path.join(root, "images"),
|
| 27 |
+
"labels_dir": os.path.join(root, "labels"),
|
| 28 |
+
},
|
| 29 |
+
)]
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def _generate_examples(self, images_dir, labels_dir):
|
| 32 |
+
for fname in sorted(os.listdir(labels_dir)):
|
| 33 |
+
if not fname.endswith(".json"):
|
| 34 |
continue
|
| 35 |
+
with open(os.path.join(labels_dir, fname), "r") as f:
|
| 36 |
meta = json.load(f)
|
| 37 |
|
| 38 |
+
shape = meta["shapes"][0] # 只有一個 polygon
|
| 39 |
+
yield fname[:-5], {
|
| 40 |
"image": os.path.join(images_dir, meta["imagePath"]),
|
| 41 |
+
"label": shape["label"], # "carplate"
|
| 42 |
+
"points": json.dumps(shape["points"]), # <- 字串
|
| 43 |
}
|
|
|