khaclinh commited on
Commit
e101d71
·
1 Parent(s): d1ce9c9

Update testdata.py

Browse files
Files changed (1) hide show
  1. testdata.py +40 -45
testdata.py CHANGED
@@ -15,7 +15,7 @@
15
  """PP4AV dataset."""
16
 
17
  import os
18
- import glob as glob
19
  from tqdm import tqdm
20
  from pathlib import Path
21
  from typing import List
@@ -73,16 +73,12 @@ class TestData(datasets.GeneratorBasedBuilder):
73
  features=datasets.Features(
74
  {
75
  "image": datasets.Image(),
76
- "faces": datasets.Sequence(
 
77
  {
78
- "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
79
  }
80
  ),
81
- "plates": datasets.Sequence(
82
- {
83
- "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
84
- }
85
- ),
86
  }
87
  ),
88
  supervised_keys=None,
@@ -109,45 +105,44 @@ class TestData(datasets.GeneratorBasedBuilder):
109
  annotation_dir = os.path.join(annot_dir, "annotations", "fisheye")
110
  files = []
111
 
112
-
113
- for file_type in IMG_EXT:
114
- files.extend(list(Path(image_dir).glob(f'**/*.{file_type}')))
115
-
116
  idx = 0
117
- for image_path in tqdm(files):
118
- img_relative_path = image_path.relative_to(image_dir)
119
- gt_pah = (Path(annotation_dir) / img_relative_path).with_suffix('.txt')
 
 
 
 
 
 
 
 
 
120
 
121
-
122
- annotation = defaultdict(list)
123
- with open(gt_pah, 'r') as f:
124
- line = f.readline().strip()
125
- while line:
126
- assert re.match(r'^\d( [\d\.]+){4,5}$', line), 'Incorrect line: %s' % line
127
- cls, cx, cy, w, h = line.split()[:5]
128
- cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
129
- x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
130
- annotation[cls].append([x1, y1, x2, y2])
131
- line = f.readline().strip()
132
-
133
- faces = []
134
- plates = []
135
 
136
- for cls, bboxes in annotation.items():
137
- for x1, y1, x2, y2 in bboxes:
138
- if cls == 0:
139
- faces.append(
140
- {
141
- "bbox": [x1, y1, x2, y2]
142
- }
143
- )
144
- else:
145
- plates.append(
146
- {
147
- "bbox": [x1, y1, x2, y2]
148
- }
149
- )
 
 
 
 
 
 
150
 
151
- yield idx, {"image": str(image_path), "faces": faces, "plates": plates}
152
- idx += 1
153
 
 
15
  """PP4AV dataset."""
16
 
17
  import os
18
+ from glob import glob
19
  from tqdm import tqdm
20
  from pathlib import Path
21
  from typing import List
 
73
  features=datasets.Features(
74
  {
75
  "image": datasets.Image(),
76
+ #"data": datasets.Sequence(datasets.Value("float32"), length=4),
77
+ "data": datasets.Sequence(
78
  {
79
+ "faces": datasets.Sequence(datasets.Value("float32"), length=4),
80
  }
81
  ),
 
 
 
 
 
82
  }
83
  ),
84
  supervised_keys=None,
 
105
  annotation_dir = os.path.join(annot_dir, "annotations", "fisheye")
106
  files = []
107
 
 
 
 
 
108
  idx = 0
109
+ #datasets.logging.info(image_dir)
110
+ for file in glob(os.path.join(image_dir, "*.png")):
111
+ objects = []
112
+ objects.append(
113
+ {
114
+ "faces": [1, 2, 3, 4]
115
+ }
116
+ )
117
+ yield idx, {"image": file, "data": objects}
118
+ idx += 1
119
+ # for file_type in IMG_EXT:
120
+ # files.extend(list(Path(image_dir).glob(f'**/*.{file_type}')))
121
 
122
+ # idx = 0
123
+ # for image_path in tqdm(files):
124
+ # img_relative_path = image_path.relative_to(image_dir)
125
+ #gt_pah = (Path(annotation_dir) / img_relative_path).with_suffix('.txt')
 
 
 
 
 
 
 
 
 
 
126
 
127
+ #annotation = parse_annotation(gt_pah)
128
+
129
+ # annotation = defaultdict(list)
130
+ # with open(gt_pah, 'r') as f:
131
+ # line = f.readline().strip()
132
+ # while line:
133
+ # assert re.match(r'^\d( [\d\.]+){4,5}$', line), 'Incorrect line: %s' % line
134
+ # cls, cx, cy, w, h = line.split()[:5]
135
+ # cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
136
+ # x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
137
+ # annotation[cls].append([x1, y1, x2, y2])
138
+ # line = f.readline().strip()
139
+ # datasets.logging.INFO(annotation)
140
+ # abcd =acd
141
+ # for cls, bboxes in annotation.items():
142
+ # for x1, y1, x2, y2 in bboxes:
143
+ # if cls == 0:
144
+ # faces.append({"bbox": [x1, y1, x2, y2]})
145
+ # else:
146
+ # plates({"bbox": [x1, y1, x2, y2]})
147
 
 
 
148