Datasets:
Download dataset.py from aryntmr/coco-val2014-captioning: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/datasets/aryntmr/coco-val2014-captioning/resolve/main/dataset.py
- Command line
-
hf download hf://datasets/aryntmr/coco-val2014-captioning/dataset.py
-
curl -L -o dataset.py https://huggingface.co/datasets/aryntmr/coco-val2014-captioning/resolve/main/dataset.py
1.49 kB
| 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"] | |
| } | |