akashsalmuthe commited on
Commit
d64b271
·
verified ·
1 Parent(s): e2f7f85

Update images-demo.py

Browse files
Files changed (1) hide show
  1. images-demo.py +25 -57
images-demo.py CHANGED
@@ -1,90 +1,58 @@
1
- import json
2
-
3
  import datasets
4
- from datasets.tasks import QuestionAnsweringExtractive
5
-
6
-
7
- logger = datasets.logging.get_logger(__name__)
8
-
9
 
10
  _CITATION = """\
11
- @article{2016arXiv160605250R,
12
- author = {{Rajpurkar}, Pranav and {Zhang}, Jian and {Lopyrev},
13
- Konstantin and {Liang}, Percy},
14
- title = "{SQuAD: 100,000+ Questions for Machine Comprehension of Text}"
15
  }
16
  """
17
 
18
  _DESCRIPTION = """\
19
- Demo...
20
  """
 
21
 
22
- # _URL = "https://github.com/jamescalam/hf-datasets/raw/main/01_builder_script/dataset.tar.gz"
23
- _URL = "https://huggingface.co/datasets/akashsalmuthe/image-demo/resolve/main/images.tar.gz?download=true"
24
 
25
- descriptions = ["aerial shot of futuristic city with large motorway",
26
- "aerial shot of modern city at sunrise",
27
- "butterfly landing on the nose of a cat",
28
- "cute kitten walking through long grass",
29
- "fluffy dog sticking out tongue with yellow background",
30
- "futuristic city with led lit tower blocks",
31
- "futuristic wet city street after rain with red and blue lights",
32
- "ginger striped cat with long whiskers laid on wooden table",
33
- "happy dog walking through park area holding ball ",
34
- "happy ginger dog sticking out its tongue sat in front of dirt path",
35
- "happy small fluffy white dog running across grass",
36
- "kitten raising paw to sky with cyan background",
37
- "modern city skyline at sunrise with pink to blue sky",
38
- "modern neon lit city alleyway",
39
- "new york city street view with yellow cabs",
40
- "puppy with big ears sat with orange background ",
41
- "suburban area with city skyline in distance",
42
- "three young dogs on dirt road",
43
- "top down shot of black and white cat with yellow background",
44
- "two dogs playing in the snow",
45
- "two dogs running on dirt path"
46
- ]
47
 
 
 
48
 
49
-
50
- class ImagesDemo(datasets.GeneratorBasedBuilder):
51
- """Dataset creation"""
52
  def _info(self):
53
  return datasets.DatasetInfo(
54
  description=_DESCRIPTION,
55
  features=datasets.Features(
56
  {
57
- "text": datasets.Value("string"),
58
- "image": datasets.Value()
59
  }
60
  ),
61
- # No default supervised_keys (as we have to pass both question
62
- # and context as input).
63
  supervised_keys=None,
64
- homepage="https://github.com/jamescalam/hf-datasets/",
65
  citation=_CITATION,
66
  )
67
 
68
  def _split_generators(self, dl_manager):
69
- path = dl_manager.download(_URL)
70
- image_iters = dl_manager.iter_archive(path)
71
  return [
72
  datasets.SplitGenerator(
73
  name=datasets.Split.TRAIN,
74
  gen_kwargs={
75
  "images": image_iters
76
- }
77
  ),
78
  ]
79
 
80
  def _generate_examples(self, images):
81
- """This function returns the examples in the raw (text) form."""
82
- idx = 0
83
-
84
- for filepath, image in images:
85
- yield idx, {
86
- "image":{"path":filepath, "bytes":image.read()},
87
- "text":descriptions[idx]
88
- }
89
-
90
- idx += 1
 
 
 
1
  import datasets
 
 
 
 
 
2
 
3
  _CITATION = """\
4
+ @InProceedings{huggingface:dataset,
5
+ title = {Small image-text set},
6
+ author={James Briggs},
7
+ year={2022}
8
  }
9
  """
10
 
11
  _DESCRIPTION = """\
12
+ Demo dataset for testing or showing image-text capabilities.
13
  """
14
+ _HOMEPAGE = "https://huggingface.co/datasets/jamescalam/image-text-demo"
15
 
16
+ _LICENSE = ""
 
17
 
18
+ _REPO = "https://huggingface.co/datasets/jamescalam/image-text-demo"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
+ class ImageSet(datasets.GeneratorBasedBuilder):
21
+ """Small sample of image-text pairs"""
22
 
 
 
 
23
  def _info(self):
24
  return datasets.DatasetInfo(
25
  description=_DESCRIPTION,
26
  features=datasets.Features(
27
  {
28
+ 'text': datasets.Value("string"),
29
+ 'image': datasets.Image(),
30
  }
31
  ),
 
 
32
  supervised_keys=None,
33
+ homepage=_HOMEPAGE,
34
  citation=_CITATION,
35
  )
36
 
37
  def _split_generators(self, dl_manager):
38
+ images_archive = dl_manager.download(f"{_REPO}/resolve/main/images.tgz")
39
+ image_iters = dl_manager.iter_archive(images_archive)
40
  return [
41
  datasets.SplitGenerator(
42
  name=datasets.Split.TRAIN,
43
  gen_kwargs={
44
  "images": image_iters
45
+ }
46
  ),
47
  ]
48
 
49
  def _generate_examples(self, images):
50
+ """ This function returns the examples in the raw (text) form."""
51
+
52
+ for idx, (filepath, image) in enumerate(images):
53
+ description = filepath.split('/')[-1][:-4]
54
+ description = description.replace('_', ' ')
55
+ yield idx, {
56
+ "image": {"path": filepath, "bytes": image.read()},
57
+ "text": description,
58
+ }