| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| ''' |
| Custom dataset-builder for ssynth dataset |
| ''' |
|
|
| import os |
| import datasets |
| import glob |
| import re |
|
|
|
|
| logger = datasets.logging.get_logger(__name__) |
|
|
| _CITATION = """\ |
| @article{kim2024ssynth, |
| title={Knowledge-based in silico models and dataset for the comparative evaluation of mammography AI for a range of breast characteristics, lesion conspicuities and doses}, |
| author={Kim, Andrea and Saharkhiz, Niloufar and Sizikova, Elena and Lago, Miguel, and Sahiner, Berkman and Delfino, Jana G., and Badano, Aldo}, |
| journal={International Conference on Medical Image Computing and Computer Assisted Intervention (MICCAI)}, |
| volume={}, |
| pages={}, |
| year={2024} |
| } |
| """ |
|
|
|
|
| _DESCRIPTION = """\ |
| S-SYNTH is an open-source, flexible skin simulation framework to rapidly generate synthetic skin models and images using digital rendering of an anatomically inspired multi-layer, multi-component skin and growing lesion model. It allows for generation of highly-detailed 3D skin models and digitally rendered synthetic images of diverse human skin tones, with full control of underlying parameters and the image formation process. |
| Curated by: Andrea Kim, Niloufar Saharkhiz, Elena Sizikova, Miguel Lago, Berkman Sahiner, Jana Delfino, Aldo Badano |
| License: Creative Commons 1.0 Universal License (CC0) |
| """ |
|
|
|
|
| _HOMEPAGE = "https://github.com/DIDSR/ssynth-release?tab=readme-ov-file" |
|
|
| _REPO = "https://huggingface.co/datasets/didsr/ssynth_data/resolve/main" |
|
|
| |
| _CROPPED = True |
|
|
| _URLS = { |
| "synthetic_data": f"{_REPO}/data/synthetic_dataset/output_10k.zip", |
| "read_me": f"{_REPO}/README.md" |
| } |
|
|
| DATA_DIR = {"all_data": "output_10k"} |
|
|
| class ssynth_dataConfig(datasets.BuilderConfig): |
| """ssynth dataset""" |
| def __init__(self, name, **kwargs): |
| super(ssynth_dataConfig, self).__init__( |
| version=datasets.Version("1.0.0"), |
| name=name, |
| description="ssynth_data", |
| **kwargs, |
| ) |
|
|
| class ssynth_data(datasets.GeneratorBasedBuilder): |
| """ssynth dataset.""" |
| |
| DEFAULT_WRITER_BATCH_SIZE = 256 |
| BUILDER_CONFIGS = [ |
| ssynth_dataConfig("output_10k"), |
| ] |
| |
| def _info(self): |
| if self.config.name == "output_10k": |
| |
| features = datasets.Features( |
| { |
| "Cropped": datasets.Features({ |
| "image": datasets.Value("string"), |
| "mask": datasets.Value("string") |
| }), |
| "Uncropped": datasets.Features({ |
| "image": datasets.Value("string"), |
| "mask": datasets.Value("string") |
| }) |
| } |
| ) |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| supervised_keys=None, |
| homepage=_HOMEPAGE, |
| citation=_CITATION, |
| ) |
| |
| def _split_generators( |
| self, dl_manager: datasets.utils.download_manager.DownloadManager): |
| |
| if self.config.name == "output_10k": |
| data_dir = dl_manager.download_and_extract(_URLS['synthetic_data']) |
| return [ |
| datasets.SplitGenerator( |
| name="output_10k", |
| gen_kwargs={ |
| "files": data_dir, |
| "name": "all_data", |
| }, |
| ), |
| ] |
| |
| def get_all_file_paths(self, root_directory): |
| file_paths = [] |
|
|
| |
| for folder, _, files in os.walk(root_directory): |
| for file in files: |
| if file == "cropped_image.png": |
| |
| file_path = os.path.join(folder, file) |
| file_paths.append(file_path) |
| return file_paths |
| |
| def get_other_images(self, cropped_image_path, file_name): |
| other_image_paths = [] |
|
|
| |
| directory = os.path.dirname(cropped_image_path) |
|
|
| |
| for file in os.listdir(directory): |
| if file == file_name: |
| |
| file_path = os.path.join(directory, file) |
| |
| return file_path |
| return None |
| |
| |
| def _generate_examples(self, files, name): |
| if self.config.name == "output_10k": |
| key = 0 |
| data_paths = self.get_all_file_paths(os.path.join(files, DATA_DIR[name])) |
| |
| cropped_images = [] |
| uncropped_images = [] |
| for path in data_paths: |
| res_dic = {} |
| cropped_image = path |
| cropped_mask = self.get_other_images(path,"cropped_mask.png") |
| image = self.get_other_images(path,"image.png") |
| mask = self.get_other_images(path,"mask.png") |
| cropped_data = { |
| "image": cropped_image, |
| "mask": cropped_mask |
| } |
| uncropped_data = { |
| "image": image, |
| "mask": mask |
| } |
| res_dic["Cropped"] = cropped_data |
| res_dic["Uncropped"] = uncropped_data |
| |
| yield key, res_dic |
| key += 1 |
| |
| |
| |