DLS Course 4 W2 A2 Input layer shape is not correct

I am working on Exercise 2 the alpaca model and run into a problem with the input layer.

I get the following message:

Test failed

Expected value

[‘InputLayer’, [(None, 160, 160, 3)], 0]

does not match the input value:

[‘InputLayer’, [(1, 160, 160, 3)], 0]

With debugging I have found that the statement:

# create the input layer (Same as the imageNetv2 input size)

Returns a tensorflow object with the shape (None, 160, 160, 3)

The following statement:

# apply data augmentation to the inputs

Returns a tensorflow object with the shape (1, 160, 160, 3)

I do not know how to change the augmentation statement in order to have it return shape (None, 160, 160, 3)

Does anyone has a hint for me?

You code in alpaca_model() should call the data_augmentation() function.

I have programmed the model so that it calls the data_augmentation() function in the step:

# apply data augmentation to the inputs

x = data_augmentation…

the statement print(x) gives me: Tensor(“sequential_1/random_rotation_1/transform_28/ImageProjectiveTransformV2:0”, shape=(1, 160, 160, 3), dtype=float32)

The parameter passed to data_augmentation(…) should be “inputs”.

“inputs” should be a Keras Input object with the shape equal to the input_shape.

Tip: Don’t make things too complicated. There’s nothing tricky going on here.

Thanks for helping me out, but I have done that already. I have the following lines of code:

inputs = tf.keras.Input(shape=input_shape)
print(inputs)
x = data_augmentation(inputs)
print(x)

The print statements give:

Tensor("input_85:0", shape=(None, 160, 160, 3), dtype=float32)
Tensor("sequential_1/random_rotation_1/transform_38/ImageProjectiveTransformV2:0", shape=(1, 160, 160, 3), dtype=float32)

Because of the error message i described earlier my thought is that it is going wrong here.

Did you happen to modify this line of code?

If yes, that will cause problems.

Hi TMosh,

Thank you for your support. I did not change that line of code.

But now after a Kernel restart, the code runs without error. Not sure what the problem was, but I cannot recreate it. Thanks again for your help.

2 Likes

In a lot of these assignments in C4 and C5, the notebooks use global objects. So while you’re editing the notebook, any changes you make that modify a global object can cause runtime problems with previously tested code.

Often restarting the kernel and running all the cells again will straighten out these issues.