Datasets:
ivelin
commited on
Commit
·
97cff20
1
Parent(s):
ad1211b
chore: checkpoint
Browse filesSigned-off-by: ivelin <ivelin.eth@gmail.com>
- ui_refexp.py +24 -12
ui_refexp.py
CHANGED
|
@@ -21,7 +21,7 @@ import os
|
|
| 21 |
import tensorflow as tf
|
| 22 |
import re
|
| 23 |
import datasets
|
| 24 |
-
|
| 25 |
import numpy as np
|
| 26 |
|
| 27 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
|
@@ -68,7 +68,7 @@ _METADATA_URLS = {
|
|
| 68 |
def tfrecord2list(tfr_file: None):
|
| 69 |
"""Filter and convert refexp tfrecord file to a list of dict object.
|
| 70 |
Each sample in the list is a dict with the following keys: (image_id, prompt, target_bounding_box)"""
|
| 71 |
-
|
| 72 |
count = 0
|
| 73 |
donut_refexp_dict = []
|
| 74 |
for raw_record in raw_tfr_dataset:
|
|
@@ -141,8 +141,8 @@ class UIRefExp(datasets.GeneratorBasedBuilder):
|
|
| 141 |
"screenshot": datasets.Image(),
|
| 142 |
# click the search button next to menu drawer at the top of the screen
|
| 143 |
"prompt": datasets.Value("string"),
|
| 144 |
-
#
|
| 145 |
-
"target_bounding_box":
|
| 146 |
}
|
| 147 |
)
|
| 148 |
|
|
@@ -215,13 +215,25 @@ class UIRefExp(datasets.GeneratorBasedBuilder):
|
|
| 215 |
|
| 216 |
metadata = tfrecord2list(metadata_file)
|
| 217 |
files_to_keep = set()
|
|
|
|
| 218 |
for sample in metadata:
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
for file_path, file_obj in images:
|
| 221 |
-
image_id =
|
| 222 |
-
if image_id
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
import tensorflow as tf
|
| 22 |
import re
|
| 23 |
import datasets
|
| 24 |
+
import json
|
| 25 |
import numpy as np
|
| 26 |
|
| 27 |
# Find for instance the citation on arxiv or on the dataset repo/website
|
|
|
|
| 68 |
def tfrecord2list(tfr_file: None):
|
| 69 |
"""Filter and convert refexp tfrecord file to a list of dict object.
|
| 70 |
Each sample in the list is a dict with the following keys: (image_id, prompt, target_bounding_box)"""
|
| 71 |
+
raw_tfr_dataset = tf.data.TFRecordDataset([tfr_file])
|
| 72 |
count = 0
|
| 73 |
donut_refexp_dict = []
|
| 74 |
for raw_record in raw_tfr_dataset:
|
|
|
|
| 141 |
"screenshot": datasets.Image(),
|
| 142 |
# click the search button next to menu drawer at the top of the screen
|
| 143 |
"prompt": datasets.Value("string"),
|
| 144 |
+
# json: {xmin, ymin, xmax, ymax}, normalized screen reference values between 0 and 1
|
| 145 |
+
"target_bounding_box": datasets.Value("string"),
|
| 146 |
}
|
| 147 |
)
|
| 148 |
|
|
|
|
| 215 |
|
| 216 |
metadata = tfrecord2list(metadata_file)
|
| 217 |
files_to_keep = set()
|
| 218 |
+
image_labels = {}
|
| 219 |
for sample in metadata:
|
| 220 |
+
image_id = sample["image_id"]
|
| 221 |
+
files_to_keep.add(image_id)
|
| 222 |
+
labels = image_labels.get(image_id)
|
| 223 |
+
if isinstance(labels, list):
|
| 224 |
+
labels.append(sample)
|
| 225 |
+
else:
|
| 226 |
+
labels = [sample]
|
| 227 |
+
image_labels[image_id] = labels
|
| 228 |
for file_path, file_obj in images:
|
| 229 |
+
image_id = re.search("(\d+).jpg", file_path)
|
| 230 |
+
if image_id:
|
| 231 |
+
image_id = image_id.group(1)
|
| 232 |
+
if image_id in files_to_keep:
|
| 233 |
+
for labels in image_labels[image_id]:
|
| 234 |
+
bb_json = json.dumps(labels["target_bounding_box"])
|
| 235 |
+
yield file_path, {
|
| 236 |
+
"screenshot": {"path": file_path, "bytes": file_obj.read()},
|
| 237 |
+
"prompt": labels["prompt"],
|
| 238 |
+
"target_bounding_box": bb_json
|
| 239 |
+
}
|