|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Dream!n map datasets""" |
|
|
|
import datasets |
|
import json |
|
import urllib |
|
|
|
_CITATION = """ |
|
""" |
|
|
|
_DESCRIPTION = "Dream!n map datasets" |
|
|
|
|
|
_DATASET_URL = "https://huggingface.co/datasets/JAWCF/horizontal-map/resolve/main/images.tar.gz" |
|
|
|
json_url = urllib.request.urlopen("https://huggingface.co/datasets/JAWCF/horizontal-map/resolve/main/maps.json") |
|
DICT_DESC = json.loads(json_url.read()) |
|
|
|
class Maps(datasets.GeneratorBasedBuilder): |
|
|
|
def _info(self): |
|
features = datasets.Features({ |
|
'image': datasets.Image(), |
|
'text': datasets.Value('string') |
|
}) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
supervised_keys=None, |
|
|
|
homepage="", |
|
|
|
license="", |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
path = dl_manager.download(_DATASET_URL) |
|
image_iters = dl_manager.iter_archive(path) |
|
splits = [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"images": image_iters |
|
} |
|
), |
|
] |
|
return splits |
|
|
|
def _generate_examples(self, images): |
|
"""Yields examples.""" |
|
idx = 0 |
|
for filepath, image in images: |
|
yield idx, { |
|
"image": {"path": filepath, "bytes": image.read()}, |
|
"text" : DICT_DESC[filepath.split("/")[-1].lower()], |
|
} |
|
idx+=1 |