Image Segmentation


I have a mistake in the third exercise, but I don’t understand why.

this is part of the code

inputs = Input(input_size)
# Contracting Path (encoding)
# Add a conv_block with the inputs of the unet_ model and n_filters
cblock1 = conv_block(inputs, n_filters)
# Chain the first element of the output of each block to be the input of the next conv_block.
# Double the number of filters at each new step
cblock2 = conv_block(cblock1, n_filters=2*n_filters)

and this is the error explanation

ValueError Traceback (most recent call last)
4 num_channels = 3
----> 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)
17 # Chain the first element of the output of each block to be the input of the next conv_block.
18 # Double the number of filters at each new step
—> 19 cblock2 = conv_block(cblock1, n_filters=2n_filters)
20 cblock3 = conv_block(cblock2, n_filters=4
21 cblock4 = conv_block(cblock3, n_filters=6*n_filters, dropout_prob=0.3) # Include a dropout of 0.3 for this layer

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

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ 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)
928 # Maintains info about the stack.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ 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,
1093 graph = backend.get_graph()
1094 # Use self._name_scope() to avoid auto-incrementing the name.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/ 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_113 expects 1 inputs, but it received 2 input tensors. Inputs received: [<tf.Tensor ‘max_pooling2d_36/MaxPool:0’ shape=(None, 48, 64, 32) dtype=float32>, <tf.Tensor ‘conv2d_112/Relu:0’ shape=(None, 96, 128, 32) dtype=float32>]

I had been stuck for hours, and still, I don’t understand the error. So I appreciate you could help me with this.



Hi Carlos,

Look at what a call to conv_block() returns. What do you need from this at this point?

1 Like

I appreciate your help. I forgot that conv_block() has a skip layer and a next layer output.

Thank you,


1 Like

Hello there. I am still stuck on this and it is giving me the same error.

@RizzyG: please read the instructions again more carefully. Where does it say that cblock5 has the same number of filters as cblock4?

Also note that the output of conv_block is a 2-tuple, right? You don’t want to pass the whole 2-tuple to the next layer: at each layer you need to select the appropriate input (which is the point that was discussed earlier on this thread).

Also please note that the rules of this course say we are not supposed to publish our solution code in public places (correct or not). But I admit that it sure makes it easier to debug when you can see the actual code! :scream_cat:

My apologies. Thank you for the assistance!

No worries! Thanks for editing your post to remove the code!