The following error which I can’t able to get rid of while developing the convolution model. Can someone help me out with this?
GRADED FUNCTION: convolutional_model
def convolutional_model(input_shape):
“”"
Implements the forward propagation for the model:
CONV2D → RELU → MAXPOOL → CONV2D → RELU → MAXPOOL → FLATTEN → DENSE
Note that for simplicity and grading purposes, you'll hard-code some values
such as the stride and kernel (filter) sizes.
Normally, functions should take these values as function parameters.
Arguments:
input_img -- input dataset, of shape (input_shape)
Returns:
model -- TF Keras model (object containing the information for the entire training process)
"""
input_img = tf.keras.Input(shape=input_shape),
## CONV2D: 8 filters 4x4, stride of 1, padding 'SAME'
Z1 = tfl.Conv2D(filters=8,kernel_size=(4,4),strides=(1,1), padding='same')(input_img),
## RELU
A1 = tfl.ReLU()(Z1),
## MAXPOOL: window 8x8, stride 8, padding 'SAME'
P1 = tfl.MaxPool2D(pool_size=(8,8), strides=(8,8), padding='same')(A1),
## CONV2D: 16 filters 2x2, stride 1, padding 'SAME'
Z2 =tfl.Conv2D(16,(2,2),strides=(1,1), padding='same')(P1),
## RELU
A2 =tfl.ReLU()(Z2),
## MAXPOOL: window 4x4, stride 4, padding 'SAME'
P2 = tfl.MaxPool2D(pool_size=(4,4), strides=(4,4), padding='same')(A2),
## FLATTEN
F = tfl.Flatten()(P2),
## Dense layer
## 6 neurons in output layer. Hint: one of the arguments should be "activation='softmax'"
outputs = tfl.Dense(6,activation='softmax')(F)
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
model = tf.keras.Model(inputs=input_img, outputs=outputs)
return model
Error:
TypeError Traceback (most recent call last)
in
----> 1 conv_model = convolutional_model((64, 64, 3))
2 conv_model.compile(optimizer=‘adam’,
3 loss=‘categorical_crossentropy’,
4 metrics=[‘accuracy’])
5 conv_model.summary()
in convolutional_model(input_shape)
18 input_img = tf.keras.Input(shape=input_shape),
19 ## CONV2D: 8 filters 4x4, stride of 1, padding ‘SAME’
—> 20 Z1 = tfl.Conv2D(filters=8,kernel_size=(4,4),strides=(1,1), padding=‘same’)(input_img),
21 ## RELU
22 A1 = tfl.ReLU()(Z1),
/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.
TypeError: Dimension value must be integer or None or have an index method, got value ‘TensorShape([None, 64, 64, 3])’ with type ‘<class ‘tensorflow.python.framework.tensor_shape.TensorShape’>’