|
import datasets |
|
import tarfile |
|
import os |
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {Bee-wings-large}, |
|
author={Slawek Maciura}, |
|
year={2023} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Random Small |
|
""" |
|
_HOMEPAGE = "" |
|
|
|
_LICENSE = "" |
|
|
|
_REPO = "https://huggingface.co/datasets/smaciu/bee-wings-large" |
|
|
|
|
|
class ImageSet(datasets.GeneratorBasedBuilder): |
|
"""Small sample of image-text pairs""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
'file_name': datasets.Value('string'), |
|
'image': datasets.Image(), |
|
'label': datasets.Value("string"), |
|
} |
|
), |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
images_archive = dl_manager.download(f"{_REPO}/resolve/main/bee-wings-large.tar") |
|
|
|
|
|
image_iters = dl_manager.iter_archive(images_archive) |
|
return [ |
|
datasets.SplitGenerator(name=datasets.Split.TRAIN,gen_kwargs={"images": image_iters}), |
|
] |
|
|
|
def _generate_examples(self, images): |
|
""" This function returns the examples in the raw (text) form.""" |
|
|
|
for idx, (filepath, image) in enumerate(images): |
|
|
|
|
|
filename = os.path.basename(filepath) |
|
description = filename[:2] |
|
yield idx, { |
|
"file_name": filename, |
|
"image": {"path": filepath, "bytes": image.read()}, |
|
"label": description, |
|
} |
|
|