Update prostate158.py
Browse files- prostate158.py +43 -6
prostate158.py
CHANGED
|
@@ -1,11 +1,10 @@
|
|
| 1 |
import datasets
|
| 2 |
from typing import List
|
| 3 |
-
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
from pathlib import Path
|
| 7 |
import os
|
| 8 |
-
import nibabel as nib
|
| 9 |
|
| 10 |
_DESCRIPTION = "Prostate dataset."
|
| 11 |
|
|
@@ -26,7 +25,7 @@ class Prostate158Dataset(datasets.GeneratorBasedBuilder):
|
|
| 26 |
|
| 27 |
]
|
| 28 |
|
| 29 |
-
DEFAULT_CONFIG_NAME = "
|
| 30 |
|
| 31 |
def _info(self):
|
| 32 |
if self.config.name == "2d":
|
|
@@ -39,6 +38,17 @@ class Prostate158Dataset(datasets.GeneratorBasedBuilder):
|
|
| 39 |
"adc_tumor_reader1": datasets.Image(),
|
| 40 |
}
|
| 41 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
elif self.config.name == "3d_path":
|
| 43 |
features = datasets.Features(
|
| 44 |
{
|
|
@@ -49,6 +59,17 @@ class Prostate158Dataset(datasets.GeneratorBasedBuilder):
|
|
| 49 |
"adc_tumor_reader1_path": datasets.Value(dtype="string"),
|
| 50 |
}
|
| 51 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
return datasets.DatasetInfo(
|
| 54 |
description=_DESCRIPTION,
|
|
@@ -89,16 +110,32 @@ class Prostate158Dataset(datasets.GeneratorBasedBuilder):
|
|
| 89 |
images_list = ["t2", "adc", "dwi", "t2_anatomy_reader1", "adc_tumor_reader1"]
|
| 90 |
df = pd.read_csv(downloaded_files / f"{split}.csv")
|
| 91 |
if self.config.name == "2d":
|
|
|
|
|
|
|
|
|
|
| 92 |
yield_index = -1
|
| 93 |
for row in df.to_dict(orient="records"):
|
| 94 |
images_data = {image_name: nib.load(downloaded_files / row[image_name]).get_fdata() for image_name in images_list}
|
| 95 |
-
# print("example_shape", images_data["t2"].shape)
|
| 96 |
for i in range(images_data["t2"].shape[2]):
|
| 97 |
yield_index += 1
|
| 98 |
yield yield_index, {image_name: Image.fromarray(image[:, :, i]) for image_name, image in images_data.items()}
|
| 99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
elif self.config.name == "3d_path":
|
| 101 |
for idx, row in enumerate(df.to_dict(orient="records")):
|
| 102 |
-
|
| 103 |
-
yield idx, images_data
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import datasets
|
| 2 |
from typing import List
|
| 3 |
+
|
| 4 |
import pandas as pd
|
| 5 |
import numpy as np
|
| 6 |
from pathlib import Path
|
| 7 |
import os
|
|
|
|
| 8 |
|
| 9 |
_DESCRIPTION = "Prostate dataset."
|
| 10 |
|
|
|
|
| 25 |
|
| 26 |
]
|
| 27 |
|
| 28 |
+
DEFAULT_CONFIG_NAME = "3d_path"
|
| 29 |
|
| 30 |
def _info(self):
|
| 31 |
if self.config.name == "2d":
|
|
|
|
| 38 |
"adc_tumor_reader1": datasets.Image(),
|
| 39 |
}
|
| 40 |
)
|
| 41 |
+
elif self.config.name == "2d_array":
|
| 42 |
+
features = datasets.Features(
|
| 43 |
+
{
|
| 44 |
+
"t2": datasets.Array2D(),
|
| 45 |
+
"adc": datasets.Array2D(),
|
| 46 |
+
"dwi": datasets.Array2D(),
|
| 47 |
+
"t2_anatomy_reader1": datasets.Array2D(),
|
| 48 |
+
"adc_tumor_reader1": datasets.Array2D(),
|
| 49 |
+
}
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
elif self.config.name == "3d_path":
|
| 53 |
features = datasets.Features(
|
| 54 |
{
|
|
|
|
| 59 |
"adc_tumor_reader1_path": datasets.Value(dtype="string"),
|
| 60 |
}
|
| 61 |
)
|
| 62 |
+
|
| 63 |
+
elif self.config.name == "3d_array":
|
| 64 |
+
features = datasets.Features(
|
| 65 |
+
{
|
| 66 |
+
"t2": datasets.Array3D(),
|
| 67 |
+
"adc": datasets.Array3D(),
|
| 68 |
+
"dwi": datasets.Array3D(),
|
| 69 |
+
"t2_anatomy_reader1": datasets.Array3D(),
|
| 70 |
+
"adc_tumor_reader1": datasets.Array3D(),
|
| 71 |
+
}
|
| 72 |
+
)
|
| 73 |
|
| 74 |
return datasets.DatasetInfo(
|
| 75 |
description=_DESCRIPTION,
|
|
|
|
| 110 |
images_list = ["t2", "adc", "dwi", "t2_anatomy_reader1", "adc_tumor_reader1"]
|
| 111 |
df = pd.read_csv(downloaded_files / f"{split}.csv")
|
| 112 |
if self.config.name == "2d":
|
| 113 |
+
import nibabel as nib
|
| 114 |
+
from PIL import Image # moving imports here to not require unnecessary packages to other users
|
| 115 |
+
|
| 116 |
yield_index = -1
|
| 117 |
for row in df.to_dict(orient="records"):
|
| 118 |
images_data = {image_name: nib.load(downloaded_files / row[image_name]).get_fdata() for image_name in images_list}
|
|
|
|
| 119 |
for i in range(images_data["t2"].shape[2]):
|
| 120 |
yield_index += 1
|
| 121 |
yield yield_index, {image_name: Image.fromarray(image[:, :, i]) for image_name, image in images_data.items()}
|
| 122 |
|
| 123 |
+
elif self.config.name == "2d_array":
|
| 124 |
+
import nibabel as nib
|
| 125 |
+
|
| 126 |
+
yield_index = -1
|
| 127 |
+
for row in df.to_dict(orient="records"):
|
| 128 |
+
images_data = {image_name: nib.load(downloaded_files / row[image_name]).get_fdata() for image_name in images_list}
|
| 129 |
+
for i in range(images_data["t2"].shape[2]):
|
| 130 |
+
yield_index += 1
|
| 131 |
+
yield yield_index, {image_name: image[:, :, i] for image_name, image in images_data.items()}
|
| 132 |
+
|
| 133 |
elif self.config.name == "3d_path":
|
| 134 |
for idx, row in enumerate(df.to_dict(orient="records")):
|
| 135 |
+
yield idx, {image_name+"_path": downloaded_files / row[image_name] for image_name in images_list}
|
|
|
|
| 136 |
|
| 137 |
+
elif self.config.name == "3d_array":
|
| 138 |
+
import nibabel as nib
|
| 139 |
+
|
| 140 |
+
for idx, row in enumerate(df.to_dict(orient="records")):
|
| 141 |
+
yield idx, {image_name: nib.load(downloaded_files / row[image_name]).get_fdata() for image_name in images_list}
|