File size: 2,445 Bytes
adcad33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bc857f9
adcad33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Version, Features, Value, Sequence, Image, Split

_CITATION = """\
@inproceedings{lin2014microsoft,
  title={Microsoft coco: Common objects in context},
  author={Lin, Tsung-Yi and Maire, Michael and Belongie, Serge and Hays, James and Perona, Pietro and Ramanan, Deva and Doll{\'a}r, Piotr and Zitnick, C Lawrence},
  booktitle={Computer Vision--ECCV 2014: 13th European Conference, Zurich, Switzerland, September 6-12, 2014, Proceedings, Part V 13},
  pages={740--755},
  year={2014},
  organization={Springer}
}
"""

_DESCRIPTION = """\
Code and datasets for "Microsoft COCO: Common Objects in Context".
"""

_HOMEPAGE = "https://huggingface.co/datasets/Mayfull/coco-karpathy-with-image"
_LICENSE = "Null"

class SugarCrepeDataset(GeneratorBasedBuilder):
    VERSION = Version("1.0.0")

    def _info(self):
        return DatasetInfo(
            description=_DESCRIPTION,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
            features=Features(
                {
                    "images": Image(),
                    "sentences": Sequence(Value("string")),
                    "cocoid": Value("string"),
                }
            ),
        )


    def _split_generators(self, dl_manager):
        urls_to_download = {
            "images": "https://huggingface.co/datasets/Mayfull/coco-karpathy-with-image/resolve/main/images.zip",
            "examples": "https://huggingface.co/datasets/Mayfull/coco-karpathy-with-image/resolve/main/examples.jsonl",
        }
        downloaded_files = dl_manager.download_and_extract(urls_to_download)

        return [
            SplitGenerator(
                name=Split.TRAIN,
                gen_kwargs={
                    "examples_file": downloaded_files["examples"],
                    "images_dir": os.path.join(downloaded_files["images"]),
                },
            ),
        ]

    def _generate_examples(self, examples_file, images_dir):
        with open(examples_file, "r", encoding="utf-8") as f:
            for idx, line in enumerate(f):
                data = eval(line)
                image_path = os.path.join(images_dir, data["filename"])
                yield idx, {
                    "images": image_path,
                    "sentences": data["sentences"],
                    "cocoid": data["cocoid"],
                }