Update testdata.py
Browse files- testdata.py +31 -36
testdata.py
CHANGED
|
@@ -15,7 +15,7 @@
|
|
| 15 |
"""PP4AV dataset."""
|
| 16 |
|
| 17 |
import os
|
| 18 |
-
|
| 19 |
from tqdm import tqdm
|
| 20 |
from pathlib import Path
|
| 21 |
from typing import List
|
|
@@ -73,9 +73,8 @@ class TestData(datasets.GeneratorBasedBuilder):
|
|
| 73 |
features=datasets.Features(
|
| 74 |
{
|
| 75 |
"image": datasets.Image(),
|
| 76 |
-
#"data": datasets.Sequence(datasets.Value("float32"), length=4),
|
| 77 |
"faces": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=4)),
|
| 78 |
-
"plates": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=4)),
|
| 79 |
}
|
| 80 |
),
|
| 81 |
supervised_keys=None,
|
|
@@ -102,41 +101,37 @@ class TestData(datasets.GeneratorBasedBuilder):
|
|
| 102 |
annotation_dir = os.path.join(annot_dir, "annotations", "fisheye")
|
| 103 |
files = []
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
idx = 0
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
objects.append([1,2,3,4])
|
| 110 |
-
objects.append([5,6,7,8])
|
| 111 |
-
yield idx, {"image": file, "faces": objects, "plates": objects}
|
| 112 |
-
idx += 1
|
| 113 |
-
# for file_type in IMG_EXT:
|
| 114 |
-
# files.extend(list(Path(image_dir).glob(f'**/*.{file_type}')))
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
# assert re.match(r'^\d( [\d\.]+){4,5}$', line), 'Incorrect line: %s' % line
|
| 128 |
-
# cls, cx, cy, w, h = line.split()[:5]
|
| 129 |
-
# cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
|
| 130 |
-
# x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
|
| 131 |
-
# annotation[cls].append([x1, y1, x2, y2])
|
| 132 |
-
# line = f.readline().strip()
|
| 133 |
-
# datasets.logging.INFO(annotation)
|
| 134 |
-
# abcd =acd
|
| 135 |
-
# for cls, bboxes in annotation.items():
|
| 136 |
-
# for x1, y1, x2, y2 in bboxes:
|
| 137 |
-
# if cls == 0:
|
| 138 |
-
# faces.append({"bbox": [x1, y1, x2, y2]})
|
| 139 |
-
# else:
|
| 140 |
-
# plates({"bbox": [x1, y1, x2, y2]})
|
| 141 |
|
|
|
|
|
|
|
| 142 |
|
|
|
|
| 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 |
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 |
supervised_keys=None,
|
|
|
|
| 101 |
annotation_dir = os.path.join(annot_dir, "annotations", "fisheye")
|
| 102 |
files = []
|
| 103 |
|
| 104 |
+
|
| 105 |
+
for file_type in IMG_EXT:
|
| 106 |
+
files.extend(list(Path(image_dir).glob(f'**/*.{file_type}')))
|
| 107 |
+
|
| 108 |
idx = 0
|
| 109 |
+
for image_path in tqdm(files):
|
| 110 |
+
img_relative_path = image_path.relative_to(image_dir)
|
| 111 |
+
gt_pah = (Path(annotation_dir) / img_relative_path).with_suffix('.txt')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
|
| 114 |
+
annotation = defaultdict(list)
|
| 115 |
+
with open(gt_pah, 'r') as f:
|
| 116 |
+
line = f.readline().strip()
|
| 117 |
+
while line:
|
| 118 |
+
assert re.match(r'^\d( [\d\.]+){4,5}$', line), 'Incorrect line: %s' % line
|
| 119 |
+
cls, cx, cy, w, h = line.split()[:5]
|
| 120 |
+
cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
|
| 121 |
+
x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
|
| 122 |
+
annotation[cls].append([x1, y1, x2, y2])
|
| 123 |
+
line = f.readline().strip()
|
| 124 |
+
|
| 125 |
+
faces = []
|
| 126 |
+
plates = []
|
| 127 |
|
| 128 |
+
for cls, bboxes in annotation.items():
|
| 129 |
+
for x1, y1, x2, y2 in bboxes:
|
| 130 |
+
if cls == 0:
|
| 131 |
+
faces.append([x1, y1, x2, y2])
|
| 132 |
+
else:
|
| 133 |
+
plates.append([x1, y1, x2, y2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
yield idx, {"image": str(image_path), "faces": faces, "plates": plates}
|
| 136 |
+
idx += 1
|
| 137 |
|