Here is the code I wrote as per the instructions, but I am getting an error. Please help.
def happyModel():
“”"
Implements the forward propagation for the binary classification model:
ZEROPAD2D → CONV2D → BATCHNORM → RELU → MAXPOOL → FLATTEN → DENSE
Note that for simplicity and grading purposes, you'll hard-code all the values
such as the stride and kernel (filter) sizes.
Normally, functions should take these values as function parameters.
Arguments:
None
Returns:
model -- TF Keras model (object containing the information for the entire training process)
"""
model = tf.keras.Sequential([
## ZeroPadding2D with padding 3, input shape of 64 x 64 x 3
## Conv2D with 32 7x7 filters and stride of 1
## BatchNormalization for axis 3
## ReLU
## Max Pooling 2D with default parameters
## Flatten layer
## Dense layer with 1 unit for output & 'sigmoid' activation
# YOUR CODE STARTS HERE
tfl.ZeroPadding2D(padding=3),
tfl.Conv2D(32,7,strides=1),
tfl.BatchNormalization(axis=3),
tfl.ReLU(),
tfl.MaxPool2D(pool_size=(2,2),padding= 'valid'),
tfl.Flatten(data_format= None),
tfl.Dense(1,activation= 'sigmoid'),
# YOUR CODE ENDS HERE
])
return model
happy_model = happyModel()
Print a summary for each layer
for layer in summary(happy_model):
print(layer)
output = [[‘ZeroPadding2D’, (None, 70, 70, 3), 0, ((3, 3), (3, 3))],
[‘Conv2D’, (None, 64, 64, 32), 4736, ‘valid’, ‘linear’, ‘GlorotUniform’],
[‘BatchNormalization’, (None, 64, 64, 32), 128],
[‘ReLU’, (None, 64, 64, 32), 0],
[‘MaxPooling2D’, (None, 32, 32, 32), 0, (2, 2), (2, 2), ‘valid’],
[‘Flatten’, (None, 32768), 0],
[‘Dense’, (None, 1), 32769, ‘sigmoid’]]
comparator(summary(happy_model), output)
ERROR message is:
AttributeError Traceback (most recent call last)
in
1 happy_model = happyModel()
2 # Print a summary for each layer
----> 3 for layer in summary(happy_model):
4 print(layer)
5
~/work/release/W1A2/test_utils.py in summary(model)
30 result =
31 for layer in model.layers:
—> 32 descriptors = [layer.class.name, layer.output_shape, layer.count_params()]
33 if (type(layer) == Conv2D):
34 descriptors.append(layer.padding)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in output_shape(self)
2177 “”"
2178 if not self._inbound_nodes:
→ 2179 raise AttributeError('The layer has never been called ’
2180 ‘and thus has no defined output shape.’)
2181 all_output_shapes = set(
AttributeError: The layer has never been called and thus has no defined output shape.