Datasets:
update dataset.py
Browse files- dataset.py +25 -21
dataset.py
CHANGED
|
@@ -1,39 +1,43 @@
|
|
| 1 |
-
.# dataset.py
|
| 2 |
-
import json
|
| 3 |
import os
|
|
|
|
| 4 |
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Features, Value, Sequence, Image
|
| 5 |
|
| 6 |
class TLPD(GeneratorBasedBuilder):
|
| 7 |
def _info(self):
|
| 8 |
return DatasetInfo(
|
|
|
|
| 9 |
features=Features({
|
| 10 |
-
"image": Image(),
|
| 11 |
-
"label": Value("string"),
|
| 12 |
-
"points": Sequence(Sequence(Value("float32")))
|
| 13 |
-
})
|
| 14 |
-
description="TLPD: Taiwan License Plate Dataset with polygon labels from LabelMe.",
|
| 15 |
)
|
| 16 |
|
| 17 |
def _split_generators(self, dl_manager):
|
| 18 |
return [
|
| 19 |
SplitGenerator(
|
| 20 |
name=Split.TRAIN,
|
| 21 |
-
gen_kwargs={
|
|
|
|
|
|
|
|
|
|
| 22 |
)
|
| 23 |
]
|
| 24 |
|
| 25 |
def _generate_examples(self, images_dir, labels_dir):
|
| 26 |
for fname in sorted(os.listdir(labels_dir)):
|
| 27 |
-
if fname.endswith(".json"):
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import json
|
| 3 |
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Features, Value, Sequence, Image
|
| 4 |
|
| 5 |
class TLPD(GeneratorBasedBuilder):
|
| 6 |
def _info(self):
|
| 7 |
return DatasetInfo(
|
| 8 |
+
description="Taiwan License Plate Dataset with LabelMe polygon annotations.",
|
| 9 |
features=Features({
|
| 10 |
+
"image": Image(), # will auto-decode as PIL.Image
|
| 11 |
+
"label": Value("string"), # "carplate"
|
| 12 |
+
"points": Sequence(Sequence(Value("float32"))) # [[x1,y1], [x2,y2], ...]
|
| 13 |
+
})
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
def _split_generators(self, dl_manager):
|
| 17 |
return [
|
| 18 |
SplitGenerator(
|
| 19 |
name=Split.TRAIN,
|
| 20 |
+
gen_kwargs={
|
| 21 |
+
"images_dir": os.path.join(dl_manager.manual_dir, "images"),
|
| 22 |
+
"labels_dir": os.path.join(dl_manager.manual_dir, "labels")
|
| 23 |
+
}
|
| 24 |
)
|
| 25 |
]
|
| 26 |
|
| 27 |
def _generate_examples(self, images_dir, labels_dir):
|
| 28 |
for fname in sorted(os.listdir(labels_dir)):
|
| 29 |
+
if not fname.endswith(".json"):
|
| 30 |
+
continue
|
| 31 |
+
label_path = os.path.join(labels_dir, fname)
|
| 32 |
+
with open(label_path, "r") as f:
|
| 33 |
+
data = json.load(f)
|
| 34 |
+
image_filename = data["imagePath"]
|
| 35 |
+
image_path = os.path.join(images_dir, image_filename)
|
| 36 |
+
label = data["shapes"][0]["label"]
|
| 37 |
+
points = data["shapes"][0]["points"]
|
| 38 |
+
key = fname.replace(".json", "")
|
| 39 |
+
yield key, {
|
| 40 |
+
"image": image_path,
|
| 41 |
+
"label": label,
|
| 42 |
+
"points": points
|
| 43 |
+
}
|