starpig commited on
Commit
e736481
·
1 Parent(s): 6998d54

fix: correct VERSION type and stringify points

Browse files
Files changed (1) hide show
  1. 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
- from pathlib import Path # ← 新增
8
-
9
 
10
  class TLPD(GeneratorBasedBuilder):
11
- VERSION = "0.0.2" # 只要改了版本,Hub 就會重建
12
 
13
  def _info(self):
14
  return DatasetInfo(
15
- description="Taiwan License Plate Dataset",
16
  features=Features({
17
- "image": Image(),
18
- "label": Value("string"),
19
- "points": Sequence(Sequence(Value("float32"))),
 
20
  }),
21
  )
22
 
23
  def _split_generators(self, dl_manager):
24
- data_dir = Path(__file__).resolve().parent # ★ 關鍵:改這行
25
- return [
26
- SplitGenerator(
27
- name=Split.TRAIN,
28
- gen_kwargs={
29
- "images_dir": data_dir / "images",
30
- "labels_dir": data_dir / "labels",
31
- },
32
- )
33
- ]
34
 
35
  def _generate_examples(self, images_dir, labels_dir):
36
- for file in sorted(os.listdir(labels_dir)):
37
- if not file.endswith(".json"):
38
  continue
39
- with open(os.path.join(labels_dir, file), "r") as f:
40
  meta = json.load(f)
41
 
42
- shape = meta["shapes"][0]
43
- yield file[:-5], {
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
  }