Datasets:
Please enter the commit message for your changes. Lines starting
Browse fileswith '#' will be ignored, and an empty message aborts the commit.
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
modified: dataset.py
- dataset.py +22 -10
dataset.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Features, Value, Sequence, Image
|
|
@@ -7,19 +8,20 @@ class TLPD(GeneratorBasedBuilder):
|
|
| 7 |
return DatasetInfo(
|
| 8 |
description="Taiwan License Plate Dataset with LabelMe polygon annotations.",
|
| 9 |
features=Features({
|
| 10 |
-
"image": Image(), #
|
| 11 |
-
"label": Value("string"), #
|
| 12 |
-
"points": Sequence(Sequence(Value("float32"))) # [
|
| 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(
|
| 22 |
-
"labels_dir": os.path.join(
|
| 23 |
}
|
| 24 |
)
|
| 25 |
]
|
|
@@ -28,14 +30,24 @@ class TLPD(GeneratorBasedBuilder):
|
|
| 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 |
-
|
|
|
|
| 35 |
image_path = os.path.join(images_dir, image_filename)
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
yield key, {
|
| 40 |
"image": image_path,
|
| 41 |
"label": label,
|
|
|
|
| 1 |
+
|
| 2 |
import os
|
| 3 |
import json
|
| 4 |
from datasets import GeneratorBasedBuilder, DatasetInfo, SplitGenerator, Split, Features, Value, Sequence, Image
|
|
|
|
| 8 |
return DatasetInfo(
|
| 9 |
description="Taiwan License Plate Dataset with LabelMe polygon annotations.",
|
| 10 |
features=Features({
|
| 11 |
+
"image": Image(), # auto-decodes to PIL.Image
|
| 12 |
+
"label": Value("string"), # e.g., 'carplate'
|
| 13 |
+
"points": Sequence(Sequence(Value("float32"))) # list of [x, y] coords
|
| 14 |
+
}),
|
| 15 |
)
|
| 16 |
|
| 17 |
def _split_generators(self, dl_manager):
|
| 18 |
+
data_dir = dl_manager.manual_dir
|
| 19 |
return [
|
| 20 |
SplitGenerator(
|
| 21 |
name=Split.TRAIN,
|
| 22 |
gen_kwargs={
|
| 23 |
+
"images_dir": os.path.join(data_dir, "images"),
|
| 24 |
+
"labels_dir": os.path.join(data_dir, "labels")
|
| 25 |
}
|
| 26 |
)
|
| 27 |
]
|
|
|
|
| 30 |
for fname in sorted(os.listdir(labels_dir)):
|
| 31 |
if not fname.endswith(".json"):
|
| 32 |
continue
|
| 33 |
+
|
| 34 |
label_path = os.path.join(labels_dir, fname)
|
| 35 |
with open(label_path, "r") as f:
|
| 36 |
data = json.load(f)
|
| 37 |
+
|
| 38 |
+
image_filename = data.get("imagePath")
|
| 39 |
image_path = os.path.join(images_dir, image_filename)
|
| 40 |
+
|
| 41 |
+
shapes = data.get("shapes", [])
|
| 42 |
+
if not shapes:
|
| 43 |
+
continue # skip if no annotation
|
| 44 |
+
|
| 45 |
+
label = shapes[0].get("label", "unknown")
|
| 46 |
+
points = shapes[0].get("points", [])
|
| 47 |
+
|
| 48 |
+
key = os.path.splitext(fname)[0]
|
| 49 |
+
|
| 50 |
+
print("Yielding:", key, label, points)
|
| 51 |
yield key, {
|
| 52 |
"image": image_path,
|
| 53 |
"label": label,
|