khaclinh commited on
Commit
dcf131f
·
1 Parent(s): 5ec2f93

Update testdata.py

Browse files
Files changed (1) hide show
  1. testdata.py +14 -28
testdata.py CHANGED
@@ -109,14 +109,6 @@ class TestData(datasets.GeneratorBasedBuilder):
109
  def _split_generators(self, dl_manager):
110
  data_dir = dl_manager.download_and_extract(_URLS)
111
  return [
112
- datasets.SplitGenerator(
113
- name=datasets.Split.TRAIN,
114
- gen_kwargs={
115
- "split": "train",
116
- "data_dir": data_dir["test"],
117
- "annot_dir": data_dir["annot"],
118
- },
119
- ),
120
  datasets.SplitGenerator(
121
  name=datasets.Split.TEST,
122
  gen_kwargs={
@@ -125,14 +117,6 @@ class TestData(datasets.GeneratorBasedBuilder):
125
  "annot_dir": data_dir["annot"],
126
  },
127
  ),
128
- datasets.SplitGenerator(
129
- name=datasets.Split.VALIDATION,
130
- gen_kwargs={
131
- "split": "val",
132
- "data_dir": data_dir["test"],
133
- "annot_dir": data_dir["annot"],
134
- },
135
- ),
136
  ]
137
 
138
  def _generate_examples(self, split, data_dir, annot_dir):
@@ -141,7 +125,6 @@ class TestData(datasets.GeneratorBasedBuilder):
141
  files = []
142
  faces = []
143
  plates = []
144
- logger.info(image_dir)
145
  for file_type in IMG_EXT:
146
  files.extend(list(Path(image_dir).glob(f'**/*.{file_type}')))
147
 
@@ -149,21 +132,24 @@ class TestData(datasets.GeneratorBasedBuilder):
149
  img_relative_path = image_path.relative_to(image_dir)
150
  gt_pah = (Path(annotation_dir) / img_relative_path).with_suffix('.txt')
151
 
152
- annotation = parse_annotation(gt_pah)
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  for cls, bboxes in annotation.items():
155
  for x1, y1, x2, y2 in bboxes:
156
  if cls == 0:
157
- faces.append(
158
- {
159
- "bbox": [x1, y1, x2, y2]
160
- }
161
- )
162
  else:
163
- plates(
164
- {
165
- "bbox": [x1, y1, x2, y2]
166
- }
167
- )
168
 
169
  yield idx, {"image": image_path, "faces": faces, "plates": plates}
 
109
  def _split_generators(self, dl_manager):
110
  data_dir = dl_manager.download_and_extract(_URLS)
111
  return [
 
 
 
 
 
 
 
 
112
  datasets.SplitGenerator(
113
  name=datasets.Split.TEST,
114
  gen_kwargs={
 
117
  "annot_dir": data_dir["annot"],
118
  },
119
  ),
 
 
 
 
 
 
 
 
120
  ]
121
 
122
  def _generate_examples(self, split, data_dir, annot_dir):
 
125
  files = []
126
  faces = []
127
  plates = []
 
128
  for file_type in IMG_EXT:
129
  files.extend(list(Path(image_dir).glob(f'**/*.{file_type}')))
130
 
 
132
  img_relative_path = image_path.relative_to(image_dir)
133
  gt_pah = (Path(annotation_dir) / img_relative_path).with_suffix('.txt')
134
 
135
+ #annotation = parse_annotation(gt_pah)
136
+
137
+ annotation = defaultdict(list)
138
+ with open(gt_pah, 'r') as f:
139
+ line = f.readline().strip()
140
+ while line:
141
+ assert re.match(r'^\d( [\d\.]+){4,5}$', line), 'Incorrect line: %s' % line
142
+ cls, cx, cy, w, h = line.split()[:5]
143
+ cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
144
+ x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
145
+ annotation[cls].append([x1, y1, x2, y2])
146
+ line = f.readline().strip()
147
 
148
  for cls, bboxes in annotation.items():
149
  for x1, y1, x2, y2 in bboxes:
150
  if cls == 0:
151
+ faces.append({"bbox": [x1, y1, x2, y2]})
 
 
 
 
152
  else:
153
+ plates({"bbox": [x1, y1, x2, y2]})
 
 
 
 
154
 
155
  yield idx, {"image": image_path, "faces": faces, "plates": plates}