Adding loading script
Browse filesSigned-off-by: Jiri Podivin <jpodivin@gmail.com>
- plantorgans.py +85 -0
plantorgans.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datasets
|
| 2 |
+
|
| 3 |
+
_DESCRIPTION = """Photos of various plants with their major, above ground organs labeled. Includes labels for stem, leafs, fruits and flowers."""
|
| 4 |
+
|
| 5 |
+
_HOMEPAGE = "https://huggingface.co/datasets/jpodivin/plantorgans"
|
| 6 |
+
|
| 7 |
+
_CITATION = """"""
|
| 8 |
+
|
| 9 |
+
_LICENSE = "MIT"
|
| 10 |
+
|
| 11 |
+
_NAMES = [
|
| 12 |
+
'Leaf',
|
| 13 |
+
'Stem',
|
| 14 |
+
'Flower',
|
| 15 |
+
'Fruit',
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
_BASE_URL = "https://huggingface.co/datasets/jpodivin/plantorgans/blob/main/sourcedata/"
|
| 19 |
+
|
| 20 |
+
_DOWNLOAD_SUFFIX = "download?true"
|
| 21 |
+
_METADATA_URLS = [
|
| 22 |
+
""
|
| 23 |
+
]
|
| 24 |
+
|
| 25 |
+
class PlantOrgans(datasets.GeneratorBasedBuilder):
|
| 26 |
+
"""Plantorgans dataset
|
| 27 |
+
"""
|
| 28 |
+
BUILDER_CONFIGS = [
|
| 29 |
+
PlantOrgansConfig(
|
| 30 |
+
name="semantic_segmentation",
|
| 31 |
+
description="This configuration contains segmentation masks."
|
| 32 |
+
),
|
| 33 |
+
]
|
| 34 |
+
|
| 35 |
+
def _info(self):
|
| 36 |
+
return datasets.DatasetInfo(
|
| 37 |
+
description=_DESCRIPTION,
|
| 38 |
+
features=datasets.Features(
|
| 39 |
+
{
|
| 40 |
+
"image": datasets.Image(),
|
| 41 |
+
"annotation": datasets.ClassLabel(names=_NAMES),
|
| 42 |
+
}
|
| 43 |
+
),
|
| 44 |
+
supervised_keys=("image", "annotation"),
|
| 45 |
+
homepage=_HOMEPAGE,
|
| 46 |
+
citation=_CITATION,
|
| 47 |
+
license=_LICENSE,
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def _split_generators(self, dl_manager):
|
| 52 |
+
archive_path = dl_manager.download(_BASE_URL)
|
| 53 |
+
split_metadata_paths = dl_manager.download(_METADATA_URLS)
|
| 54 |
+
return [
|
| 55 |
+
datasets.SplitGenerator(
|
| 56 |
+
name=datasets.Split.TRAIN,
|
| 57 |
+
gen_kwargs={
|
| 58 |
+
"images": dl_manager.iter_archive(archive_path),
|
| 59 |
+
"metadata_path": split_metadata_paths["train"],
|
| 60 |
+
},
|
| 61 |
+
),
|
| 62 |
+
datasets.SplitGenerator(
|
| 63 |
+
name=datasets.Split.VALIDATION,
|
| 64 |
+
gen_kwargs={
|
| 65 |
+
"images": dl_manager.iter_archive(archive_path),
|
| 66 |
+
"metadata_path": split_metadata_paths["test"],
|
| 67 |
+
},
|
| 68 |
+
),
|
| 69 |
+
]
|
| 70 |
+
def _generate_examples(self, images, metadata_path):
|
| 71 |
+
...
|
| 72 |
+
|
| 73 |
+
class PlantOrgansConfig(datasets.BuilderConfig):
|
| 74 |
+
"""Builder Config for PlantOrgans"""
|
| 75 |
+
|
| 76 |
+
def __init__(self, data_url, metadata_urls, **kwargs):
|
| 77 |
+
"""BuilderConfig for PlantOrgans.
|
| 78 |
+
Args:
|
| 79 |
+
data_url: `string`, url to download the zip file from.
|
| 80 |
+
metadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
|
| 81 |
+
**kwargs: keyword arguments forwarded to super.
|
| 82 |
+
"""
|
| 83 |
+
super().__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 84 |
+
self.data_url = data_url
|
| 85 |
+
self.metadata_urls = metadata_urls
|