"""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, # }