|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""MyoQuant-SDH-Data: The MyoQuant SDH Model Data.""" |
|
|
|
|
|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{Meyer, |
|
title = {MyoQuant SDH Data}, |
|
author={Corentin Meyer}, |
|
year={2022} |
|
} |
|
""" |
|
_NAMES = ["control", "sick"] |
|
|
|
_DESCRIPTION = """\ |
|
This dataset is used to train the SDH model of MyoQuant to detect and quantify anomaly in the mitochondria repartition in SDH stained muscle fiber with myopathy disorders. |
|
""" |
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/corentinm7/MyoQuant-SDH-Data" |
|
|
|
_LICENSE = "agpl-3.0" |
|
|
|
_URLS = { |
|
"SDH_16k": "https://huggingface.co/datasets/corentinm7/MyoQuant-SDH-Data/resolve/main/SDH_16k/SDH_16k.zip" |
|
} |
|
_METADATA_URL = { |
|
"SDH_16k_metadata": "https://huggingface.co/datasets/corentinm7/MyoQuant-SDH-Data/resolve/main/SDH_16k/metadata.jsonl" |
|
} |
|
|
|
|
|
class SDH_16k(datasets.GeneratorBasedBuilder): |
|
"""This dataset is used to train the SDH model of MyoQuant to detect and quantify anomaly in the mitochondria repartition in SDH stained muscle fiber with myopathy disorders.""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEFAULT_CONFIG_NAME = "SDH_16k" |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features( |
|
{ |
|
"image": datasets.Image(), |
|
"label": datasets.ClassLabel(num_classes=2, names=_NAMES), |
|
} |
|
), |
|
supervised_keys=("image", "label"), |
|
homepage=_HOMEPAGE, |
|
citation=_CITATION, |
|
license=_LICENSE, |
|
task_templates=[ |
|
datasets.ImageClassification(image_column="image", label_column="label") |
|
], |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
archive_path = dl_manager.download(_URLS) |
|
split_metadata_path = dl_manager.download(_METADATA_URL) |
|
files_metadata = {} |
|
with open(split_metadata_path["SDH_16k_metadata"], encoding="utf-8") as f: |
|
for lines in f.read().splitlines(): |
|
file_json_metdata = json.loads(lines) |
|
files_metadata.setdefault(file_json_metdata["split"], []).append( |
|
file_json_metdata |
|
) |
|
downloaded_files = dl_manager.download_and_extract(archive_path) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={ |
|
"download_path": downloaded_files["SDH_16k"], |
|
"metadata": files_metadata["train"], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={ |
|
"download_path": downloaded_files["SDH_16k"], |
|
"metadata": files_metadata["validation"], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={ |
|
"download_path": downloaded_files["SDH_16k"], |
|
"metadata": files_metadata["test"], |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, download_path, metadata): |
|
"""Generate images and labels for splits.""" |
|
for single_metdata in metadata: |
|
img_path = os.path.join( |
|
download_path, |
|
single_metdata["split"], |
|
single_metdata["label"], |
|
single_metdata["file_name"], |
|
) |
|
yield single_metdata["file_name"], { |
|
"image": {"path": img_path, "bytes": open(img_path, "rb").read()}, |
|
"label": single_metdata["label"], |
|
} |
|
|