Upload tfcol.py
Browse files
tfcol.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The HuggingFace Datasets, Santiago Hincapie-Potes and the TF Colombia community.
|
| 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.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
import datasets
|
| 21 |
+
|
| 22 |
+
_URLs = {
|
| 23 |
+
"train": {
|
| 24 |
+
"images": "https://huggingface.co/datasets/shpotes/tfcol/resolve/main/data/train.tar.gz",
|
| 25 |
+
"annotations": "https://huggingface.co/datasets/shpotes/tfcol/raw/main/data/train.jsonl",
|
| 26 |
+
},
|
| 27 |
+
"val": {
|
| 28 |
+
"images": "https://huggingface.co/datasets/shpotes/tfcol/resolve/main/data/val.tar.gz",
|
| 29 |
+
"annotations": "https://huggingface.co/datasets/shpotes/tfcol/raw/main/data/val.jsonl",
|
| 30 |
+
},
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class TFCol(datasets.GeneratorBasedBuilder):
|
| 35 |
+
VERSION = datasets.Version("1.0.0")
|
| 36 |
+
|
| 37 |
+
def _info(self):
|
| 38 |
+
features = datasets.Features(
|
| 39 |
+
{
|
| 40 |
+
"lat": datasets.Value("float32"),
|
| 41 |
+
"lon": datasets.Value("float32"),
|
| 42 |
+
"labels": datasets.Sequence(
|
| 43 |
+
datasets.ClassLabel(
|
| 44 |
+
num_classes=20,
|
| 45 |
+
names=[
|
| 46 |
+
"ropa",
|
| 47 |
+
"licorera",
|
| 48 |
+
"belleza/barbería/peluquería",
|
| 49 |
+
"electrónica/cómputo",
|
| 50 |
+
"parqueadero",
|
| 51 |
+
"café/restaurante",
|
| 52 |
+
"muebles/tapicería",
|
| 53 |
+
"ferretería",
|
| 54 |
+
"puesto móvil/toldito",
|
| 55 |
+
"electrodomésticos",
|
| 56 |
+
"carnicería/fruver",
|
| 57 |
+
"bar",
|
| 58 |
+
"animales",
|
| 59 |
+
"tienda",
|
| 60 |
+
"farmacia",
|
| 61 |
+
"deporte",
|
| 62 |
+
"talleres carros/motos",
|
| 63 |
+
"zapatería",
|
| 64 |
+
"supermercado",
|
| 65 |
+
"hotel",
|
| 66 |
+
],
|
| 67 |
+
)
|
| 68 |
+
),
|
| 69 |
+
"image": datasets.Value("string"),
|
| 70 |
+
}
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
return datasets.DatasetInfo(features=features)
|
| 74 |
+
|
| 75 |
+
def _split_generators(self, dl_manager):
|
| 76 |
+
"""Returns SplitGenerators."""
|
| 77 |
+
data_dir = dl_manager.download_and_extract(_URLs)
|
| 78 |
+
|
| 79 |
+
return [
|
| 80 |
+
datasets.SplitGenerator(
|
| 81 |
+
name=datasets.Split.TRAIN,
|
| 82 |
+
# These kwargs will be passed to _generate_examples
|
| 83 |
+
gen_kwargs={
|
| 84 |
+
"annotations": data_dir["train"]["annotations"],
|
| 85 |
+
"images": data_dir["train"]["images"],
|
| 86 |
+
"split": "train",
|
| 87 |
+
},
|
| 88 |
+
),
|
| 89 |
+
datasets.SplitGenerator(
|
| 90 |
+
name=datasets.Split.VALIDATION,
|
| 91 |
+
# These kwargs will be passed to _generate_examples
|
| 92 |
+
gen_kwargs={
|
| 93 |
+
"annotations": data_dir["val"]["annotations"],
|
| 94 |
+
"images": data_dir["val"]["images"],
|
| 95 |
+
"split": "val",
|
| 96 |
+
},
|
| 97 |
+
),
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
def _generate_examples(self, annotations, images, split):
|
| 101 |
+
"""Yields examples as (key, example) tuples."""
|
| 102 |
+
|
| 103 |
+
with open(annotations, encoding="utf-8") as f:
|
| 104 |
+
for id_, row in enumerate(f):
|
| 105 |
+
data = json.loads(row)
|
| 106 |
+
|
| 107 |
+
yield id_, {
|
| 108 |
+
"lat": data["lat"],
|
| 109 |
+
"lon": data["lon"],
|
| 110 |
+
"labels": data["labels"],
|
| 111 |
+
"image": os.path.join(images, split, data["fname"]),
|
| 112 |
+
}
|