I am on week3 final label Exercise 6 first assignment to compute the total loss. I am quite confused exactly what lab asks us to do. And it seems the exercise want us to use tf.keras.losses.categorical_crossentropy() and the first parameter, based on the function document, is supposed to be one_hot() transformation of the input labels. I passed previous test on using tf.one_hot(), but this one, when I try to do
oh = tf.one_hot(labels, 2,axis=0)
System kept saying it is argument exception for calling one_hot:
InvalidArgumentError: Value for attr ‘TI’ of float is not in the list of allowed values: uint8, int32, int64
; NodeDef: {{node OneHot}}; Op<name=OneHot; signature=indices:TI, depth:int32, on_value:T, off_value:T → output:T; attr=axis:int,default=-1; attr=T:type; attr=TI:type,default=DT_INT64,allowed=[DT_UINT8, DT_INT32, DT_INT64]> [Op:OneHot]
Apparently, system think ‘indices’, which is the labels passed into ‘def compute_total_loss(logits, labels):’ is of type TI, I have no idea why that it. I print out labels variable, it shows: tf.Tensor(
[[0. 1.]
[0. 0.]
[0. 0.]
[0. 0.]
[0. 0.]
[1. 0.]], shape=(6, 2), dtype=float32)
There’s no doc saying whether this TI, or should be an array of float32. Can someone help me to get this sorted out. This is not related to class knowledge but very Tensorflow specific syntax
{moderator edit - solution code removed}