C3W3: Week3 Errors for exercise 3 train model

Folks:
When I work on C3 Week3 Programming asisgnment Saimese Model Exercise 3 Train model, I got errors like this:


File “/usr/local/lib/python3.8/dist-packages/keras/src/engine/training.py”, line 1338, in train_function *
return step_function(self, iterator)
File “/tmp/ipykernel_14/512915329.py”, line 36, in norm *
return tf.math.l2_normalize(x, axis=1) # use tensorflow built in normalization

TypeError: Expected int32 passed to parameter 'y' of op 'Maximum', got 1e-12 of type 'float' instead. Error: Expected int32, but got 1e-12 of type 'float'.

I highly suspect it caused by Triplet loss function when I did:
def norm(x):
return tf.math.l2_normalize(x, axis=1) # use tensorflow built in normalization

sim = tf.linalg.matmul(norm(v2), norm(v1),  transpose_b=True)

According to lab instructions. Anybody has any idea for that ?

Thanks.

Hi @Zhiyi_Li2

You are not asked by instructions to do normalization when calculating TripletLossFn.

Normalization should have been done by Exercise 1 Siamese(..) function, as per instructions for it:

tf.keras.layers.Lambda: Layer with no weights that applies the function f, which should be specified using a lambda syntax. You will use this layer to apply normalization with the function.

So by just looking at what you posted, most probably you should get rid of def norm(x).. and do not use norm for the tf.linalg.matmul(..)

Cheers

Thanks. I removed normalization function.