File size: 2,017 Bytes
4d5bb3d 7dcef9f 4d5bb3d 7dcef9f 81d9a65 7dcef9f 4d5bb3d 7dcef9f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
import datasets
_CITATION = """\
@InProceedings{huggingface:dataset,
title = {Small image-text set},
author={James Briggs},
year={2022}
}
"""
_DESCRIPTION = """\
Demo dataset for testing or showing image-text capabilities.
"""
_HOMEPAGE = "https://huggingface.co/datasets/jamescalam/image-text-demo"
_LICENSE = ""
_URL="https://huggingface.co/datasets/aadhiya/image-test/resolve/main/images.tar.gz"
_REPO = "https://huggingface.co/datasets/jamescalam/image-text-demo"
descriptions=[
"BotPeg Dance",
"BotPeg Dance",
"BotPeg Excited",
"BotPeg Excited",
"BotPeg Fight",
"BotPeg Funny",
"BotPeg Funny",
"BotPeg Funny",
"BotPeg Love",
"BotPeg Mad",
"BotPeg Sad",
"BotPeg Scared",
"BotPeg Shy",
"BotPeg Thinking",
"BotPeg Thinking",
"BotPeg Winner",
"BotPeg Worried",
]
class ImageSet(datasets.GeneratorBasedBuilder):
"""Small sample of image-text pairs"""
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
'text': datasets.Value("string"),
'image': datasets.Image(),
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
path=dl_manager.download(_URL)
image_iters=dl_manager.iter_archive(path)
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."""
idx=0
for filepath,image in images:
yield idx,{
"image":{"path":filepath,"bytes":image.read()},
"text":descriptions[idx]
}
idx+=1
|