|
|
|
"""PlantsDataset |
|
|
|
Automatically generated by Colaboratory. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/13QeVLQP2QGaxkGcaoMi25geoBxHQ_3rQ |
|
""" |
|
|
|
from datasets import Dataset, DatasetInfo, Features, Value, Split, DownloadManager, GeneratorBasedBuilder |
|
from datasets import SplitGenerator |
|
|
|
import os |
|
from datasets import Dataset, DatasetInfo, Features, Value, Split, GeneratorBasedBuilder |
|
|
|
|
|
_DRIVE_ID = "1fXgVwhdU5YGj0SPIcHxSpxkhvRh54oEH" |
|
_URL = f"https://drive.google.com/uc?export=download&id={_DRIVE_ID}" |
|
|
|
|
|
class PlantsDataset(GeneratorBasedBuilder): |
|
VERSION = "1.0.0" |
|
|
|
def _info(self): |
|
features = Features({ |
|
"image": Value("string"), |
|
"label": Value("int64"), |
|
}) |
|
return DatasetInfo( |
|
description="Your dataset description", |
|
features=features, |
|
supervised_keys=("image", "label"), |
|
homepage="Your dataset homepage", |
|
citation="Citation for your dataset", |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
downloaded_file = dl_manager.download_and_extract(_URL) |
|
|
|
return [ |
|
SplitGenerator( |
|
name=Split.TRAIN, |
|
gen_kwargs={ |
|
"data_folder": os.path.join(downloaded_file, "train"), |
|
}, |
|
), |
|
SplitGenerator( |
|
name=Split.TEST, |
|
gen_kwargs={ |
|
"data_folder": os.path.join(downloaded_file, "test"), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, data_folder): |
|
for label, subfolder in enumerate(["gigantic", "small"]): |
|
subfolder_path = os.path.join(data_folder, subfolder) |
|
for root, _, files in os.walk(subfolder_path): |
|
for file_name in files: |
|
file_path = os.path.join(root, file_name) |
|
|
|
|
|
if os.path.isfile(file_path): |
|
|
|
yield { |
|
"image": file_path, |
|
"label": label, |
|
} |
|
|
|
|
|
|
|
plants_dataset = PlantsDataset() |
|
|
|
|
|
plants_dataset.download_and_prepare() |