Encoder error - Week 4

All,

I’m running into a problem with my Encoder and am stuck. Any tips?

ERROR:

positions 5
d 4
angle_rads [[0. 0. 0. 0. ]
[1. 1. 0.01 0.01]
[2. 2. 0.02 0.02]
[3. 3. 0.03 0.03]
[4. 4. 0.04 0.04]]
angle rad shape (5, 4)

TypeError Traceback (most recent call last)
in
1 # UNIT TEST
----> 2 Encoder_test(Encoder)

~/work/W4A1/public_tests.py in Encoder_test(target)
114 x = np.array([[2, 1, 3], [1, 2, 0]])
115
→ 116 encoderq_output = encoderq(x, True, None)
117
118 assert tf.is_tensor(encoderq_output), “Wrong type. Output must be a tensor”

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/base_layer.py in call(self, *args, **kwargs)
1010 with autocast_variable.enable_auto_cast_variables(
1011 self._compute_dtype_object):
→ 1012 outputs = call_fn(inputs, *args, **kwargs)
1013
1014 if self._activity_regularizer:

in call(self, x, training, mask)
56 # Pass the output through the stack of encoding layers
57 for i in range(self.num_layers):
—> 58 x = self.enc_layers(x)
59 # END CODE HERE
60

TypeError: ‘ListWrapper’ object is not callable

When your Encoder calls “x = self.enc_layers(…)”, you need to index the layer with [i], and you need to pass all of the parameters x, training, and mask. Not just ‘x’.

6 Likes

Got it. Thank Tom!

JB

For any other “less than expert” Python coders out there, remember that depending on context, one of the following may be appropriate while the other is not:

thing = method[something](something else)
thing = method(something)[something else]

This observation got me unstuck after (admittedly) many attempts.

1 Like

Thanks you for this very useful tip !

1 Like