Week 1 assignment 2 typerror

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)
19 input_img = tf.keras.Input(shape=input_shape),
20 ## CONV2D: 8 filters 4x4, stride of 1, padding ‘SAME’
—> 21 Z1 = tf.keras.layers.Conv2D(filters = 8, kernel_size = 4, strides = (1,1), padding = ‘same’)(input_img),
22
23 #Z1 = None

/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)
1096 # Build layer if applicable (if the build method has been
1097 # overridden).
→ 1098 self._maybe_build(inputs)
1099 cast_inputs = self._maybe_cast_inputs(inputs, input_list)
1100

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in _maybe_build(self, inputs)
2641 # operations.
2642 with tf_utils.maybe_init_scope(self):
→ 2643 self.build(input_shapes) # pylint:disable=not-callable
2644 # We must set also ensure that the layer is marked as built, and the build
2645 # shape is stored since user defined build functions may not be calling

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/layers/convolutional.py in build(self, input_shape)
184
185 def build(self, input_shape):
→ 186 input_shape = tensor_shape.TensorShape(input_shape)
187 input_channel = self._get_input_channel(input_shape)
188 if input_channel % self.groups != 0:

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/tensor_shape.py in init(self, dims)
754 “”"
755 if isinstance(dims, (tuple, list)): # Most common case.
→ 756 self._dims = [Dimension(d) for d in dims]
757 elif dims is None:
758 self._dims = None

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/tensor_shape.py in (.0)
754 “”"
755 if isinstance(dims, (tuple, list)): # Most common case.
→ 756 self._dims = [Dimension(d) for d in dims]
757 elif dims is None:
758 self._dims = None

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/tensor_shape.py in init(self, value)
202 TypeError("Dimension value must be integer or None or have "
203 “an index method, got value ‘{0!r}’ with type ‘{1!r}’”
→ 204 .format(value, type(value))), None)
205 if self._value < 0:
206 raise ValueError("Dimension d must be >= 0" self._value)

/opt/conda/lib/python3.7/site-packages/six.py in raise_from(value, from_value)

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’>’

I think you can change the paratheses to brace like:[ 64, 64, 3]

I made changes but still getting same error

Looks like many other people have run into this exact error before [Programming Assignment: Convolutional Neural Networks: Application]

You’ll help yourself and save a lot of time if you learn how to use the forum search to your advantage. For example, I found the above thread quickly after searching on “Z1 =“

It may not be obvious from the error stack, but information in this thread [Tips for troubles with Sequential and Functional API syntax] may also prove useful both here and going forward in the Specialization.

In convolutional_model(), in the code for “Z1 = …”, you have a syntax error caused by the comma at the end of the line.