aryntmr's picture
Upload dataset.py with huggingface_hub
7d27d48 verified
import json
import datasets
class CocoBaseEval(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
DESCRIPTION = "COCO 2014 validation set subset (1000 images) with captions and object annotations"
def _info(self):
return datasets.DatasetInfo(
description=self.DESCRIPTION,
features=datasets.Features({
"image_id": datasets.Value("int32"),
"image": datasets.Image(),
"input_prompt": datasets.Value("string"),
"gt_objects": datasets.Sequence(datasets.Value("string")),
"gt_captions": datasets.Sequence(datasets.Value("string"))
})
)
def _split_generators(self, dl_manager):
return [
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"data_file": "data.jsonl"}
)
]
def _generate_examples(self, data_file):
import json
with open(data_file, "r") as f:
for idx, line in enumerate(f):
item = json.loads(line)
# Make sure we yield the full item with all fields
yield idx, {
"image_id": item["image_id"],
"image": item["image"],
"input_prompt": item["input_prompt"],
"gt_objects": item["gt_objects"],
"gt_captions": item["gt_captions"]
}