arch-max / arch-max.py
bruno-cotrim's picture
Update arch-max.py
879ad58
Raw
History Blame Contribute Delete
4.82 kB
# Copyright (C) 2022, François-Guillaume Fernandez.
# This program is licensed under the Apache License 2.0.
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0> for full license details.
"""Arch-MAX (Architecture: Modular Artificial Explainable) dataset."""
import os
import json
from pathlib import Path
import pandas as pd
import datasets
_HOMEPAGE = "https://huggingface.co/datasets/bruno-cotrim/arch-max"
_LICENSE = "Apache License 2.0"
_CITATION = """ """
_DESCRIPTION = """ """
_REPO = "https://huggingface.co/datasets/bruno-cotrim/arch-max/resolve/main"
class HouseXMAConfig(datasets.BuilderConfig):
"""BuilderConfig for HouseXMA."""
def __init__(self, data_url, metadata_urls, **kwargs):
"""BuilderConfig for Imagette.
Args:
data_url: `string`, url to download the zip file from.
matadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
**kwargs: keyword arguments forwarded to super.
"""
super(HouseXMAConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
self.data_url = data_url
self.metadata_urls = metadata_urls
_COLLUMNS = [
'Residential',
'Commercial',
'Industrial',
'Cafe',
'Hotel',
'Restaurant',
'Store',
'MiscCommercial',
'Suburban',
'MiscResidential',
'CountryHouse',
'ConstructionSite',
'MiscIndustrial',
'PowerPlant',
'WaterTreatment',
'Door',
'Window',
'Awning',
'Billboard',
'Porch',
'Sign',
'Table',
'TiledRoof',
'TiledRoofTop',
'TiledRoofBottom',
'VendingMachine',
'WallSign',
'Statue',
'Chimney',
'Pipe',
'Machine',
'Truck',
'Car',
]
class HouseXMA(datasets.GeneratorBasedBuilder):
BUILDER_CONFIGS = [
HouseXMAConfig(
name="Difficulty lvl. 1",
description="Simplest version of the dataset. All examples show the same textures and camera position.",
data_url=f"{_REPO}/images/c1.zip",
metadata_urls=f"{_REPO}/labels/c1/all.csv",
),
HouseXMAConfig(
name="Difficulty lvl. 2",
description="Textures vary, camera is static.",
data_url=f"{_REPO}/images/c2.zip",
metadata_urls=f"{_REPO}/labels/c2/all.csv",
),
HouseXMAConfig(
name="Difficulty lvl. 3",
description="Textures vary, camera varies lightly.",
data_url=f"{_REPO}/images/c3.zip",
metadata_urls=f"{_REPO}/labels/c3/all.csv",
),
HouseXMAConfig(
name="Difficulty lvl. 4",
description="Textures vary, camera varies lightly, background objects present.",
data_url=f"{_REPO}/images/c4.zip",
metadata_urls=f"{_REPO}/labels/c4/all.csv",
),
HouseXMAConfig(
name="Difficulty lvl. 5",
description="Textures vary, camera varies heavily, background objects present.",
data_url=f"{_REPO}/images/c5.zip",
metadata_urls=f"{_REPO}/labels/c5/all.csv",
),
HouseXMAConfig(
name="Difficulty lvl. 6",
description="Textures vary, camera varies heavily, background objects present, brightness and contrast vary.",
data_url=f"{_REPO}/images/c6.zip",
metadata_urls=f"{_REPO}/labels/c6/all.csv",
),
]
def _info(self):
features = {
"image": datasets.Image()
}
for col in _COLLUMNS:
features[col] = datasets.ClassLabel(num_classes=2)
return datasets.DatasetInfo(
description=_DESCRIPTION + self.config.description,
features=datasets.Features(features),
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
images_path = dl_manager.download_and_extract(self.config.data_url)
labels_path = dl_manager.download(self.config.metadata_urls)
return [
datasets.SplitGenerator(
name='all',
gen_kwargs={
"images": images_path,
"labels": labels_path,
},
)
]
def _generate_examples(self, images, labels):
idx = 0
labels = pd.read_csv(labels)
for ix in range(len(labels)):
row = labels.iloc[ix].to_dict()
im_path = os.path.join(images, str(row['id']) + '.jpg')
example = {
"image": im_path
}
for col in _COLLUMNS:
example[col] = row[col]
yield idx, example
idx += 1