khaclinh commited on
Commit
354003c
1 Parent(s): ee47538

Update testdata.py

Browse files
Files changed (1) hide show
  1. testdata.py +25 -4
testdata.py CHANGED
@@ -73,8 +73,8 @@ class TestData(datasets.GeneratorBasedBuilder):
73
  features=datasets.Features(
74
  {
75
  "image": datasets.Image(),
76
- "path": datasets.Value("string"),
77
- "gt_path": datasets.Value("string"),
78
 
79
  }
80
  ),
@@ -99,17 +99,38 @@ class TestData(datasets.GeneratorBasedBuilder):
99
 
100
  def _generate_examples(self, split, data_dir, annot_dir):
101
  image_dir = os.path.join(data_dir, "fisheye")
102
- annotation_dir = os.path.join(annot_dir, "annotations", "fisheye")
103
  files = []
104
 
105
  idx = 0
106
  for i_file in glob(os.path.join(image_dir, "*.png")):
 
 
 
107
  img_relative_file = os.path.relpath(i_file, image_dir)
108
  gt_relative_path = img_relative_file.replace(".png", ".txt")
109
 
110
  gt_path = os.path.join(annotation_dir, gt_relative_path)
111
 
112
- yield idx, {"image": i_file, "path": i_file, "gt_path": gt_path}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  idx += 1
115
 
 
73
  features=datasets.Features(
74
  {
75
  "image": datasets.Image(),
76
+ "faces": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=4)),
77
+ "plates": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=4)),
78
 
79
  }
80
  ),
 
99
 
100
  def _generate_examples(self, split, data_dir, annot_dir):
101
  image_dir = os.path.join(data_dir, "fisheye")
102
+ annotation_dir = os.path.join(annot_dir, "fisheye")
103
  files = []
104
 
105
  idx = 0
106
  for i_file in glob(os.path.join(image_dir, "*.png")):
107
+ plates = []
108
+ faces = []
109
+
110
  img_relative_file = os.path.relpath(i_file, image_dir)
111
  gt_relative_path = img_relative_file.replace(".png", ".txt")
112
 
113
  gt_path = os.path.join(annotation_dir, gt_relative_path)
114
 
115
+ annotation = defaultdict(list)
116
+ with open(gt_file, "r", encoding="utf-8") as f:
117
+ line = f.readline().strip()
118
+ while line:
119
+ assert re.match(r"^\d( [\d\.]+){4,5}$", line), "Incorrect line: %s" % line
120
+ cls, cx, cy, w, h = line.split()[:5]
121
+ cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
122
+ x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
123
+ annotation[cls].append([x1, y1, x2, y2])
124
+ line = f.readline().strip()
125
+
126
+ for cls, bboxes in annotation.items():
127
+ for x1, y1, x2, y2 in bboxes:
128
+ if cls == 0:
129
+ faces.append([x1, y1, x2, y2])
130
+ else:
131
+ plates([x1, y1, x2, y2])
132
+
133
+ yield idx, {"image": i_file, "faces": faces, "plates": plates}
134
 
135
  idx += 1
136