alexanderdann commited on
Commit
a4dfc3d
·
verified ·
1 Parent(s): f7f462d

Fixing changed loading script

Browse files
Files changed (1) hide show
  1. CTSpine1K.py +9 -9
CTSpine1K.py CHANGED
@@ -120,11 +120,11 @@ class CTSpine1K(datasets.GeneratorBasedBuilder):
120
  features = datasets.Features(
121
  {
122
  "image": datasets.Array3D(
123
- shape=(None, None, None),
124
  dtype="float32",
125
  ),
126
  "segmentation": datasets.Array3D(
127
- shape=(None, None, None),
128
  dtype="int32",
129
  ),
130
  "patient_id": datasets.Value("string"),
@@ -133,8 +133,8 @@ class CTSpine1K(datasets.GeneratorBasedBuilder):
133
  else:
134
  features = datasets.Features(
135
  {
136
- "image": datasets.Array2D(shape=(None, None), dtype="float32"),
137
- "segmentation": datasets.Array2D(shape=(None, None), dtype="int32"),
138
  "patient_id": datasets.Value("string"),
139
  },
140
  )
@@ -279,14 +279,14 @@ class CTSpine1K(datasets.GeneratorBasedBuilder):
279
  @staticmethod
280
  def _volumetric_sample(path: Path) -> np.ndarray:
281
  volume = nib.load(path)
282
-
283
- return volume.get_fdata()
284
 
285
  def _generate_examples(self, pairs: list[tuple[Path, Path]]) -> Generator:
286
  for volume_path, label_path in pairs:
287
  patient_id = Path(volume_path.stem).stem
288
  image = self._volumetric_sample(volume_path)
289
- segmentation = self._volumetric_sample(label_path)
290
 
291
  if self.config.volumetric:
292
  yield {
@@ -297,7 +297,7 @@ class CTSpine1K(datasets.GeneratorBasedBuilder):
297
  else:
298
  for idx in range(image.shape[2]): # iterate over axial slices
299
  yield {
300
- "image": image[:, :, idx],
301
- "segmentation": segmentation[:, :, idx],
302
  "patient_id": patient_id + f"_{idx}",
303
  }
 
120
  features = datasets.Features(
121
  {
122
  "image": datasets.Array3D(
123
+ shape=(None, 512, 512),
124
  dtype="float32",
125
  ),
126
  "segmentation": datasets.Array3D(
127
+ shape=(None, 512, 512),
128
  dtype="int32",
129
  ),
130
  "patient_id": datasets.Value("string"),
 
133
  else:
134
  features = datasets.Features(
135
  {
136
+ "image": datasets.Array2D(shape=(512, 512), dtype="float32"),
137
+ "segmentation": datasets.Array2D(shape=(512, 512), dtype="int32"),
138
  "patient_id": datasets.Value("string"),
139
  },
140
  )
 
279
  @staticmethod
280
  def _volumetric_sample(path: Path) -> np.ndarray:
281
  volume = nib.load(path)
282
+ volume = volume.get_fdata()
283
+ return np.transpose(volume, (2, 0, 1))
284
 
285
  def _generate_examples(self, pairs: list[tuple[Path, Path]]) -> Generator:
286
  for volume_path, label_path in pairs:
287
  patient_id = Path(volume_path.stem).stem
288
  image = self._volumetric_sample(volume_path)
289
+ segmentation = self._volumetric_sample(label_path).astype(np.uint32)
290
 
291
  if self.config.volumetric:
292
  yield {
 
297
  else:
298
  for idx in range(image.shape[2]): # iterate over axial slices
299
  yield {
300
+ "image": image[idx],
301
+ "segmentation": segmentation[idx],
302
  "patient_id": patient_id + f"_{idx}",
303
  }