File size: 6,231 Bytes
430d827 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# Copyright 2022 for msynth dataset
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''
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"
# Initialize an empty list to store the file paths
_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":
# Define dataset features and keys
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 = [] # List to store file paths
# Walk through the directory and its subdirectories using os.walk
for folder, _, files in os.walk(root_directory):
for file in files:
if file == "cropped_image.png":
# Get the full path of the file
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 = []
# Get the directory containing the cropped_image.png
directory = os.path.dirname(cropped_image_path)
# Walk through the directory to find other image files
for file in os.listdir(directory):
if file == file_name:
# Get the full path of the other image file
file_path = os.path.join(directory, file)
#other_image_paths.append(file_path)
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
|