Create bee-wings-large.py
Browse files- bee-wings-large.py +62 -0
bee-wings-large.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import tarfile
|
3 |
+
import os
|
4 |
+
|
5 |
+
_CITATION = """\
|
6 |
+
@InProceedings{huggingface:dataset,
|
7 |
+
title = {Small image-text set},
|
8 |
+
author={James Briggs},
|
9 |
+
year={2022}
|
10 |
+
}
|
11 |
+
"""
|
12 |
+
|
13 |
+
_DESCRIPTION = """\
|
14 |
+
Random Small
|
15 |
+
"""
|
16 |
+
|
17 |
+
|
18 |
+
_LICENSE = ""
|
19 |
+
|
20 |
+
_REPO = "https://huggingface.co/datasets/smaciu/bee-wings-large"
|
21 |
+
|
22 |
+
|
23 |
+
class ImageSet(datasets.GeneratorBasedBuilder):
|
24 |
+
"""Small sample of image-text pairs"""
|
25 |
+
|
26 |
+
def _info(self):
|
27 |
+
return datasets.DatasetInfo(
|
28 |
+
description=_DESCRIPTION,
|
29 |
+
features=datasets.Features(
|
30 |
+
{
|
31 |
+
'file_name': datasets.Value('string'),
|
32 |
+
'image': datasets.Image(),
|
33 |
+
'label': datasets.Value("string"),
|
34 |
+
}
|
35 |
+
),
|
36 |
+
supervised_keys=None,
|
37 |
+
homepage=_HOMEPAGE,
|
38 |
+
citation=_CITATION,
|
39 |
+
)
|
40 |
+
|
41 |
+
def _split_generators(self, dl_manager):
|
42 |
+
images_archive = dl_manager.download(f"{_REPO}/resolve/main/bee-wings-large.tar")
|
43 |
+
|
44 |
+
|
45 |
+
image_iters = dl_manager.iter_archive(images_archive)
|
46 |
+
return [
|
47 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN,gen_kwargs={"images": image_iters}),
|
48 |
+
]
|
49 |
+
|
50 |
+
def _generate_examples(self, images):
|
51 |
+
""" This function returns the examples in the raw (text) form."""
|
52 |
+
|
53 |
+
for idx, (filepath, image) in enumerate(images):
|
54 |
+
|
55 |
+
|
56 |
+
filename = os.path.basename(filepath) # Get the file name from the path
|
57 |
+
description = filename[:2]
|
58 |
+
yield idx, {
|
59 |
+
"file_name": filename,
|
60 |
+
"image": {"path": filepath, "bytes": image.read()},
|
61 |
+
"label": description,
|
62 |
+
}
|