khaclinh commited on
Commit
f988b29
1 Parent(s): be93239

Update testdata.py

Browse files
Files changed (1) hide show
  1. testdata.py +21 -46
testdata.py CHANGED
@@ -22,7 +22,10 @@ from typing import List
22
  import re
23
  from collections import defaultdict
24
  import datasets
25
- from PIL import Image
 
 
 
26
 
27
 
28
  _HOMEPAGE = "http://shuoyang1213.me/WIDERFACE/"
@@ -57,29 +60,11 @@ _URLS = {
57
  }
58
 
59
  IMG_EXT = ['png', 'jpeg', 'jpg']
60
- _SUBREDDITS = ["zurich"]
61
-
62
- class TestDataConfig(datasets.BuilderConfig):
63
- """BuilderConfig for TestData."""
64
 
65
- def __init__(self, name, **kwargs):
66
- """BuilderConfig for TestData.
67
- Args:
68
- **kwargs: keyword arguments forwarded to super.
69
- """
70
- super(TestDataConfig, self).__init__(version=datasets.Version("1.0.0", ""), name=name, **kwargs)
71
 
72
  class TestData(datasets.GeneratorBasedBuilder):
73
  """WIDER FACE dataset."""
74
-
75
- BUILDER_CONFIGS = [
76
- TestDataConfig("fisheye"),
77
- ]
78
-
79
- BUILDER_CONFIGS += [TestDataConfig(subreddit) for subreddit in _SUBREDDITS]
80
-
81
- DEFAULT_CONFIG_NAME = "fisheye"
82
-
83
  VERSION = datasets.Version("1.0.0")
84
 
85
  def _info(self):
@@ -88,15 +73,8 @@ class TestData(datasets.GeneratorBasedBuilder):
88
  features=datasets.Features(
89
  {
90
  "image": datasets.Image(),
91
- "objects": datasets.Sequence(
92
- {
93
- "faces": datasets.Sequence(datasets.Sequence(datasets.Value("float32"), length=4)),
94
- "plates": datasets.Sequence(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
  }
102
  ),
@@ -112,32 +90,35 @@ class TestData(datasets.GeneratorBasedBuilder):
112
  datasets.SplitGenerator(
113
  name=datasets.Split.TEST,
114
  gen_kwargs={
115
- "name": self.config.name,
 
 
 
 
 
 
 
 
116
  "data_dir": data_dir["test"],
117
  "annot_dir": data_dir["annot"],
118
  },
119
  ),
120
  ]
121
 
122
- def _generate_examples(self, name, data_dir, annot_dir):
123
-
124
- image_dir = os.path.join(data_dir, name)
125
- annotation_dir = os.path.join(annot_dir, name)
126
  files = []
127
 
128
  idx = 0
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)
143
  with open(gt_path, "r", encoding="utf-8") as f:
@@ -147,7 +128,6 @@ class TestData(datasets.GeneratorBasedBuilder):
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,13 +137,8 @@ class TestData(datasets.GeneratorBasedBuilder):
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
 
 
22
  import re
23
  from collections import defaultdict
24
  import datasets
25
+
26
+ datasets.logging.set_verbosity_info()
27
+
28
+
29
 
30
 
31
  _HOMEPAGE = "http://shuoyang1213.me/WIDERFACE/"
 
60
  }
61
 
62
  IMG_EXT = ['png', 'jpeg', 'jpg']
 
 
 
 
63
 
 
 
 
 
 
 
64
 
65
  class TestData(datasets.GeneratorBasedBuilder):
66
  """WIDER FACE dataset."""
67
+
 
 
 
 
 
 
 
 
68
  VERSION = datasets.Version("1.0.0")
69
 
70
  def _info(self):
 
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
  ),
 
90
  datasets.SplitGenerator(
91
  name=datasets.Split.TEST,
92
  gen_kwargs={
93
+ "split": "fisheye",
94
+ "data_dir": data_dir["test"],
95
+ "annot_dir": data_dir["annot"],
96
+ },
97
+ ),
98
+ datasets.SplitGenerator(
99
+ name=datasets.Split.TRAIN,
100
+ gen_kwargs={
101
+ "split": "normal",
102
  "data_dir": data_dir["test"],
103
  "annot_dir": data_dir["annot"],
104
  },
105
  ),
106
  ]
107
 
108
+ def _generate_examples(self, split, data_dir, annot_dir):
109
+ image_dir = os.path.join(data_dir, "fisheye")
110
+ annotation_dir = os.path.join(annot_dir, "fisheye")
 
111
  files = []
112
 
113
  idx = 0
114
  for i_file in glob(os.path.join(image_dir, "*.png")):
115
  plates = []
116
  faces = []
 
117
 
118
  img_relative_file = os.path.relpath(i_file, image_dir)
119
  gt_relative_path = img_relative_file.replace(".png", ".txt")
120
 
121
  gt_path = os.path.join(annotation_dir, gt_relative_path)
 
 
 
122
 
123
  annotation = defaultdict(list)
124
  with open(gt_path, "r", encoding="utf-8") as f:
 
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
 
 
137
  faces.append([x1, y1, x2, y2])
138
  else:
139
  plates.append([x1, y1, x2, y2])
140
+
141
+ yield idx, {"image": i_file, "faces": faces, "plates": plates}
 
 
 
 
 
142
 
143
  idx += 1
144