orobix / retina-unet

Retina blood vessel segmentation with a convolutional neural network
1.26k stars 468 forks source link

Filter size error #6

Closed ilknuricke closed 7 years ago

ilknuricke commented 7 years ago

Hi,

Thanks for making this code available. I wanted to give this a quick look. I am on Mac OS, installed latest Keras and Tensorflow. Tried on python 3.5 after 2to3 for mostly the print statements.

Here is the error I am getting:

Using TensorFlow backend. I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.dylib locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.dylib locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.dylib locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.1.dylib locally I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.dylib locally

train images/masks shape: (20, 1, 565, 565) train images range (min-max): 0.0 - 1.0 train masks are within 0-1

patches per full image: 9500

train PATCHES images/masks shape: (190000, 1, 48, 48) train PATCHES images range (min-max): 0.0 - 1.0 I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:892] OS X does not support NUMA - returning NUMA node zero I tensorflow/core/common_runtime/gpu/gpu_init.cc:102] Found device 0 with properties: name: GeForce GT 650M major: 3 minor: 0 memoryClockRate (GHz) 0.9 pciBusID 0000:01:00.0 Total memory: 1023.69MiB Free memory: 25.46MiB I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0 I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: Y I tensorflow/core/common_runtime/gpu/gpu_device.cc:838] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GT 650M, pci bus id: 0000:01:00.0) Traceback (most recent call last): File "./src/retinaNN_training.py", line 107, in model = get_unet(n_ch, patch_height, patch_width) #the U-net model File "./src/retinaNN_training.py", line 34, in get_unet conv1 = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(inputs) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 514, in call self.add_inbound_node(inbound_layers, node_indices, tensor_indices) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 572, in add_inbound_node Node.create_node(self, inbound_layers, node_indices, tensor_indices) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 149, in create_node output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0])) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/layers/convolutional.py", line 466, in call filter_shape=self.W_shape) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 1579, in conv2d x = tf.nn.conv2d(x, kernel, strides, padding=padding) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 394, in conv2d data_format=data_format, name=name) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op op_def=op_def) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2319, in create_op set_shapes_for_outputs(ret) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1711, in set_shapes_for_outputs shapes = shape_func(op) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 246, in conv2d_shape padding) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 184, in get2d_conv_output_size (row_stride, col_stride), padding_type) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py", line 149, in get_conv_output_size "Filter: %r Input: %r" % (filter_size, input_size)) ValueError: Filter must not be larger than the input: Filter: (3, 3) Input: (1, 48)

ilknuricke commented 7 years ago

using latest keras and theano, I am getting a different error

Using Theano backend. WARNING (theano.configdefaults): Only clang++ is supported. With g++, we end up with strange g++/OSX bugs. Using gpu device 0: GeForce GT 650M (CNMeM is disabled, cuDNN 5005)

train images/masks shape: (20, 1, 565, 565) train images range (min-max): 0.0 - 1.0 train masks are within 0-1

patches per full image: 9500

train PATCHES images/masks shape: (190000, 1, 48, 48) train PATCHES images range (min-max): 0.0 - 1.0 Traceback (most recent call last): File "./src/retinaNN_training.py", line 107, in model = get_unet(n_ch, patch_height, patch_width) #the U-net model File "./src/retinaNN_training.py", line 48, in get_unet up1 = merge([UpSampling2D(size=(2, 2))(conv3), conv2], mode='concat', concat_axis=1) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 1528, in merge name=name) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 1186, in init node_indices, tensor_indices) File "/Users/ilknur/anaconda/lib/python3.5/site-packages/keras/engine/topology.py", line 1253, in _arguments_validation 'Layer shapes: %s' % (input_shapes)) Exception: "concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 0, 24, 128), (None, 0, 24, 64)]

ilknuricke commented 7 years ago

Actually, the issue was related to Keras and not about your code. Latest version of Keras is now using tensorflow by default--I just had to modify the keras,json file to use theano backend and theano dimension ordering as follows: { "floatx": "float32", "image_dim_ordering": "th", "backend": "theano", "epsilon": 1e-07 }

lantiga commented 7 years ago

Thanks for letting us know. At the very least, we will mention this in the README. Ideally we should modify the code to work with either Tensorflow and Theano as soon as we have time.

dcorti commented 7 years ago

I upgraded to latest keras (1.1.0), and looks fine for both backend: Theano and TensoFflow. The only problem is related to the dimension settings, so "image_dim_ordering" must be set to "th", as you pointed out. Thank you!