|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""chensu test animal classification dataset with images of cats and dogs""" |
|
|
|
import os |
|
|
|
import datasets |
|
from datasets import load_dataset |
|
from datasets.tasks import ImageClassification |
|
|
|
|
|
_HOMEPAGE = "https://oss.console.aliyun.com/bucket/oss-cn-beijing/340788/object" |
|
|
|
_CITATION = """\ |
|
@ONLINE { |
|
author="chensu" |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
This is a test dataset used to demonstrate the process of creating a hugging face dataset |
|
""" |
|
|
|
_URLS = { |
|
"train": "https://340788.oss-cn-beijing.aliyuncs.com/train.zip", |
|
"test": "https://340788.oss-cn-beijing.aliyuncs.com/test.zip", |
|
} |
|
|
|
_NAMES = ["cat", "dog"] |
|
|
|
|
|
class TestDataset(datasets.GeneratorBasedBuilder): |
|
"""Test classification dataset.""" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"image_file_path": datasets.Value("string"), |
|
"image": datasets.Image(), |
|
"labels": datasets.features.ClassLabel(names=_NAMES), |
|
} |
|
), |
|
supervised_keys=("image", "labels"), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
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"]]), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"files": dl_manager.iter_files([data_files["test"]]), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, files): |
|
for i, path in enumerate(files): |
|
file_name = os.path.basename(path) |
|
if file_name.endswith(".jpeg"): |
|
yield i, { |
|
"image_file_path": path, |
|
"image": path, |
|
"labels": os.path.basename(os.path.dirname(path)).lower(), |
|
} |