Week 1 Convolution model application issue

Hello everyone,
I have an issue with the second assignment of week 1
I get this error
ValueError: Input 0 of layer max_pool is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [None, 600, 64, 64, 32]

here my code:
input_shape = tf.keras.Input(X_train_orig.shape)

X = tf.keras.layers.Activation('relu')(X) 

X = tf.keras.layers.MaxPooling2D(pool_size=(2,2),strides=None, name='max_pool')(X)

doesnt look right and i dont see where you are supposed to use pool of 2,2?

WHAT do you mean, what’s wrong with max pooling?

If you read the instructions, do they specify a pool size of (2,2)?

i removed the size 2,2 and i still see the same error

<ipython-input-35-b08309b8f7f0> in happyModel()
     23     X = tf.keras.layers.Activation('relu')(X)
     24 
---> 25     X = tf.keras.layers.MaxPooling2D(name='max_pool')(X)
     26 
     27     X = tf.keras.layers.Flatten()(X)

/opt/conda/lib/python3.7/site-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.

/opt/conda/lib/python3.7/site-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.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name)
    178                          'expected ndim=' + str(spec.ndim) + ', found ndim=' +
    179                          str(ndim) + '. Full shape received: ' +
--> 180                          str(x.shape.as_list()))
    181     if spec.max_ndim is not None:
    182       ndim = x.shape.ndims

ValueError: Input 0 of layer max_pool is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [None, 600, 64, 64, 32]

Double check your implementation against the instructions again very carefully. You are probably missing something else also.

Still don’t understand what the issue is

Post the code for the failing method here and I will see if I spot something.

    input_shape = tf.keras.Input(X_train_orig.shape)
    X = tf.keras.layers.Conv2D(filters=32, kernel_size=(3, 3), strides = (1, 1), padding='same', name = 'conv')(input_shape)
    X = tf.keras.layers.BatchNormalization(axis = 3, name = 'bn')(X)
    X = tf.keras.layers.Activation('relu')(X) 
 
    X = tf.keras.layers.MaxPooling2D(name='max_pool')(X)
     
    X = tf.keras.layers.Flatten()(X)
    X = tf.keras.layers.Dense(units=1, activation='sigmoid', name='fc')(X)
      
    # Create model. This creates your Keras model instance, you'll use this instance to train/test the model.
    model = Model(inputs = input_shape, outputs = X, name='happyModel')

ValueError: Input 0 of layer max_pool is incompatible with the layer: expected ndim=4, found ndim=5. Full shape received: [None, 600, 64, 64, 32]

As I said before, you have not followed the instructions:

    input_img = tf.keras.Input(shape=input_shape)
    ## CONV2D: 8 filters 4x4, stride of 1, padding 'SAME'
    # Z1 = None
    ## RELU
    # A1 = None
    ## MAXPOOL: window 8x8, stride 8, padding 'SAME'
    # P1 = None
    ## CONV2D: 16 filters 2x2, stride 1, padding 'SAME'
    # Z2 = None
    ## RELU
    # A2 = None
    ## MAXPOOL: window 4x4, stride 4, padding 'SAME'
    # P2 = None
    ## FLATTEN
    # F = None
    ## Dense layer
    ## 6 neurons in output layer. Hint: one of the arguments should be "activation='softmax'" 
    # outputs = None
    model = tf.keras.Model(inputs=input_img, outputs=outputs)
    return model

Implement the convolutional_model function below to build the following model: CONV2D -> RELU -> MAXPOOL -> CONV2D -> RELU -> MAXPOOL -> FLATTEN -> DENSE . Use the functions above!

Also, plug in the following parameters for all the steps:

  • Conv2D: Use 8 4 by 4 filters, stride 1, padding is “SAME”
  • ReLU
  • MaxPool2D: Use an 8 by 8 filter size and an 8 by 8 stride, padding is “SAME”
  • Conv2D : Use 16 2 by 2 filters, stride 1, padding is “SAME”
  • ReLU
  • MaxPool2D : Use a 4 by 4 filter size and a 4 by 4 stride, padding is “SAME”
  • Flatten the previous output.
  • Fully-connected (Dense) layer: Apply a fully connected layer with 6 neurons and a softmax activation.

If you look at your implementation and compare it to the lab instructions, you see several differences.

Are you unsure about what paramters to use for each laye, go to Module: tf.keras.layers  |  TensorFlow Core v2.6.0 and study the documentation.