Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dense3dCrf: single modality #4

Open
dspdavinci opened this issue Jul 15, 2018 · 1 comment
Open

dense3dCrf: single modality #4

dspdavinci opened this issue Jul 15, 2018 · 1 comment

Comments

@dspdavinci
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants