FOOT40K / foot.py
aidystark's picture
Update foot.py
c1ada15 verified
import collections
import json
import os
import datasets
_HOMEPAGE = "https://huggingface.co/datasets/aidystark/FOOTNET40k"
_LICENSE = "CC BY 4.0"
#_NAMES = ["Dressing Shoe", "Crocs", "Heels", "Sneakers", "Boot", "Sandals"]
#_ANNOTATION_FILENAME = "_annotations.coco.json"
class FOOT40KConfig(datasets.BuilderConfig):
"""Builder Config for FOOT40K"""
def __init__(self, data_url, **kwargs):# metadata_url, **kwargs):
"""BuilderConfig for FOOT40K.
Args:
data_url: `string`, url to download the zip file from.
metadata_url:
**kwargs: keyword arguments forwarded to super.
"""
super(FOOT40KConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
self.data_url = data_url
#self.metadata_url = metadata_url
class FOOT40K(datasets.GeneratorBasedBuilder):
"""FOOT40K Images dataset"""
BUILDER_CONFIGS = [
FOOT40KConfig(
name="shoe_all",
description="Shoe Data.",
data_url="https://huggingface.co/datasets/aidystark/FOOT40K/resolve/main/FOOT40k.tar.gz?download=true",
#metadata_url = "https://huggingface.co/datasets/aidystark/FOOT40K/resolve/main/foot40k.json?download=true",
),
]
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features(
{
"image": datasets.Image(),
#"Label": datasets.Value("string"),
}
),
homepage=_HOMEPAGE,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
#archive_path = dl_manager.download(self.config.data_url)
#image_iters = dl_manager.iter_archive(archive_path)
#metadata_path = dl_manager.download(self.config.metadata_url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"images": dl_manager.iter_archive(dl_manager.download(self.config.data_url)),
#"images": image_iters,#"metadata_path": metadata_path,
},
),
]
def _generate_examples(self, images ): #, metadata_path):
for file_path, file_obj in images:
yield file_path, {
"image": {"path": file_path, "bytes": file_obj.read()},
#"solution": Path(file_path).name.split('.')[0],
}
#idx = 0
#with open(metadata_path, "r") as f:
# filename_to_label = json.load(f)
#labels = [item["Label"] for item in filename_to_label]
#for filepath, image in images:
# yield idx, {
# "image": {"path": filepath, "bytes": image.read()},
# #"label": labels[idx],
# }
# idx += 1