# Week 1 Convolution model application issue

**URL:** <https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567>\
**Category:** Convolutional Neural Networks\
**Tags:** coursera-platform\
**Created:** [October 1, 2021, 5:31pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567 "2021-10-01T17:31:04Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![brakenseddik](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@brakenseddik](https://community.deeplearning.ai/u/brakenseddik)\
**Post date:** [October 1, 2021, 5:31pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/1 "2021-10-01T17:31:04Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![jonaslalin](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jonaslalin/32/63_2.png) [@jonaslalin](https://community.deeplearning.ai/u/jonaslalin)\
**Post date:** [October 1, 2021, 5:50pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/2 "2021-10-01T17:50:21Z")

</div>

> [@brakenseddik](#):
>
> input\_shape = tf.keras.Input(X\_train\_orig.shape)
> 
> ```auto
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![brakenseddik](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@brakenseddik](https://community.deeplearning.ai/u/brakenseddik)\
**Post date:** [October 1, 2021, 6:38pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/3 "2021-10-01T18:38:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jonaslalin](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jonaslalin/32/63_2.png) [@jonaslalin](https://community.deeplearning.ai/u/jonaslalin)\
**Post date:** [October 1, 2021, 6:40pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/4 "2021-10-01T18:40:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brakenseddik](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@brakenseddik](https://community.deeplearning.ai/u/brakenseddik)\
**Post date:** [October 1, 2021, 6:45pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/5 "2021-10-01T18:45:30Z")

</div>

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

```auto
<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]

```

---

<div class="post-metadata">

**Author:** ![jonaslalin](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jonaslalin/32/63_2.png) [@jonaslalin](https://community.deeplearning.ai/u/jonaslalin)\
**Post date:** [October 1, 2021, 7:43pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/6 "2021-10-01T19:43:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brakenseddik](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@brakenseddik](https://community.deeplearning.ai/u/brakenseddik)\
**Post date:** [October 2, 2021, 7:01pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/7 "2021-10-02T19:01:37Z")

</div>

Still don’t understand what the issue is

---

<div class="post-metadata">

**Author:** ![jonaslalin](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jonaslalin/32/63_2.png) [@jonaslalin](https://community.deeplearning.ai/u/jonaslalin)\
**Post date:** [October 2, 2021, 7:07pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/8 "2021-10-02T19:07:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brakenseddik](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@brakenseddik](https://community.deeplearning.ai/u/brakenseddik)\
**Post date:** [October 2, 2021, 7:29pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/9 "2021-10-02T19:29:40Z")

</div>

```auto
    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]

---

<div class="post-metadata">

**Author:** ![jonaslalin](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/jonaslalin/32/63_2.png) [@jonaslalin](https://community.deeplearning.ai/u/jonaslalin)\
**Post date:** [October 2, 2021, 7:44pm UTC](https://community.deeplearning.ai/t/week-1-convolution-model-application-issue/44567/10 "2021-10-02T19:44:48Z")

</div>

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

```auto
    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](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Conv2D): Use 8 4 by 4 filters, stride 1, padding is “SAME”
- [ReLU](https://www.tensorflow.org/api_docs/python/tf/keras/layers/ReLU)
- [MaxPool2D](https://www.tensorflow.org/api_docs/python/tf/keras/layers/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](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Flatten) the previous output.
- Fully-connected ([Dense](https://www.tensorflow.org/api_docs/python/tf/keras/layers/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 &nbsp;|&nbsp; TensorFlow Core v2.6.0](https://www.tensorflow.org/api_docs/python/tf/keras/layers) and study the documentation.
