Create horizontal-map.py
Browse files- horizontal-map.py +76 -0
horizontal-map.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.Wikipedia
|
| 15 |
+
|
| 16 |
+
# Lint as: python3
|
| 17 |
+
"""Dream!n map datasets"""
|
| 18 |
+
|
| 19 |
+
import datasets
|
| 20 |
+
import json
|
| 21 |
+
import urllib
|
| 22 |
+
|
| 23 |
+
_CITATION = """
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
_DESCRIPTION = "Dream!n map datasets"
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
_DATASET_URL = "https://huggingface.co/datasets/JAWCF/maps/resolve/main/images.tar.gz"
|
| 30 |
+
|
| 31 |
+
json_url = urllib.request.urlopen("https://huggingface.co/datasets/JAWCF/maps/resolve/main/maps.json")
|
| 32 |
+
DICT_DESC = json.loads(json_url.read())
|
| 33 |
+
|
| 34 |
+
class Maps(datasets.GeneratorBasedBuilder):
|
| 35 |
+
|
| 36 |
+
def _info(self):
|
| 37 |
+
features = datasets.Features({
|
| 38 |
+
'image': datasets.Image(),
|
| 39 |
+
'text': datasets.Value('string')
|
| 40 |
+
})
|
| 41 |
+
return datasets.DatasetInfo(
|
| 42 |
+
# This is the description that will appear on the datasets page.
|
| 43 |
+
description=_DESCRIPTION,
|
| 44 |
+
# This defines the different columns of the dataset and their types
|
| 45 |
+
features=features, # Here we define them above because they are different between the two configurations
|
| 46 |
+
supervised_keys=None,
|
| 47 |
+
# Homepage of the dataset for documentation
|
| 48 |
+
homepage="",
|
| 49 |
+
# License for the dataset if available
|
| 50 |
+
license="",
|
| 51 |
+
# Citation for the dataset
|
| 52 |
+
citation=_CITATION,
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
def _split_generators(self, dl_manager):
|
| 56 |
+
path = dl_manager.download(_DATASET_URL)
|
| 57 |
+
image_iters = dl_manager.iter_archive(path)
|
| 58 |
+
splits = [
|
| 59 |
+
datasets.SplitGenerator(
|
| 60 |
+
name=datasets.Split.TRAIN,
|
| 61 |
+
gen_kwargs={
|
| 62 |
+
"images": image_iters
|
| 63 |
+
}
|
| 64 |
+
),
|
| 65 |
+
]
|
| 66 |
+
return splits
|
| 67 |
+
|
| 68 |
+
def _generate_examples(self, images):
|
| 69 |
+
"""Yields examples."""
|
| 70 |
+
idx = 0
|
| 71 |
+
for filepath, image in images:
|
| 72 |
+
yield idx, {
|
| 73 |
+
"image": {"path": filepath, "bytes": image.read()},
|
| 74 |
+
"text" : DICT_DESC[filepath.split("/")[-1].lower()],
|
| 75 |
+
}
|
| 76 |
+
idx+=1
|