File size: 1,491 Bytes
5cc52b5
 
 
 
 
2dbfc6f
 
5cc52b5
 
 
2dbfc6f
5cc52b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7d27d48
5cc52b5
 
 
7d27d48
 
 
 
 
 
 
 
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
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"]
                }