| from xml.etree import ElementTree as ET | |
| import datasets | |
| _CITATION = """\ | |
| @InProceedings{huggingface:dataset, | |
| title = {wagons-images-classification}, | |
| author = {TrainingDataPro}, | |
| year = {2023} | |
| } | |
| """ | |
| _DESCRIPTION = """\ | |
| The dataset consists of images depicting **loaded and unloaded** wagons. | |
| The data are organasied in two folders for loaded and unloaded wagons and assisted with | |
| .CSV file containing text classification of the images. | |
| This dataset can be useful for various tasks, such as *image classification, object | |
| detection and data-driven analyses related to wagon loading and unloading processes. | |
| The dataset is useful for **rail transport sphere**, it can be utilised for automation | |
| the identification and classification of the wagons and further optimization of the | |
| processes in the industry. | |
| """ | |
| _NAME = "wagons-images-classification" | |
| _HOMEPAGE = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}" | |
| _LICENSE = "" | |
| _DATA = f"https://huggingface.co/datasets/TrainingDataPro/{_NAME}/resolve/main/data/" | |
| _LABELS = ["loaded", "unloaded"] | |
| class WagonsImagesClassification(datasets.GeneratorBasedBuilder): | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| description=_DESCRIPTION, | |
| features=datasets.Features( | |
| { | |
| "id": datasets.Value("int32"), | |
| "name": datasets.Value("string"), | |
| "image": datasets.Image(), | |
| "label": datasets.ClassLabel( | |
| num_classes=len(_LABELS), | |
| names=_LABELS, | |
| ), | |
| } | |
| ), | |
| supervised_keys=None, | |
| homepage=_HOMEPAGE, | |
| citation=_CITATION, | |
| ) | |
| def _split_generators(self, dl_manager): | |
| images = dl_manager.download(f"{_DATA}images.tar.gz") | |
| images = dl_manager.iter_archive(images) | |
| return [ | |
| datasets.SplitGenerator( | |
| name=datasets.Split.TRAIN, | |
| gen_kwargs={ | |
| "images": images, | |
| }, | |
| ), | |
| ] | |
| def _generate_examples(self, images): | |
| for idx, ((image_path, image)) in enumerate(images): | |
| label = "unloaded" if "unloaded" in image_path else "loaded" | |
| yield idx, { | |
| "id": idx, | |
| "name": image_path, | |
| "image": {"path": image_path, "bytes": image.read()}, | |
| "label": label, | |
| } | |