OperatorNotAllowedInGraphError: Iterating over a symbolic `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function

I am getting this error in week 1’s assignment in step 3 where we have to map the one hot encoding function to the dataset

My code:
train_data = train_data.map(lambda feature, label: my_one_hot(feature, label))

Hello @Danyail_Mateen.
Thank you for posting. The error occurs because iterating over a symbolic tensor is not allowed in Graph execution mode. TensorFlow does not support explicit loops or operations that require iteration over tensors in a graph.

So i’d recommend you to try modify your code using “map” function in another way rather than using lambda inside map funcation as it can lead to the TensorFlow trying to build a computation graph for the lambda function

I hope this helps you.

thanks for your response, will try that. been stuck here for a while