Update testdata.py
Browse files- testdata.py +19 -8
testdata.py
CHANGED
|
@@ -88,8 +88,14 @@ class TestData(datasets.GeneratorBasedBuilder):
|
|
| 88 |
features=datasets.Features(
|
| 89 |
{
|
| 90 |
"image": datasets.Image(),
|
| 91 |
-
"
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
# "size": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=2)),
|
| 94 |
|
| 95 |
}
|
|
@@ -123,14 +129,14 @@ class TestData(datasets.GeneratorBasedBuilder):
|
|
| 123 |
for i_file in glob(os.path.join(image_dir, "*.png")):
|
| 124 |
plates = []
|
| 125 |
faces = []
|
| 126 |
-
|
| 127 |
|
| 128 |
img_relative_file = os.path.relpath(i_file, image_dir)
|
| 129 |
gt_relative_path = img_relative_file.replace(".png", ".txt")
|
| 130 |
|
| 131 |
gt_path = os.path.join(annotation_dir, gt_relative_path)
|
| 132 |
-
img = Image.open( i_file )
|
| 133 |
-
img_h, img_w = img.size
|
| 134 |
# sizes.append([img_h, img_w])
|
| 135 |
|
| 136 |
annotation = defaultdict(list)
|
|
@@ -141,7 +147,7 @@ class TestData(datasets.GeneratorBasedBuilder):
|
|
| 141 |
cls, cx, cy, w, h = line.split()[:5]
|
| 142 |
cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
|
| 143 |
x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
|
| 144 |
-
x1, y1, x2, y2 = round(x1 * img_w), round(y1 * img_h), round(x2 * img_w), round(y2 * img_h)
|
| 145 |
annotation[cls].append([x1, y1, x2, y2])
|
| 146 |
line = f.readline().strip()
|
| 147 |
|
|
@@ -151,8 +157,13 @@ class TestData(datasets.GeneratorBasedBuilder):
|
|
| 151 |
faces.append([x1, y1, x2, y2])
|
| 152 |
else:
|
| 153 |
plates.append([x1, y1, x2, y2])
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
idx += 1
|
| 158 |
|
|
|
|
| 88 |
features=datasets.Features(
|
| 89 |
{
|
| 90 |
"image": datasets.Image(),
|
| 91 |
+
"objects": datasets.Sequence(
|
| 92 |
+
{
|
| 93 |
+
"faces": datasets.Sequence(datasets.Value("float32"), length=4),
|
| 94 |
+
"plates": datasets.Sequence(datasets.Value("float32"), length=4),
|
| 95 |
+
}
|
| 96 |
+
),
|
| 97 |
+
#"faces": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=4)),
|
| 98 |
+
# "plates": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=4)),
|
| 99 |
# "size": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=2)),
|
| 100 |
|
| 101 |
}
|
|
|
|
| 129 |
for i_file in glob(os.path.join(image_dir, "*.png")):
|
| 130 |
plates = []
|
| 131 |
faces = []
|
| 132 |
+
objects = []
|
| 133 |
|
| 134 |
img_relative_file = os.path.relpath(i_file, image_dir)
|
| 135 |
gt_relative_path = img_relative_file.replace(".png", ".txt")
|
| 136 |
|
| 137 |
gt_path = os.path.join(annotation_dir, gt_relative_path)
|
| 138 |
+
# img = Image.open( i_file )
|
| 139 |
+
# img_h, img_w = img.size
|
| 140 |
# sizes.append([img_h, img_w])
|
| 141 |
|
| 142 |
annotation = defaultdict(list)
|
|
|
|
| 147 |
cls, cx, cy, w, h = line.split()[:5]
|
| 148 |
cls, cx, cy, w, h = int(cls), float(cx), float(cy), float(w), float(h)
|
| 149 |
x1, y1, x2, y2 = cx - w / 2, cy - h / 2, cx + w / 2, cy + h / 2
|
| 150 |
+
# x1, y1, x2, y2 = round(x1 * img_w), round(y1 * img_h), round(x2 * img_w), round(y2 * img_h)
|
| 151 |
annotation[cls].append([x1, y1, x2, y2])
|
| 152 |
line = f.readline().strip()
|
| 153 |
|
|
|
|
| 157 |
faces.append([x1, y1, x2, y2])
|
| 158 |
else:
|
| 159 |
plates.append([x1, y1, x2, y2])
|
| 160 |
+
objects.append(
|
| 161 |
+
{
|
| 162 |
+
"faces": faces,
|
| 163 |
+
"plates": plates
|
| 164 |
+
}
|
| 165 |
+
)
|
| 166 |
+
yield idx, {"image": i_file, "objects": objects}
|
| 167 |
|
| 168 |
idx += 1
|
| 169 |
|