jamescalam commited on
Commit
9dc041f
·
verified ·
1 Parent(s): 82e5776

create dataset builder file

Browse files
Files changed (1) hide show
  1. shrek-detection.py +60 -0
shrek-detection.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+
3
+ _CITATION = """\
4
+ @InProceedings{huggingface:dataset,
5
+ title = {Shrek Detection Dataset},
6
+ author={Aurelio AI},
7
+ year={2024}
8
+ }
9
+ """
10
+
11
+ _DESCRIPTION = """\
12
+ Demo dataset for testing Shrek detection capabilities in images.
13
+ """
14
+ _HOMEPAGE = "https://huggingface.co/datasets/aurelio-ai/shrek-detection"
15
+
16
+ _LICENSE = ""
17
+
18
+ _REPO = "https://huggingface.co/datasets/aurelio-ai/shrek-detection"
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
+ filename = filepath.split('/')[-1][:-4]
54
+ cls = int(filename)[0]
55
+ description = filename[1:].replace('_', ' ')
56
+ yield idx, {
57
+ "image": {"path": filepath, "bytes": image.read()},
58
+ "text": description,
59
+ "is_shrek": cls
60
+ }