deepmedic / dense3dCrf

Fully-connected (dense) 3D CRF for processing biomedical scans
Other
137 stars 48 forks source link

dense3dCrf: single modality #4

Open dspdavinci opened 6 years ago

dspdavinci commented 6 years ago

Hello Kamnitsask,

Thank you for sharing your work. I add dense3dCrf to the output of a 3d CNN segmentation model as below and receive an error. What do I miss in crf configuration?

Thanks!

import dense_crf
import nibabel
import numpy as np
import nibabel as nib

# I is image
# P is cnn output
I = np.load('test_X.npy')
P = np.load('test_y_hat.npy')

# somehow, crf requires I to be int8 and P to be float32
I = I * 255
I[I < 0] = 0
I[I > 255] = 255

# try to expand dimension
I = np.expand_dims(I, axis=-1)
P = np.expand_dims(P, axis=-1)

I = np.asarray(I, np.uint8)
P = np.asarray(P, np.float32)

# sanity check
print('type I: {}, shape I: {}, dtype: {}'.format(type(I), I.shape, I.dtype))
print('type P: {}, shape P: {}, dtype: {}'.format(type(P), P.shape, P.dtype))

dense_crf_param = {}
dense_crf_param['MaxIterations'] = 2.0
dense_crf_param['PosRStd'] = 3.0
dense_crf_param['PosCStd'] = 3.0
dense_crf_param['PosZStd'] = 3.0
dense_crf_param['PosW'] = 1.0
dense_crf_param['ModalityNum'] = 1
dense_crf_param['BilateralRStd'] = 5.0
dense_crf_param['BilateralCStd'] = 5.0
dense_crf_param['BilateralZStd'] = 5.0
dense_crf_param['BilateralW'] = 3.0
dense_crf_param['BilateralModsStds'] = 3.0

print('crf config ok')

# inference
y_hat_crf = dense_crf.dense_crf(I, P, dense_crf_param)

Output

type I: <type 'numpy.ndarray'>, shape I: (512, 512, 360, 1), dtype: uint8 type P: <type 'numpy.ndarray'>, shape P: (512, 512, 360, 1), dtype: float32 crf config ok MaxIterations :2 PosRStd :3 PosCStd :3 PosZStd :3 PosW :1 BilateralRStd :5 BilateralCStd :5 BilateralZStd :5 ModalityNum :1 BilateralW :3

input data channel 1 and BilateralModsStds size 0 do not match Traceback (most recent call last): File "\<stdin>", line 47, in SystemError: error return without exception set

MiguelAngeloMartinsRibeiro commented 2 years ago

Hello @dspdavinci I want to apply 3dcrf to a 3D matrix of segmentation masks I think what you've done it's pretty similiar to what I want Did you have results? Could you use it?

Thank you for your time