Mayfull commited on
Commit
adcad33
·
verified ·
1 Parent(s): 2b7877c

Upload coco-karpathy-with-image.py

Browse files
Files changed (1) hide show
  1. coco-karpathy-with-image.py +67 -0
coco-karpathy-with-image.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from datasets import DatasetInfo, GeneratorBasedBuilder, SplitGenerator, Version, Features, Value, Sequence, Image, Split
3
+
4
+ _CITATION = """\
5
+ @inproceedings{lin2014microsoft,
6
+ title={Microsoft coco: Common objects in context},
7
+ 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},
8
+ booktitle={Computer Vision--ECCV 2014: 13th European Conference, Zurich, Switzerland, September 6-12, 2014, Proceedings, Part V 13},
9
+ pages={740--755},
10
+ year={2014},
11
+ organization={Springer}
12
+ }
13
+ """
14
+
15
+ _DESCRIPTION = """\
16
+ Code and datasets for "Microsoft COCO: Common Objects in Context".
17
+ """
18
+
19
+ _HOMEPAGE = "https://huggingface.co/datasets/Mayfull/coco-karpathy-with-image"
20
+ _LICENSE = "Null"
21
+
22
+ class SugarCrepeDataset(GeneratorBasedBuilder):
23
+ VERSION = Version("1.0.0")
24
+
25
+ def _info(self):
26
+ return DatasetInfo(
27
+ description=_DESCRIPTION,
28
+ homepage=_HOMEPAGE,
29
+ license=_LICENSE,
30
+ citation=_CITATION,
31
+ features=Features(
32
+ {
33
+ "images": Image(),
34
+ "sentences": Sequence(Value("string")),
35
+ "cocoid": Value("string"),
36
+ }
37
+ ),
38
+ )
39
+
40
+
41
+ def _split_generators(self, dl_manager):
42
+ urls_to_download = {
43
+ "images": "https://huggingface.co/datasets/Mayfull/coco-karpathy-with-image/resolve/main/images.zip",
44
+ "examples": "https://huggingface.co/datasets/Mayfull/coco-karpathy-with-image/resolve/main/examples.jsonl",
45
+ }
46
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
47
+
48
+ return [
49
+ SplitGenerator(
50
+ name=Split.TEST,
51
+ gen_kwargs={
52
+ "examples_file": downloaded_files["examples"],
53
+ "images_dir": os.path.join(downloaded_files["images"]),
54
+ },
55
+ ),
56
+ ]
57
+
58
+ def _generate_examples(self, examples_file, images_dir):
59
+ with open(examples_file, "r", encoding="utf-8") as f:
60
+ for idx, line in enumerate(f):
61
+ data = eval(line)
62
+ image_path = os.path.join(images_dir, data["filename"])
63
+ yield idx, {
64
+ "images": image_path,
65
+ "sentences": data["sentences"],
66
+ "cocoid": data["cocoid"],
67
+ }