add custom script
Browse files- cell_benchmark.py +87 -0
cell_benchmark.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datasets
|
| 3 |
+
#from datasets import DownloadManager, DatasetInfo
|
| 4 |
+
|
| 5 |
+
_DESCRIPTION = """\
|
| 6 |
+
A segmentation dataset for [TODO: complete...]
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
_HOMEPAGE = "https://huggingface.co/datasets/alkzar90/cell_benchmark"
|
| 11 |
+
_EXTENSION = [".jpg", ".png"]
|
| 12 |
+
_URL_BASE = "https://huggingface.co/datasets/alkzar90/cell_benchmark/resolve/main/data/"
|
| 13 |
+
_SPLIT_URLS = {
|
| 14 |
+
"train": _URL_BASE + "train.zip",
|
| 15 |
+
"val": _URL_BASE + "val.zip",
|
| 16 |
+
"test": _URL_BASE + "test.zip",
|
| 17 |
+
"masks": _URL_BASE + "masks.zip",
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class Cellsegmentation(datasets.GeneratorBasedBuilder):
|
| 23 |
+
|
| 24 |
+
def _info(self) -> DatasetInfo:
|
| 25 |
+
features = datasets.Features({
|
| 26 |
+
"image": datasets.Image(),
|
| 27 |
+
"masks": datasets.Image(),
|
| 28 |
+
"path" : datasets.Value("string"),
|
| 29 |
+
})
|
| 30 |
+
return datasets.DatasetInfo(
|
| 31 |
+
description=_DESCRIPTION,
|
| 32 |
+
features=datasets.Features(features),
|
| 33 |
+
supervised_keys=("image", "masks"),
|
| 34 |
+
homepage_HOMEPAGE,
|
| 35 |
+
citation="",
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _split_generators(self, dl_manager):
|
| 40 |
+
data_files = dl_manager.download_and_extract(_SPLIT_URLS)
|
| 41 |
+
splits = [
|
| 42 |
+
datasets.SplitGenerator(
|
| 43 |
+
name=datasets.Split.TRAIN,
|
| 44 |
+
gen_kwargs={
|
| 45 |
+
"files" : dl_manager.iter_files([data_files["train"]]),
|
| 46 |
+
"masks": data_files["masks"],
|
| 47 |
+
"split": "training",
|
| 48 |
+
},
|
| 49 |
+
),
|
| 50 |
+
datasets.SplitGenerator(
|
| 51 |
+
name=datasets.Split.VALIDATION,
|
| 52 |
+
gen_kwargs={
|
| 53 |
+
"files" : dl_manager.iter_files([data_files["validation"]]),
|
| 54 |
+
"masks": data_files["masks"],
|
| 55 |
+
"split": "validation",
|
| 56 |
+
},
|
| 57 |
+
),
|
| 58 |
+
datasets.SplitGenerator(
|
| 59 |
+
name=datasets.Split.TEST,
|
| 60 |
+
gen_kwargs={
|
| 61 |
+
"files" : dl_manager.iter_files([data_files["test"]]),
|
| 62 |
+
"masks": data_files["masks"],
|
| 63 |
+
"split": "test",
|
| 64 |
+
}
|
| 65 |
+
)
|
| 66 |
+
]
|
| 67 |
+
return splits
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _generate_examples(self, files, masks, split):
|
| 71 |
+
mask_path = os.path.basename(masks)
|
| 72 |
+
for i, path in enumereate(files):
|
| 73 |
+
file_name = os.path.basename(path)
|
| 74 |
+
yield i, {
|
| 75 |
+
"image": path,
|
| 76 |
+
"masks": mask_path + "mask_" + file_name.replace("jpg", "png"),
|
| 77 |
+
"path": path,
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|