titu1994 / Fully-Connected-DenseNets-Semantic-Segmentation

Fully Connected DenseNet for Image Segmentation (https://arxiv.org/pdf/1611.09326v1.pdf)
84 stars 41 forks source link

TF bug #5

Closed ahundt closed 7 years ago

ahundt commented 7 years ago

I tried training this in TF and ran into the following bug:


I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:02:00.0)
Running with tf training, initializing batches...
creating densenet model
Traceback (most recent call last):
  File "densenet_fcn.py", line 134, in <module>
    model = get_model(image_train_size=image_train_size,model_type=model_type,tensor=image_batch)
  File "densenet_fcn.py", line 50, in get_model
    model = densenet_fc.create_fc_dense_net(number_of_classes,image_train_size)
  File "/home/ahundt/src/tf-image-segmentation/tf_image_segmentation/models/densenet_fcn/densenet_fc.py", line 260, in create_fc_dense_net
    x = transition_up_block(x, nb_filters=upsampling_conv, type=upscaling_type, output_shape=out_shape)
  File "/home/ahundt/src/tf-image-segmentation/tf_image_segmentation/models/densenet_fcn/densenet_fc.py", line 97, in transition_up_block
    x = SubPixelUpscaling(r=2, channels=int(nb_filters // 4))(x)
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.2.2-py2.7.egg/keras/engine/topology.py", line 572, in __call__
    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.2.2-py2.7.egg/keras/engine/topology.py", line 635, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/usr/local/lib/python2.7/dist-packages/Keras-1.2.2-py2.7.egg/keras/engine/topology.py", line 166, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
  File "/home/ahundt/src/tf-image-segmentation/tf_image_segmentation/models/densenet_fcn/layers.py", line 70, in call
    y = depth_to_scale_tf(x, self.r, self.channels)
  File "/home/ahundt/src/tf-image-segmentation/tf_image_segmentation/models/densenet_fcn/layers.py", line 48, in depth_to_scale_tf
    Xc = tf.split(3, channels, input)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 1216, in split
    split_dim=axis, num_split=num_or_size_splits, value=value, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 3426, in _split
    num_split=num_split, name=name)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 509, in apply_op
    (prefix, dtypes.as_dtype(input_arg.type).name))
TypeError: Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32.

The code successfully trains for a while on pascal-voc with a simpler U-net: https://github.com/ahundt/tf-image-segmentation/blob/ahundt-keras/tf_image_segmentation/recipes/pascal_voc/FCNs/densenet_fcn.py

titu1994 commented 7 years ago

@ahundt It's a bug with the SubPixelConvolutionLayer. I have to find some to fix it, or at least swap it out for a play UpSampling layer.

For now. you can try swapping out SubPixelConvolutionLayer with the Keras UpSampling layer. There's a repository called Tetrachrome which was the original implementation. I wonder if they fixed the bug in the Tensorflow backend.

Sorry for the trouble.

ahundt commented 7 years ago

I think it is a matter of the type being passed in being an in32 vs flot32. I wonder where I can fix the flag. There have been some code changes as well since you put that in but they look relatively minor.

ahundt commented 7 years ago

I've started looking into this and it is possible the issue is related to the following: https://github.com/tensorflow/tensorflow/issues/4590

samtzai commented 7 years ago

Its because of a change on tf parameters order on the split function. I will try to provide sth

samtzai commented 7 years ago

I have checked current version and it is working with tf and just minor change needed to make it work on keras 2. Should this issue be closed?

ahundt commented 7 years ago

probably, this code is now at https://github.com/farizrahman4u/keras-contrib/blob/master/keras_contrib/applications/densenet.py