File size: 1,760 Bytes
546dd0d
16fdc81
b61714e
546dd0d
 
 
 
 
 
 
 
 
 
4105fe6
546dd0d
 
 
 
 
9153f81
ee3869f
546dd0d
 
 
 
 
 
 
 
 
807c2fd
546dd0d
21001a1
546dd0d
 
 
 
 
 
 
 
22a6315
ee3869f
 
546dd0d
 
78f6e0d
546dd0d
 
9718eb8
 
64658c5
9718eb8
0f4b0fe
 
64658c5
 
9718eb8
826f34c
9718eb8
ef5140c
9718eb8
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
import datasets
import tarfile
import os

_CITATION = """\
@InProceedings{huggingface:dataset,
title = {Small image-text set},
author={James Briggs},
year={2022}
}
"""

_DESCRIPTION = """\
Random Small 
"""
_HOMEPAGE = "https://huggingface.co/datasets/jamescalam/image-text-demo"

_LICENSE = ""

_REPO = "https://huggingface.co/datasets/smaciu/bee-wings-small"


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/random_small.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)  # Get the file name from the path
            description = filename[:2]
            yield idx, {
                "file_name": filename,
                "image": {"path": filepath, "bytes": image.read()},
                "label": description,
            }