Commit
·
0f7c6fd
1
Parent(s):
bc92237
aggregate captions
Browse files- LocalizedNarratives.py +81 -27
- README.md +3 -1
LocalizedNarratives.py
CHANGED
@@ -60,33 +60,45 @@ _ANNOTATION_URLs = {
|
|
60 |
}
|
61 |
|
62 |
|
63 |
-
_FEATURES =
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
"utterance": datasets.Value("string"),
|
74 |
-
"start_time": datasets.Value("float32"),
|
75 |
-
"end_time": datasets.Value("float32"),
|
76 |
-
}
|
77 |
-
),
|
78 |
-
"traces": datasets.Sequence(
|
79 |
-
datasets.Sequence(
|
80 |
{
|
81 |
-
"
|
82 |
-
"
|
83 |
-
"
|
84 |
}
|
85 |
-
)
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
|
92 |
class LocalizedNarrativesOpenImages(datasets.GeneratorBasedBuilder):
|
@@ -95,7 +107,16 @@ class LocalizedNarrativesOpenImages(datasets.GeneratorBasedBuilder):
|
|
95 |
VERSION = datasets.Version("1.0.0")
|
96 |
|
97 |
BUILDER_CONFIGS = [
|
98 |
-
datasets.BuilderConfig(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
]
|
100 |
|
101 |
DEFAULT_CONFIG_NAME = "OpenImages"
|
@@ -103,7 +124,7 @@ class LocalizedNarrativesOpenImages(datasets.GeneratorBasedBuilder):
|
|
103 |
def _info(self):
|
104 |
return datasets.DatasetInfo(
|
105 |
description=_DESCRIPTION,
|
106 |
-
features=_FEATURES,
|
107 |
homepage=_HOMEPAGE,
|
108 |
license=_LICENSE,
|
109 |
citation=_CITATION,
|
@@ -120,6 +141,12 @@ class LocalizedNarrativesOpenImages(datasets.GeneratorBasedBuilder):
|
|
120 |
]
|
121 |
|
122 |
def _generate_examples(self, annotation_list: str, split: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
counter = 0
|
124 |
for annotation_file in annotation_list:
|
125 |
with open(annotation_file, "r", encoding="utf-8") as fi:
|
@@ -138,3 +165,30 @@ class LocalizedNarrativesOpenImages(datasets.GeneratorBasedBuilder):
|
|
138 |
"voice_recording": annotation["voice_recording"],
|
139 |
}
|
140 |
counter += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
|
62 |
|
63 |
+
_FEATURES = {
|
64 |
+
"OpenImages": datasets.Features(
|
65 |
+
{
|
66 |
+
"image": datasets.Image(),
|
67 |
+
"image_url": datasets.Value("string"),
|
68 |
+
"dataset_id": datasets.Value("string"),
|
69 |
+
"image_id": datasets.Value("string"),
|
70 |
+
"annotator_id": datasets.Value("int32"),
|
71 |
+
"caption": datasets.Value("string"),
|
72 |
+
"timed_caption": datasets.Sequence(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
{
|
74 |
+
"utterance": datasets.Value("string"),
|
75 |
+
"start_time": datasets.Value("float32"),
|
76 |
+
"end_time": datasets.Value("float32"),
|
77 |
}
|
78 |
+
),
|
79 |
+
"traces": datasets.Sequence(
|
80 |
+
datasets.Sequence(
|
81 |
+
{
|
82 |
+
"x": datasets.Value("float32"),
|
83 |
+
"y": datasets.Value("float32"),
|
84 |
+
"t": datasets.Value("float32"),
|
85 |
+
}
|
86 |
+
)
|
87 |
+
),
|
88 |
+
"voice_recording": datasets.Value("string"),
|
89 |
+
}
|
90 |
+
),
|
91 |
+
"OpenImages_captions": datasets.Features(
|
92 |
+
{
|
93 |
+
"image": datasets.Image(),
|
94 |
+
"image_url": datasets.Value("string"),
|
95 |
+
"dataset_id": datasets.Value("string"),
|
96 |
+
"image_id": datasets.Value("string"),
|
97 |
+
"annotator_ids": [datasets.Value("int32")],
|
98 |
+
"captions": [datasets.Value("string")],
|
99 |
+
}
|
100 |
+
),
|
101 |
+
}
|
102 |
|
103 |
|
104 |
class LocalizedNarrativesOpenImages(datasets.GeneratorBasedBuilder):
|
|
|
107 |
VERSION = datasets.Version("1.0.0")
|
108 |
|
109 |
BUILDER_CONFIGS = [
|
110 |
+
datasets.BuilderConfig(
|
111 |
+
name="OpenImages",
|
112 |
+
version=VERSION,
|
113 |
+
description="OpenImages subset of Localized Narratives"
|
114 |
+
),
|
115 |
+
datasets.BuilderConfig(
|
116 |
+
name="OpenImages_captions",
|
117 |
+
version=VERSION,
|
118 |
+
description="OpenImages subset of Localized Narratives where captions are groupped per image (images can have multiple captions). For this subset, `timed_caption`, `traces` and `voice_recording` are not available."
|
119 |
+
),
|
120 |
]
|
121 |
|
122 |
DEFAULT_CONFIG_NAME = "OpenImages"
|
|
|
124 |
def _info(self):
|
125 |
return datasets.DatasetInfo(
|
126 |
description=_DESCRIPTION,
|
127 |
+
features=_FEATURES[self.config.name],
|
128 |
homepage=_HOMEPAGE,
|
129 |
license=_LICENSE,
|
130 |
citation=_CITATION,
|
|
|
141 |
]
|
142 |
|
143 |
def _generate_examples(self, annotation_list: str, split: str):
|
144 |
+
if self.config.name == "OpenImages":
|
145 |
+
return self._generate_examples_original_format(annotation_list, split)
|
146 |
+
elif self.config.name == "OpenImages_captions":
|
147 |
+
return self._generate_examples_aggregated_captions(annotation_list, split)
|
148 |
+
|
149 |
+
def _generate_examples_original_format(self, annotation_list: str, split: str):
|
150 |
counter = 0
|
151 |
for annotation_file in annotation_list:
|
152 |
with open(annotation_file, "r", encoding="utf-8") as fi:
|
|
|
165 |
"voice_recording": annotation["voice_recording"],
|
166 |
}
|
167 |
counter += 1
|
168 |
+
|
169 |
+
def _generate_examples_aggregated_captions(self, annotation_list: str, split: str):
|
170 |
+
result = {}
|
171 |
+
for annotation_file in annotation_list:
|
172 |
+
with open(annotation_file, "r", encoding="utf-8") as fi:
|
173 |
+
for line in fi:
|
174 |
+
annotation = json.loads(line)
|
175 |
+
image_url = f"https://s3.amazonaws.com/open-images-dataset/{split}/{annotation['image_id']}.jpg"
|
176 |
+
image_id = annotation["image_id"]
|
177 |
+
if image_id in result:
|
178 |
+
assert result[image_id]["dataset_id"] == annotation["dataset_id"]
|
179 |
+
assert result[image_id]["image_id"] == annotation["image_id"]
|
180 |
+
result[image_id]["annotator_ids"].append(annotation["annotator_id"])
|
181 |
+
result[image_id]["captions"].append(annotation["caption"])
|
182 |
+
else:
|
183 |
+
result[image_id] = {
|
184 |
+
"image": image_url,
|
185 |
+
"image_url": image_url,
|
186 |
+
"dataset_id": annotation["dataset_id"],
|
187 |
+
"image_id": image_id,
|
188 |
+
"annotator_ids": [annotation["annotator_id"]],
|
189 |
+
"captions": [annotation["caption"]],
|
190 |
+
}
|
191 |
+
counter = 0
|
192 |
+
for r in result.values():
|
193 |
+
yield counter, r
|
194 |
+
counter += 1
|
README.md
CHANGED
@@ -45,7 +45,9 @@ Since the voice and the mouse pointer are synchronized, we can localize every si
|
|
45 |
This dense visual grounding takes the form of a mouse trace segment per word and is unique to our data.
|
46 |
We annotated 849k images with Localized Narratives: the whole COCO, Flickr30k, and ADE20K datasets, and 671k images of Open Images, all of which we make publicly available.
|
47 |
|
48 |
-
As of now, there is only the OpenImages subset, but feel free to contribute the other subset of Localized Narratives!
|
|
|
|
|
49 |
|
50 |
### Supported Tasks and Leaderboards
|
51 |
|
|
|
45 |
This dense visual grounding takes the form of a mouse trace segment per word and is unique to our data.
|
46 |
We annotated 849k images with Localized Narratives: the whole COCO, Flickr30k, and ADE20K datasets, and 671k images of Open Images, all of which we make publicly available.
|
47 |
|
48 |
+
As of now, there is only the `OpenImages` subset, but feel free to contribute the other subset of Localized Narratives!
|
49 |
+
|
50 |
+
`OpenImages_captions` is similar to the `OpenImages` subset. The differences are that captions are groupped per image (images can have multiple captions). For this subset, `timed_caption`, `traces` and `voice_recording` are not available.
|
51 |
|
52 |
### Supported Tasks and Leaderboards
|
53 |
|