Datasets:
Languages:
English
Size:
1K<n<10K
ArXiv:
Tags:
iiw
imageinwords
image-descriptions
image-captions
detailed-descriptions
hyper-detailed-descriptions
License:
File size: 7,309 Bytes
aadeaaf f0d9e03 aadeaaf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
import datasets
import json
import pandas as pd
import string
_DESCRIPTION = """
"""
_HOMEPAGE = "https://google.github.io/imageinwords/"
_LICENSE = "CC BY 4.0"
_DATASET_GITHUB_URLS = {
"IIW-400": "https://raw.githubusercontent.com/google/imageinwords/main/datasets/IIW-400/data.jsonl?token=GHSAT0AAAAAACRUNGOPNCHWPCGAD2WZVJSMZRUTPNA",
"DCI_Test": "https://raw.githubusercontent.com/google/imageinwords/main/datasets/DCI_Test/data.jsonl?token=GHSAT0AAAAAACRUNGOP36K62I4YLDKVTR3EZRUTO4A",
"DOCCI_Test": "https://raw.githubusercontent.com/google/imageinwords/main/datasets/DOCCI_Test/data.jsonl?token=GHSAT0AAAAAACRUNGOOVNBFPVZ7LX37AEICZRUTPEA",
"CM_3600": "https://raw.githubusercontent.com/google/imageinwords/main/datasets/CM_3600/data.jsonl?token=GHSAT0AAAAAACRUNGOOB3FKTWWUU2WAUWPAZRUTOPQ",
"LocNar_Eval": "https://raw.githubusercontent.com/google/imageinwords/main/datasets/LocNar_Eval/data.jsonl?token=GHSAT0AAAAAACRUNGOPXK6GMPSO6X6KVU3WZRUTPVA",
}
_DATASET_FEATURES = {
"IIW-400": datasets.Features({
"image/key": datasets.Value('string'),
"image/thumbnail_url": datasets.Value('string'),
"IIW": datasets.Value('string'),
"IIW-P5B": datasets.Value('string'),
"iiw-human-sxs-gpt4v": {
"metrics/Comprehensiveness": datasets.Value('string'),
"metrics/Specificity": datasets.Value('string'),
"metrics/Hallucination": datasets.Value('string'),
"metrics/First few line(s) as tldr": datasets.Value('string'),
"metrics/Human Like": datasets.Value('string'),
},
"iiw-human-sxs-iiw-p5b": {
"metrics/Comprehensiveness": datasets.Value('string'),
"metrics/Specificity": datasets.Value('string'),
"metrics/Hallucination": datasets.Value('string'),
"metrics/First few line(s) as tldr": datasets.Value('string'),
"metrics/Human Like": datasets.Value('string'),
},
}),
"DCI_Test": datasets.Features({
"image": datasets.Value('string'),
"ex_id": datasets.Value('string'),
"IIW": datasets.Value('string'),
"metrics/Comprehensiveness": datasets.Value('string'),
"metrics/Specificity": datasets.Value('string'),
"metrics/Hallucination": datasets.Value('string'),
"metrics/First few line(s) as tldr": datasets.Value('string'),
"metrics/Human Like": datasets.Value('string'),
}),
"DOCCI_Test": datasets.Features({
"image": datasets.Value('string'),
"image/thumbnail_url": datasets.Value('string'),
"IIW": datasets.Value('string'),
"DOCCI": datasets.Value('string'),
"metrics/Comprehensiveness": datasets.Value('string'),
"metrics/Specificity": datasets.Value('string'),
"metrics/Hallucination": datasets.Value('string'),
"metrics/First few line(s) as tldr": datasets.Value('string'),
"metrics/Human Like": datasets.Value('string'),
}),
"CM_3600": datasets.Features({
"image/key": datasets.Value('string'),
"image/url": datasets.Value('string'),
"IIW-P5B": datasets.Value('string'),
}),
"LocNar_Eval": datasets.Features({
"image/key": datasets.Value('string'),
"IIW-P5B": datasets.Value('string'),
}),
}
_CM_3600_URL_PATTERN = string.Template("https://open-images-dataset.s3.amazonaws.com/crossmodal-3600/$IMAGE_KEY.jpg")
_DOCCI_AAR_THUMBNAIL_URL_PATTERN = string.Template("https://storage.googleapis.com/docci/thumbnails/$IMAGE_KEY.jpg")
class ImageInWords(datasets.GeneratorBasedBuilder):
"""ImageInWords dataset"""
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="IIW-400", version=VERSION, description="IIW-400"),
datasets.BuilderConfig(name="DCI_Test", version=VERSION, description="DCI_Test"),
datasets.BuilderConfig(name="DOCCI_Test", version=VERSION, description="DOCCI_Test"),
datasets.BuilderConfig(name="CM_3600", version=VERSION, description="CM_3600"),
datasets.BuilderConfig(name="LocNar_Eval", version=VERSION, description="LocNar_Eval"),
]
DEFAULT_CONFIG_NAME = "IIW-400"
def _info(self):
return datasets.DatasetInfo(
features=_DATASET_FEATURES[self.config.name],
homepage=_HOMEPAGE,
description=_DESCRIPTION,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
hf_auth_token = dl_manager.download_config.use_auth_token
if hf_auth_token is None:
raise ConnectionError(
"Please set use_auth_token=True or use_auth_token='<TOKEN>' to download this dataset"
)
downloaded_file = dl_manager.download_and_extract(_DATASET_GITHUB_URLS[self.config.name])
if self.config.name == "LocNar_Eval":
split_type = datasets.Split.VALIDATION
else:
split_type = datasets.Split.TEST
return [
datasets.SplitGenerator(name=split_type, gen_kwargs={"filepath": downloaded_file}),
]
def _generate_examples(self, filepath):
match self.config.name:
case "IIW-400":
return self._generate_examples_iiw_400(filepath)
case "DCI_Test":
return self._generate_examples_dci_test(filepath)
case "DOCCI_Test":
return self._generate_examples_docci_test(filepath)
case "CM_3600":
return self._generate_examples_cm_3600(filepath)
case "LocNar_Eval":
return self._generate_examples_locnar_eval(filepath)
def _generate_examples_iiw_400(filepath):
with open(filepath) as fp:
for json_line in fp:
json_obj = json.loads(json_line.strip())
json_obj["image/thumbnail_url"] = _DOCCI_AAR_THUMBNAIL_URL_PATTERN.substitute(IMAGE_KEY=json_obj["image/key"])
yield json_obj["image/key"], json_obj
def _generate_examples_dci_test(filepath):
with open(filepath) as fp:
for json_line in fp:
json_obj = json.loads(json_line.strip())
yield json_obj["image"], json_obj
def _generate_examples_docci_test(filepath):
with open(filepath) as fp:
for json_line in fp:
json_obj = json.loads(json_line.strip())
json_obj["image/thumbnail_url"] = _DOCCI_AAR_THUMBNAIL_URL_PATTERN.substitute(IMAGE_KEY=json_obj["image"])
yield json_obj["image"], json_obj
def _generate_examples_cm_3600(filepath):
with open(filepath) as fp:
for json_line in fp:
json_obj = json.loads(json_line.strip())
json_obj["image/url"] = _CM_3600_URL_PATTERN.substitute(IMAGE_KEY=json_obj["image/key"])
del json_obj["image/source"]
yield json_obj["image/key"], json_obj
def _generate_examples_locnar_eval(filepath):
with open(filepath) as fp:
for json_line in fp:
json_obj = json.loads(json_line.strip())
del json_obj["image/source"]
yield json_obj["image/key"], json_obj |