C1W3_Assignment Model Runs with >97% accuracy but utils throws error


AttributeError Traceback (most recent call last)
in
----> 1 utils.test_simple_quadratic(SimpleQuadratic)

~/work/release/W3_Assignment/utils.py in test_simple_quadratic(SimpleQuadratic)
42 test_call_value = test_layer.call(test_inputs)
43
—> 44 a_type = type(test_layer.a)
45 b_type = type(test_layer.b)
46 c_type = type(test_layer.c)

AttributeError: ‘SimpleQuadratic’ object has no attribute ‘a’

Please see if utils has an error. See actual code below:

class SimpleQuadratic(Layer):

def __init__(self, units=32, activation=None):
    '''Initializes the class and sets up the internal variables'''
    super(SimpleQuadratic,self).__init__()
    self.units = units
    self.activation = tf.keras.activations.get(activation)

def build(self, input_shape):
    '''Create the state of the layer (weights)'''
    # a and b should be initialized with random normal, c (or the bias) with zeros.
    # remember to set these as trainable.
    w_init = tf.random_normal_initializer()
    self.w = tf.Variable(name = 'kernel', initial_value = w_init(shape = (input_shape[-1],self.units), dtype = 'float32'), trainable = True)
    b_init = tf.zeros_initializer()
    self.b = tf.Variable(name = 'bias', initial_value = b_init(shape = (self.units), dtype = 'float32'), trainable = True)
    super().build(input_shape)

def call(self, inputs):
    '''Defines the computation from inputs to outputs'''
    # Remember to use self.activation() to get the final output
    return self.activation(tf.matmul(tf.math.square(inputs),self.w) + tf.matmul(inputs, self.w) + self.b)

Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz 11493376/11490434 [==============================] - 0s 0us/step Train on 60000 samples Epoch 1/5 60000/60000 [==============================] - 13s 212us/sample - loss: 0.2831 - accuracy: 0.9158 Epoch 2/5 60000/60000 [==============================] - 12s 207us/sample - loss: 0.1336 - accuracy: 0.9596 Epoch 3/5 60000/60000 [==============================] - 12s 205us/sample - loss: 0.1021 - accuracy: 0.9677 Epoch 4/5 60000/60000 [==============================] - 12s 202us/sample - loss: 0.0835 - accuracy: 0.9737 Epoch 5/5 60000/60000 [==============================] - 12s 202us/sample - loss: 0.0729 - accuracy: 0.9770 10000/10000 [==============================] - 1s 78us/sample - loss: 0.0757 - accuracy: 0.9772

Out[6]:

[0.07569382057227195, 0.9772]

Thanks, David
It looks like the problem in this case is that the instructions in the comments for SimpleQuadratic build() ask you to name your variables a, b, and c, but you named the first variable w instead of a.
The test is specifically looking for a.