U net model error

Hi
I am getting the following error.

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, n_filters2)
22 cblock3 = conv_block(cblock2, n_filters
4)
23 cblock4 = conv_block(cblock3, n_filters*8, dropout_prob=.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_65 expects 1 inputs, but it received 2 input tensors. Inputs received: [<tf.Tensor 'max_pooling2d_26/Max

For each conv_block() layer, the argument must be the [0] element of the previous cblock.

Okay did that now i am getting this error.

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)
34 # Note that you must use the second element of the contractive block i.e before the maxpooling layer.
35 # At each step, use half the number of filters of the previous block
—> 36 ublock7 = upsampling_block(ublock6[0], cblock5[1], n_filters4)
37 ublock8 = upsampling_block(ublock7[0], ublock6[1], n_filters
2)
38 ublock9 = upsampling_block(ublock8[0], ublock7[1], n_filters*1)

in upsampling_block(expansive_input, contractive_input, n_filters)
18 3, # Kernel size
19 strides= (2,2),
—> 20 padding=‘same’)(expansive_input)
21
22 # Merge the previous output and the contractive_input

/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)
194 ‘, found ndim=’ + str(ndim) +
195 '. Full shape received: ’ +
→ 196 str(x.shape.as_list()))
197 # Check dtype.
198 if spec.dtype is not None:

ValueError: Input 0 of layer conv2d_transpose_12 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: [12, 16, 256]

Manage to solve. the indexing is so confusing .

I had the same issue. If anybody’s struggling with this:

  • pay attention to the output of the upsampling_block() function. It has only one item, unlike the conv_block which returns two items.

I hope this helps.