Course 4 Week 3 Assignment 2 U-Net - Test Error

Hello dear team,

I’m trying to solve the “Image_segmentation_Unet_v2” programming task.
All previous tasks work fine. But when putting the model together (Task 3.4 - Build the Model) I get the following test error result:

Test failed
Expected value

[‘Conv2D’, (None, 96, 128, 23), 759, ‘same’, ‘linear’, ‘GlorotUniform’]

does not match the input value:

[‘Conv2D’, (None, 96, 128, 32), 1056, ‘same’, ‘linear’, ‘GlorotUniform’]


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

/tf/W3A2/test_utils.py in comparator(learner, instructor)
19 “\n\n does not match the input value: \n\n”,
20 colored(f"{a}", “red”))
—> 21 raise AssertionError(“Error in test”)
22 print(colored(“All tests passed!”, “green”))
23

AssertionError: Error in test

When adding some prints for the shapes it shows the following:

encoding
cblock1[0]: Tensor(“max_pooling2d_78/MaxPool:0”, shape=(None, 48, 64, 32), dtype=float32)
cblock2[0]: Tensor(“max_pooling2d_79/MaxPool:0”, shape=(None, 24, 32, 64), dtype=float32)
cblock3[0]: Tensor(“max_pooling2d_80/MaxPool:0”, shape=(None, 12, 16, 128), dtype=float32)
cblock4[0]: Tensor(“max_pooling2d_81/MaxPool:0”, shape=(None, 6, 8, 256), dtype=float32)
cblock5[0]: Tensor(“dropout_40/cond/Identity:0”, shape=(None, 6, 8, 512), dtype=float32)
2nd index
cblock1[1]: Tensor(“conv2d_391/Relu:0”, shape=(None, 96, 128, 32), dtype=float32)
cblock2[1]: Tensor(“conv2d_393/Relu:0”, shape=(None, 48, 64, 64), dtype=float32)
cblock3[1]: Tensor(“conv2d_395/Relu:0”, shape=(None, 24, 32, 128), dtype=float32)
cblock4[1]: Tensor(“dropout_39/cond/Identity:0”, shape=(None, 12, 16, 256), dtype=float32)
cblock5[1]: Tensor(“dropout_40/cond/Identity:0”, shape=(None, 6, 8, 512), dtype=float32)
decoding
ublock6: Tensor(“conv2d_401/Relu:0”, shape=(None, 12, 16, 256), dtype=float32)
ublock7: Tensor(“conv2d_403/Relu:0”, shape=(None, 24, 32, 128), dtype=float32)
ublock8: Tensor(“conv2d_405/Relu:0”, shape=(None, 48, 64, 64), dtype=float32)
ublock9: Tensor(“conv2d_407/Relu:0”, shape=(None, 96, 128, 32), dtype=float32)

Any hints for me?
Thank you for looking into this.

1 Like

@knoell I think you have not given proper filters …for every layers multiply n_filters with 2, 4,8,16
and in decoding path multiply with 8,4,2 ,1

1 Like

Hi. Thanks for the suggestion, but I have exactly those filters.

    cblock1:  n_filters=n_filters
    cblock2:  n_filters*1*2
    cblock3:  n_filters*2*2
    cblock4:  n_filters*4*2 
    cblock5:  n_filters*8*2

and with ublocks 8,4,2,1 as decoding.

Just curious, why do you use “8 * 2” instead of just “16”?

1 Like

Also are you using “n_filters=…” for each cblock?

1 Like

I only use n_filters = n_filters for the first one, “cblock1”. It seems that it isn’t necessary, but I like the information there (which argument is set with n_filters).

After I did find out that cblock1 was included in that “mul 2” pattern, I needed to multiply by 2 for each filter.

If I interpret the prints with the shapes correctly, my version does not even reach the original filter number of 1024 at the bottom of the U-Net (cblock5). Or am I mistaken…?

I get the same values as you do for the cblock and ublock layers.
But that’s not where the problem is.
I think the error is being thrown by the last Conv2D layer, the one labeled “conv10 = …”.

It would be helpful if you post your layer summary data, instead of prints of the shapes.

The code implemented doesn’t use 1024, it stops at 512. That’s an error in Figure 2 in the instructions.

I do that with:

for layer in summary(model):
      print(layer)

[‘InputLayer’, [(None, 96, 128, 3)], 0]
[‘Conv2D’, (None, 96, 128, 32), 896, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 96, 128, 32), 9248, ‘same’, ‘relu’, ‘HeNormal’]
[‘MaxPooling2D’, (None, 48, 64, 32), 0, (2, 2)]
[‘Conv2D’, (None, 48, 64, 64), 18496, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 48, 64, 64), 36928, ‘same’, ‘relu’, ‘HeNormal’]
[‘MaxPooling2D’, (None, 24, 32, 64), 0, (2, 2)]
[‘Conv2D’, (None, 24, 32, 128), 73856, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 24, 32, 128), 147584, ‘same’, ‘relu’, ‘HeNormal’]
[‘MaxPooling2D’, (None, 12, 16, 128), 0, (2, 2)]
[‘Conv2D’, (None, 12, 16, 256), 295168, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 12, 16, 256), 590080, ‘same’, ‘relu’, ‘HeNormal’]
[‘Dropout’, (None, 12, 16, 256), 0, 0.3]
[‘MaxPooling2D’, (None, 6, 8, 256), 0, (2, 2)]
[‘Conv2D’, (None, 6, 8, 512), 1180160, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 6, 8, 512), 2359808, ‘same’, ‘relu’, ‘HeNormal’]
[‘Dropout’, (None, 6, 8, 512), 0, 0.3]
[‘Conv2DTranspose’, (None, 12, 16, 256), 1179904]
[‘Concatenate’, (None, 12, 16, 512), 0]
[‘Conv2D’, (None, 12, 16, 256), 1179904, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 12, 16, 256), 590080, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2DTranspose’, (None, 24, 32, 128), 295040]
[‘Concatenate’, (None, 24, 32, 256), 0]
[‘Conv2D’, (None, 24, 32, 128), 295040, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 24, 32, 128), 147584, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2DTranspose’, (None, 48, 64, 64), 73792]
[‘Concatenate’, (None, 48, 64, 128), 0]
[‘Conv2D’, (None, 48, 64, 64), 73792, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 48, 64, 64), 36928, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2DTranspose’, (None, 96, 128, 32), 18464]
[‘Concatenate’, (None, 96, 128, 64), 0]
[‘Conv2D’, (None, 96, 128, 32), 18464, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 96, 128, 32), 9248, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 96, 128, 32), 9248, ‘same’, ‘relu’, ‘HeNormal’]
[‘Conv2D’, (None, 96, 128, 32), 1056, ‘same’, ‘linear’, ‘GlorotUniform’]

In the very last Conv2D() layer, where you have 32, it should be 23.

Please post your code for the “conv10 = …” line.

Thanks TMosh, you are very right. I mixed up n_classes with n_filters. Problem solved. :slight_smile:

1 Like