File size: 2,769 Bytes
d7ecb2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Dataset class for image dataset."""

import datasets
import os
from datasets.tasks import ImageClassification

_URLS = "mortars_data.zip"

_HOMEPAGE = "http://https://huggingface.co/datasets/apetulante/mortars_test"

_DESCRIPTION = (
    "This dataset consists of test dataset of ancient mortar and with only obsidian images as zip file in it"
)

_NAMES = [ 
    "Obsidian-1to2mm",
    
]

_CITATION = ""
   
        
class AncientMortarConfig(datasets.BuilderConfig):
    """BuilderConfig for COCO cats image."""

    def __init__(
        self,
        data_url,
        url,
        task_templates=None,
        **kwargs,
    ):
        super(AncientMortarConfig, self).__init__(
            version=datasets.Version("1.9.0", ""), **kwargs
        )
        self.data_url = data_url
        self.url = url
        self.task_templates = task_templates
                         
class AncientMortar(datasets.GeneratorBasedBuilder):
    
    BUILDER_CONFIGS = [
        AncientMortarConfig(
            name="image",
            url="",
            data_url="",
        )
    ] 
    
              
    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "image": datasets.Image(),
                    "label": datasets.ClassLabel(names=_NAMES),
                }
            ),
            supervised_keys=("image", "label"),
            homepage=_HOMEPAGE,
            citation=_CITATION,
            task_templates=[ImageClassification(image_column="image", label_column="label")],
        )
     
    def _split_generators(self, dl_manager):
        data_files = dl_manager.download_and_extract(_URLS)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "files": dl_manager.iter_files([data_files]),
                },
            )
        ]
    def _generate_examples(self, files):
        """Generate images and labels for splits."""
        for i, path in enumerate(files):
            file_name = os.path.basename(path)
            if file_name.endswith(".bmp"):
                yield i, {
                    "image_file_path": path,
                    "image": path,
                    "labels": os.path.basename(os.path.dirname(path)).lower(),
                }
    #    for file_path in files:
    ##        if file_path.startswith(_IMAGES_DIR):
     #           if file_path[len(_IMAGES_DIR) : -len(".bmp")] in files_to_keep:
      #              label = file_path.split("/")[2]
      #              yield file_path, {
       #                 "image": {"path": file_path},
        #                "label": label,
         #           }