Datasets:
Upload plantsdataset.py
Browse files- plantsdataset.py +75 -0
plantsdataset.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""PlantsDataset
|
3 |
+
|
4 |
+
Automatically generated by Colaboratory.
|
5 |
+
|
6 |
+
Original file is located at
|
7 |
+
https://colab.research.google.com/drive/13QeVLQP2QGaxkGcaoMi25geoBxHQ_3rQ
|
8 |
+
"""
|
9 |
+
|
10 |
+
from datasets import Dataset, DatasetInfo, Features, Value, Split, DownloadManager, GeneratorBasedBuilder
|
11 |
+
from datasets import SplitGenerator
|
12 |
+
# URL for the datasethttps://drive.google.com/file/d/1fXgVwhdU5YGj0SPIcHxSpxkhvRh54oEH/view?usp=share_link
|
13 |
+
import os
|
14 |
+
from datasets import Dataset, DatasetInfo, Features, Value, Split, GeneratorBasedBuilder
|
15 |
+
|
16 |
+
# Google Drive ID for your ZIP file
|
17 |
+
_DRIVE_ID = "1fXgVwhdU5YGj0SPIcHxSpxkhvRh54oEH"
|
18 |
+
_URL = f"https://drive.google.com/uc?export=download&id={_DRIVE_ID}"
|
19 |
+
|
20 |
+
# Custom Dataset Class
|
21 |
+
class PlantsDataset(GeneratorBasedBuilder):
|
22 |
+
VERSION = "1.0.0"
|
23 |
+
|
24 |
+
def _info(self):
|
25 |
+
features = Features({
|
26 |
+
"image": Value("string"), # Replace with the actual datatype for your image data
|
27 |
+
"label": Value("int64"), # Replace with the actual datatype for your label data
|
28 |
+
})
|
29 |
+
return DatasetInfo(
|
30 |
+
description="Your dataset description",
|
31 |
+
features=features,
|
32 |
+
supervised_keys=("image", "label"),
|
33 |
+
homepage="Your dataset homepage",
|
34 |
+
citation="Citation for your dataset",
|
35 |
+
)
|
36 |
+
|
37 |
+
def _split_generators(self, dl_manager):
|
38 |
+
downloaded_file = dl_manager.download_and_extract(_URL)
|
39 |
+
|
40 |
+
return [
|
41 |
+
SplitGenerator(
|
42 |
+
name=Split.TRAIN,
|
43 |
+
gen_kwargs={
|
44 |
+
"data_folder": os.path.join(downloaded_file, "train"),
|
45 |
+
},
|
46 |
+
),
|
47 |
+
SplitGenerator(
|
48 |
+
name=Split.TEST,
|
49 |
+
gen_kwargs={
|
50 |
+
"data_folder": os.path.join(downloaded_file, "test"),
|
51 |
+
},
|
52 |
+
),
|
53 |
+
]
|
54 |
+
|
55 |
+
def _generate_examples(self, data_folder):
|
56 |
+
for label, subfolder in enumerate(["gigantic", "small"]):
|
57 |
+
subfolder_path = os.path.join(data_folder, subfolder)
|
58 |
+
for root, _, files in os.walk(subfolder_path):
|
59 |
+
for file_name in files:
|
60 |
+
file_path = os.path.join(root, file_name)
|
61 |
+
|
62 |
+
# Check if file_path is a file, not a directory
|
63 |
+
if os.path.isfile(file_path):
|
64 |
+
# Yield the example
|
65 |
+
yield {
|
66 |
+
"image": file_path,
|
67 |
+
"label": label,
|
68 |
+
}
|
69 |
+
|
70 |
+
|
71 |
+
# Create an instance of the PlantsDataset class
|
72 |
+
plants_dataset = PlantsDataset()
|
73 |
+
|
74 |
+
# Build and upload the dataset
|
75 |
+
plants_dataset.download_and_prepare()
|