Update ImageRewardDB.py
Browse files- ImageRewardDB.py +86 -30
ImageRewardDB.py
CHANGED
@@ -110,23 +110,40 @@ class ImageRewardDB(datasets.GeneratorBasedBuilder):
|
|
110 |
BUILDER_CONFIGS.append(
|
111 |
ImageRewardDBConfig(name=f"{num_k}k", part_ids=part_ids, description=f"This is a {num_k}k-scale ImageRewardDB")
|
112 |
)
|
|
|
|
|
|
|
113 |
|
114 |
DEFAULT_CONFIG_NAME = "8k" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
115 |
|
116 |
def _info(self):
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
return datasets.DatasetInfo(
|
131 |
# This is the description that will appear on the datasets page.
|
132 |
description=_DESCRIPTION,
|
@@ -199,21 +216,60 @@ class ImageRewardDB(datasets.GeneratorBasedBuilder):
|
|
199 |
assert num_data_dirs == len(json_paths)
|
200 |
|
201 |
#Iterate throug all extracted zip folders for images
|
|
|
202 |
for index, json_path in enumerate(json_paths):
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
BUILDER_CONFIGS.append(
|
111 |
ImageRewardDBConfig(name=f"{num_k}k", part_ids=part_ids, description=f"This is a {num_k}k-scale ImageRewardDB")
|
112 |
)
|
113 |
+
BUILDER_CONFIGS.append(
|
114 |
+
ImageRewardDBConfig(name=f"{num_k}k_group", part_ids=part_ids, description=f"This is a {num_k}k-scale group of ImageRewardDB")
|
115 |
+
)
|
116 |
|
117 |
DEFAULT_CONFIG_NAME = "8k" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
118 |
|
119 |
def _info(self):
|
120 |
+
if "group" in self.config.name:
|
121 |
+
features = datasets.Features(
|
122 |
+
{
|
123 |
+
"prompt_id": datasets.Value("string"),
|
124 |
+
"prompt": datasets.Value("string"),
|
125 |
+
"classification": datasets.Value("string"),
|
126 |
+
"image": datasets.Sequence(datasets.Image()),
|
127 |
+
"rank": datasets.Sequence(datasets.Value("int8")),
|
128 |
+
"overall_rating": datasets.Sequence(datasets.Value("int8")),
|
129 |
+
"image_text_alignment_rating": datasets.Sequence(datasets.Value("int8")),
|
130 |
+
"fidelity_rating": datasets.Sequence(datasets.Value("int8"))
|
131 |
+
}
|
132 |
+
)
|
133 |
+
else:
|
134 |
+
features = datasets.Features(
|
135 |
+
{
|
136 |
+
"image": datasets.Image(),
|
137 |
+
"prompt_id": datasets.Value("string"),
|
138 |
+
"prompt": datasets.Value("string"),
|
139 |
+
"classification": datasets.Value("string"),
|
140 |
+
"image_amount_in_total": datasets.Value("int8"),
|
141 |
+
"rank": datasets.Value("int8"),
|
142 |
+
"overall_rating": datasets.Value("int8"),
|
143 |
+
"image_text_alignment_rating": datasets.Value("int8"),
|
144 |
+
"fidelity_rating": datasets.Value("int8")
|
145 |
+
}
|
146 |
+
)
|
147 |
return datasets.DatasetInfo(
|
148 |
# This is the description that will appear on the datasets page.
|
149 |
description=_DESCRIPTION,
|
|
|
216 |
assert num_data_dirs == len(json_paths)
|
217 |
|
218 |
#Iterate throug all extracted zip folders for images
|
219 |
+
metadata_table = pd.read_parquet(metadata_path)
|
220 |
for index, json_path in enumerate(json_paths):
|
221 |
+
json_data = json.load(open(json_path, "r", encoding="utf-8"))
|
222 |
+
if "group" in self.config.name:
|
223 |
+
group_num = 0
|
224 |
+
image_path = []
|
225 |
+
rank = []
|
226 |
+
overall_rating, image_text_alignment_rating, fidelity_rating = [], [], []
|
227 |
+
for sample in json_data:
|
228 |
+
if group_num == 0:
|
229 |
+
image_path.clear()
|
230 |
+
rank.clear()
|
231 |
+
overall_rating.clear()
|
232 |
+
image_text_alignment_rating.clear()
|
233 |
+
fidelity_rating.clear()
|
234 |
+
prompt_id = sample["prompt_id"]
|
235 |
+
prompt = sample["prompt"]
|
236 |
+
classification = sample["classification"]
|
237 |
+
image_amount_in_total = sample["image_amount_in_total"]
|
238 |
+
image_path.append(sample["image_path"])
|
239 |
+
rank.append(sample["rank"])
|
240 |
+
overall_rating.append(sample["overall_rating"])
|
241 |
+
image_text_alignment_rating.append(sample["image_text_alignment_rating"])
|
242 |
+
fidelity_rating.append(sample["fidelity_rating"])
|
243 |
+
group_num += 1
|
244 |
+
if group_num == image_amount_in_total:
|
245 |
+
group_num = 0
|
246 |
+
yield prompt_id, ({
|
247 |
+
"prompt_id": prompt_id,
|
248 |
+
"prompt": prompt,
|
249 |
+
"classification": classification,
|
250 |
+
"image": [{
|
251 |
+
"path": image_path[idx],
|
252 |
+
"bytes": open(image_path[idx], "rb").read()
|
253 |
+
} for idx in range(image_amount_in_total)],
|
254 |
+
"rank": rank,
|
255 |
+
"overall_rating": overall_rating,
|
256 |
+
"image_text_alignment_rating": image_text_alignment_rating,
|
257 |
+
"fidelity_rating": fidelity_rating,
|
258 |
+
})
|
259 |
+
else:
|
260 |
+
for example in json_data:
|
261 |
+
image_path = os.path.join(data_dirs[index], str(example["image_path"]).split("/")[-1])
|
262 |
+
yield example["image_path"], {
|
263 |
+
"image": {
|
264 |
+
"path": image_path,
|
265 |
+
"bytes": open(image_path, "rb").read()
|
266 |
+
},
|
267 |
+
"prompt_id": example["prompt_id"],
|
268 |
+
"prompt": example["prompt"],
|
269 |
+
"classification": example["classification"],
|
270 |
+
"image_amount_in_total": example["image_amount_in_total"],
|
271 |
+
"rank": example["rank"],
|
272 |
+
"overall_rating": example["overall_rating"],
|
273 |
+
"image_text_alignment_rating": example["image_text_alignment_rating"],
|
274 |
+
"fidelity_rating": example["fidelity_rating"]
|
275 |
+
}
|