Upload foot.py
Browse files
foot.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
import collections
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
import datasets
|
6 |
+
|
7 |
+
|
8 |
+
_HOMEPAGE = "https://huggingface.co/datasets/aidystark/FOOTNET40k"
|
9 |
+
_LICENSE = "CC BY 4.0"
|
10 |
+
_DESCRIPTION = """\
|
11 |
+
title = { wlots Dataset },
|
12 |
+
type = { Open Source Dataset },
|
13 |
+
author = { asd },
|
14 |
+
howpublished = { \\url{ https://universe.roboflow.com/asd-culfr/wlots } },
|
15 |
+
url = { https://universe.roboflow.com/asd-culfr/wlots },
|
16 |
+
journal = { Roboflow Universe },
|
17 |
+
publisher = { Roboflow },
|
18 |
+
"""
|
19 |
+
_CITATION = """\
|
20 |
+
@misc{ wlots_dataset,
|
21 |
+
title = { wlots Dataset },
|
22 |
+
type = { Open Source Dataset },
|
23 |
+
author = { asd },
|
24 |
+
howpublished = { \\url{ https://universe.roboflow.com/asd-culfr/wlots } },
|
25 |
+
url = { https://universe.roboflow.com/asd-culfr/wlots },
|
26 |
+
journal = { Roboflow Universe },
|
27 |
+
publisher = { Roboflow },
|
28 |
+
year = { 2022 },
|
29 |
+
month = { may },
|
30 |
+
note = { visited on 2023-01-27 },
|
31 |
+
}
|
32 |
+
"""
|
33 |
+
_NAMES = ["Dressing Shoe", "Crocs", "Heels", "Sneakers", "Boot", "Sandals"]
|
34 |
+
#_ANNOTATION_FILENAME = "_annotations.coco.json"
|
35 |
+
|
36 |
+
|
37 |
+
class FOOT40KConfig(datasets.BuilderConfig):
|
38 |
+
"""Builder Config for FOOT40K"""
|
39 |
+
|
40 |
+
def __init__(self, data_url, metadata_url, **kwargs):
|
41 |
+
"""BuilderConfig for FOOT40K.
|
42 |
+
Args:
|
43 |
+
data_url: `string`, url to download the zip file from.
|
44 |
+
metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
|
45 |
+
**kwargs: keyword arguments forwarded to super.
|
46 |
+
"""
|
47 |
+
super(FOOT40KConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
48 |
+
self.data_url = data_url
|
49 |
+
self.metadata_url = metadata_url
|
50 |
+
|
51 |
+
class FOOT40K(datasets.GeneratorBasedBuilder):
|
52 |
+
"""FOOT40K Images dataset"""
|
53 |
+
|
54 |
+
BUILDER_CONFIGS = [
|
55 |
+
FOOT40KConfig(
|
56 |
+
name="shoe_all",
|
57 |
+
description="Shoe Data.",
|
58 |
+
data_url="https://huggingface.co/datasets/aidystark/FOOT40K/resolve/main/FOOT40k.tar.gz?download=true",
|
59 |
+
metadata_url = "https://huggingface.co/datasets/aidystark/FOOTNET40k/resolve/main/foot40k.json?download=true",
|
60 |
+
|
61 |
+
),
|
62 |
+
|
63 |
+
]
|
64 |
+
|
65 |
+
def _info(self):
|
66 |
+
return datasets.DatasetInfo(
|
67 |
+
description=_DESCRIPTION,
|
68 |
+
features=datasets.Features(
|
69 |
+
{
|
70 |
+
"image": datasets.Image(),
|
71 |
+
"label": datasets.ClassLabel(names=_NAMES),
|
72 |
+
}
|
73 |
+
),
|
74 |
+
supervised_keys=("image", "label"),
|
75 |
+
homepage=_HOMEPAGE,
|
76 |
+
citation=_CITATION,
|
77 |
+
license=_LICENSE,
|
78 |
+
)
|
79 |
+
|
80 |
+
def _split_generators(self, dl_manager):
|
81 |
+
archive_path = dl_manager.download(self.config.data_url)
|
82 |
+
image_iters = dl_manager.iter_archive(archive_path)
|
83 |
+
metadata_path = dl_manager.download(self.config.metadata_url)
|
84 |
+
return [
|
85 |
+
datasets.SplitGenerator(
|
86 |
+
name=datasets.Split.TRAIN,
|
87 |
+
gen_kwargs={
|
88 |
+
"images": image_iters,
|
89 |
+
"metadata_path": metadata_path,
|
90 |
+
},
|
91 |
+
),
|
92 |
+
|
93 |
+
]
|
94 |
+
|
95 |
+
|
96 |
+
def _generate_examples(self, images, metadata_path):
|
97 |
+
idx = 0
|
98 |
+
|
99 |
+
|
100 |
+
with open(metadata_path, "r") as f:
|
101 |
+
filename_to_label = json.load(f)
|
102 |
+
|
103 |
+
labels = [item["Label"] for item in filename_to_label]
|
104 |
+
|
105 |
+
|
106 |
+
for filepath, image in images:
|
107 |
+
yield idx, {
|
108 |
+
"image": {"path": filepath, "bytes": image.read()},
|
109 |
+
"label": labels[idx],
|
110 |
+
}
|
111 |
+
|
112 |
+
idx += 1
|