| | import datasets |
| |
|
| | _CITATION = """\ |
| | @InProceedings{huggingface:dataset, |
| | title = {Small image-text set}, |
| | author={James Briggs}, |
| | year={2022} |
| | } |
| | """ |
| |
|
| | _DESCRIPTION = """\ |
| | DEMO.. |
| | """ |
| | _HOMEPAGE = "https://huggingface.co/datasets/Souvikrad365/datademo" |
| |
|
| | _LICENSE = "" |
| | |
| | |
| |
|
| | |
| | descriptions = ['CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage', |
| | 'CT scan image of a brain with intracranial hemorrhage'] |
| |
|
| | _REPO = "https://huggingface.co/datasets/Souvikrad365/datademo" |
| |
|
| | 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): |
| | images_archive = dl_manager.download(f"{_REPO}/resolve/main/10imagesdataset.tar.gz") |
| | 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.""" |
| | |
| | idx=0 |
| | for filepath,image in images: |
| | yield idx,{ |
| | "image":{"path":filepath,"bytes":image.read()}, |
| | "text":descriptions[idx] |
| | } |
| | idx+=1 |