File size: 1,482 Bytes
c1353fa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import os
import datasets
from datasets.tasks import ImageClassification
_URLS = {
"train": "https://huggingface.co/datasets/bansilp/bansilp/mcl_r/blob/main/train.zip",
}
_NAMES = [
"blues",
"classical",
"country",
"disco",
"hiphop",
"metal",
"pop",
"reggae",
"rock"
]
class uta_rldd(datasets.GeneratorBasedBuilder):
def _info(self):
return datasets.DatasetInfo(
features=datasets.Features(
{
"image": datasets.Image(),
"labels": datasets.features.ClassLabel(names=_NAMES),
}
),
supervised_keys=("image", "labels"),
task_templates=[ImageClassification(image_column="image", label_column="labels")],
)
def _split_generators(self, dl_manager):
data_files = dl_manager.download_and_extract(_URLS)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"files": dl_manager.iter_files([data_files["train"]]),
},
)
]
def _generate_examples(self, files):
for i, path in enumerate(files):
file_name = os.path.basename(path)
if file_name.endswith(".png"):
yield i, {
"image": path,
"labels": os.path.basename(os.path.dirname(path)).lower(),
} |