Image_segmentation_Unet_v2

Hello, can somebody help me figuring this error out?

ValueError Traceback (most recent call last)
in
4 num_channels = 3
5
----> 6 unet = unet_model((img_height, img_width, num_channels))
7 comparator(summary(unet), outputs.unet_model_output)

in unet_model(input_size, n_filters, n_classes)
19 # Chain the first element of the output of each block to be the input of the next conv_block.
20 # Double the number of filters at each new step
—> 21 cblock2 = conv_block(cblock1, 2n_filters)
22 cblock3 = conv_block(cblock2, 4
n_filters)
23 cblock4 = conv_block(cblock3, 8*n_filters, dropout=0.3) # Include a dropout of 0.3 for this layer

in conv_block(inputs, n_filters, dropout_prob, max_pooling)
19 activation=‘relu’,
20 padding=‘same’,
—> 21 kernel_initializer=‘he_normal’)(inputs)
22 conv = Conv2D(n_filters, # Number of filters
23 3, # Kernel size

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
924 if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
925 return self._functional_construction_call(inputs, args, kwargs,
→ 926 input_list)
927
928 # Maintains info about the Layer.call stack.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
1090 # TODO(reedwm): We should assert input compatibility after the inputs
1091 # are casted, not before.
→ 1092 input_spec.assert_input_compatibility(self.input_spec, inputs, self.name)
1093 graph = backend.get_graph()
1094 # Use self._name_scope() to avoid auto-incrementing the name.

/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
156 str(len(input_spec)) + ’ inputs, ’
157 'but it received ’ + str(len(inputs)) +
→ 158 ’ input tensors. Inputs received: ’ + str(inputs))
159 for input_index, (x, spec) in enumerate(zip(inputs, input_spec)):
160 if spec is None:

ValueError: Layer conv2d_28 expects 1 inputs, but it received 2 input tensors. Inputs received: [<tf.Tensor ‘max_pooling2d_10/MaxPool:0’ shape=(None, 48, 64, 32) dtype=float32>, <tf.Tensor ‘conv2d_27/Relu:0’ shape=(None, 96, 128, 32) dtype=float32>]

my code:

{moderator edit - solution code removed}

1 Like

I have the same error, I tried a bunch of stuff from changing he_normal to HeNormal, trying to keep cblock4 and cblock5 both have n_filters*8, but the error just transforms into some other conv_2d layer expects 1 input but got 2 input tensors.

Also what also confused me is why it said dropout= and not dropout_prob= since dropout_prob was the parameter we had in the conv_block function.

1 Like

I have no idea. I reviewed other related posts regarding this error, but I don’t understand their replies.
I hope one mentor helps us.

@paulinpaloalto, he explains simply to fix the error

1 Like

So Hey, I solved it. Look at the output of conv_block. And what does this imply for your inputs to cblock 2 to 4. Hope it helps!

1 Like

I do not get it. You mean that cblock2, 3, 4, 5 inputs should be different? how?

1 Like

conv_block outputs 2 things. You only need to pass the first output, i.e next layer into the next layer. And in the upsampling_block portion you need to pass the second output of conv_block i.e skip layer.

3 Likes

do you mean this : cblock2 = conv_block(cblock1[0], 2*n_filters) ??

1 Like

Yes, that’s right. Likewise in the second half.

1 Like

and this ublock7 = upsampling_block(cblock6[0], cblock3[1], 4*n_filters) for the second half ?

but I run this code too, and there is error as well.

TypeError: conv_block() got an unexpected keyword argument ‘dropout’

1 Like

in upsampling, why will your first input be cblock[0], won’t it be ublock6, because that is the previous layer. Also now that you’ve gotten a hang of it. Give it time you will figure it out. Directly telling you violates the honor code

2 Likes

Change dropout to dropout_prob

1 Like

@Jaskeerat has already shown us the solution here, but the same issues were discussed on this thread and this one and probably others.

1 Like

Thanks, I found the problem and fixed it.

Hey guys typical errors here are:

  1. dropout is redefined. So is not just dropout. Check how it is defined in conv_block()
  2. conv_block has 2 outputs, while upsampling_block just 1. Therefore it makes sense to use [0] or [1] in the former to call each of the outputs, but doesn’t make sense to use them when calling the latter.
2 Likes