DLS Course 2 Week3 one hot coding question

I got the step of coding one hot code passed.

However, when running subsequent steps we are not supposed to change, I got the following error. It complains about the shape of input tensor.

I checked the forum and coursera discussion forum history There is still no clear answer.

can someone help out? Thanks

error message…

“ValueError: Cannot reshape a tensor with 6 elements to shape [4] (4 elements) for ‘{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](one_hot, Reshape/shape)’ with input shapes: [6], [1] and with input tensors computed as partial shapes: input[1] = [4]”

The most likely cause of this type of error is referencing global variables in your one_hot implementation: referencing the variable that happens to be passed as the input, as opposed to the “formal parameter” value in the body of the function. That will pass the test case, but then fail when you use the function with a different input.

Well, either that or you have hard-coded the value 4 at some point in your one_hot_matrix code. E.g. in the dimension that is passed to the tf.reshape call.

1 Like