codedecde / Luna2016-Lung-Nodule-Detection

Course Project for Bio Medical Imaging: Detecting Lung Nodules from CT Scans
MIT License
48 stars 29 forks source link

I got something wrong with class "Accuracy" #1

Open SouthMemory opened 7 years ago

SouthMemory commented 7 years ago

I got into some trouble when trying to train the model:

TypeError Traceback (most recent call last)

in () 207 if __name__ == '__main__': 208 # print "epochs" --> 209 model = train(False) in train(use_existing) 195 model = get_unet_small(options) 196 weight_save = WeightSave(options) --> 197 accuracy = Accuracy(copy.deepcopy(imgs_test),copy.deepcopy(imgs_mask_test_true)) 198 print('-'*30) 199 print('Fitting model...') in __init__(self, test_data_x, test_data_y) 154 pred = T.tensor4('pred') 155 print('pred.shape:',pred.shape) --> 156 dc = dice_coef(test,pred) 157 self.dc = theano.function([test,pred],dc) 158 in dice_coef(y_true, y_pred) 52 def dice_coef(y_true,y_pred): 53 print(y_true,y_pred) ---> 54 y_true = K.flatten(y_true) 55 y_pred = K.flatten(y_pred) 56 smooth = 0. /home/beichuan/anaconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.pyc in flatten(x) 1922 A tensor, reshaped into 1-D 1923 """ -> 1924 return tf.reshape(x, [-1]) 1925 1926 /home/beichuan/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.pyc in reshape(tensor, shape, name) 2508 """ 2509 result = _op_def_lib.apply_op("Reshape", tensor=tensor, shape=shape, -> 2510 name=name) 2511 return result 2512 /home/beichuan/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.pyc in apply_op(self, op_type_name, name, **keywords) 492 except TypeError as err: 493 if dtype is None: --> 494 raise err 495 else: 496 raise TypeError( TypeError: Expected binary or unicode string, got test It seems I can not flat or reshape y_true or y_pred, there is something wrong with their shape. I tried to print their shape, the result is as follows: Tensor("sigmoid_target_10:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("sigmoid_10/Sigmoid:0", shape=(?, 1, 512, 512), dtype=float32) Tensor("sigmoid_target_10:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("sigmoid_10/Sigmoid:0", shape=(?, 1, 512, 512), dtype=float32) Anybody tried this code and finished training? I just got confused and don't know where the problem is, thanks if someone can help!
codedecde commented 7 years ago

I had trained the models using the theano backend, so not sure about the TensorFlow backend. That said, I hope you changed line 22 of LUNA_unet.py K.set_image_dim_ordering('th') # Theano dimension ordering in this code To K.set_image_dim_ordering('tf') # Tensorflow dimension ordering.

SouthMemory commented 7 years ago

Hello,Thank you very much. I tried your advice, but it didn't work , some else error occured But one thing you are right is that the problem is about the backend So I tried to change my backend from tensorflow to theano, by editing /home/beichuan/.keras/keras.json, and then your code worked.

But I found that on my computer your code runs on CPU and not on GPUs, so it is quite slow for me. Did you run it on CPU or GPU? Did I miss something?

Thank you!

codedecde commented 7 years ago

On a K40 GPU. Make sure your theano configurations are correct. See Install and configure GPU drivers http://deeplearning.net/software/theano/install_ubuntu.html

bundelesneha05 commented 6 years ago

hello, I am facing some error while installing theano for gpu as follow, RuntimeError: To use MKL 2018 with Theano you MUST set "MKL_THREADING_LAYER=GNU" in your environement. how should I solve this?? Thanks in advance!

codedecde commented 6 years ago

https://github.com/Theano/Theano/issues/6507

bundelesneha05 commented 6 years ago

I got some error when i run the code by using theano backend as follow, RuntimeError: error getting worksize: CUDNN_STATUS_BAD_PARAM Apply node that caused the error: GpuDnnConv{algo='small', inplace=True, num_groups=1}(GpuContiguous.0, GpuContiguous.0, GpuAllocEmpty{dtype='float32', context_name=None}.0, GpuDnnConvDesc{border_mode='half', subsample=(1, 1), dilation=(1, 1), conv_mode='conv', precision='float32', num_groups=1}.0, Constant{1.0}, Constant{0.0}) Toposort index: 421 Inputs types: [GpuArrayType(float32, 4D), GpuArrayType(float32, 4D), GpuArrayType(float32, 4D), <theano.gof.type.CDataType object at 0x7fdbf1e086d0>, Scalar(float32), Scalar(float32)] Inputs shapes: [(2, 1, 512, 512), (32, 1, 3, 3), (2, 32, 512, 512), 'No shapes', (), ()] Inputs strides: [(1048576, 1048576, 2048, 4), (36, 36, 12, 4), (33554432, 1048576, 2048, 4), 'No strides', (), ()] Inputs values: ['not shown', 'not shown', 'not shown', <capsule object NULL at 0x7fdbce621d80>, 1.0, 0.0] Outputs clients: [[GpuElemwise{add,no_inplace}(GpuDnnConv{algo='small', inplace=True, num_groups=1}.0, InplaceGpuDimShuffle{x,0,x,x}.0)]]

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer): File "/home/coe/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile execfile(filename, namespace) File "/home/coe/anaconda2/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile builtins.execfile(filename, *where) File "/home/coe/UNET_CODE FROM GITHUB/Luna2016-Lung-Nodule-Detection-master/UNET/Code/LUNA_unet.py", line 219, in model = train(False) File "/home/coe/UNET_CODE FROM GITHUB/Luna2016-Lung-Nodule-Detection-master/UNET/Code/LUNA_unet.py", line 197, in train model = get_unet_small(options) File "/home/coe/UNET_CODE FROM GITHUB/Luna2016-Lung-Nodule-Detection-master/UNET/Code/LUNA_unet.py", line 80, in get_unet_small conv1 = Convolution2D(32, options.filter_width, options.stride, activation='elu',border_mode='same')(inputs) File "/home/coe/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 617, in call output = self.call(inputs, **kwargs) File "/home/coe/anaconda2/lib/python2.7/site-packages/keras/layers/convolutional.py", line 168, in call dilation_rate=self.dilation_rate) File "/home/coe/anaconda2/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 1916, in conv2d filter_dilation=dilation_rate)

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node. Thanks in advance!!