add config
Browse files- model_segvol_single.py +9 -0
model_segvol_single.py
CHANGED
|
@@ -2,6 +2,8 @@ from transformers import PreTrainedModel, PretrainedConfig
|
|
| 2 |
import numpy as np
|
| 3 |
import monai.transforms as transforms
|
| 4 |
import nibabel as nib
|
|
|
|
|
|
|
| 5 |
|
| 6 |
class SegVolConfig(PretrainedConfig):
|
| 7 |
model_type = "segvol"
|
|
@@ -199,6 +201,13 @@ class SegVolProcessor():
|
|
| 199 |
# transform
|
| 200 |
return item['image'], item['label']
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
def ForegroundNorm(self, ct_narray):
|
| 203 |
ct_voxel_ndarray = ct_narray.copy()
|
| 204 |
ct_voxel_ndarray = ct_voxel_ndarray.flatten()
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import monai.transforms as transforms
|
| 4 |
import nibabel as nib
|
| 5 |
+
from scipy import sparse
|
| 6 |
+
import ast
|
| 7 |
|
| 8 |
class SegVolConfig(PretrainedConfig):
|
| 9 |
model_type = "segvol"
|
|
|
|
| 201 |
# transform
|
| 202 |
return item['image'], item['label']
|
| 203 |
|
| 204 |
+
def load_uniseg_case(self, ct_npy_path, gt_npy_path):
|
| 205 |
+
img_array = np.load(ct_npy_path)
|
| 206 |
+
allmatrix_sp= sparse.load_npz(gt_npy_path)
|
| 207 |
+
gt_shape = ast.literal_eval(gt_npy_path.split('.')[-2])
|
| 208 |
+
gt_array=allmatrix_sp.toarray().reshape(gt_shape)
|
| 209 |
+
return img_array, gt_array
|
| 210 |
+
|
| 211 |
def ForegroundNorm(self, ct_narray):
|
| 212 |
ct_voxel_ndarray = ct_narray.copy()
|
| 213 |
ct_voxel_ndarray = ct_voxel_ndarray.flatten()
|