I’m getting an OperatorNotAllowedInGraphError when trying to use the map function to convert my datasetset labels to a one hot representation: train_data = train_data.map(my_one_hot)
Can anyone provide some guidance. Note that I have set the correct value for the as_supervised parameter in tfds.load
Here is the suggestion in the stack trace:
OperatorNotAllowedInGraphError: Iterating over a symbolic tf.Tensor is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
I figured out the issue. I was trying to programmatically determine the number of classes of the tensor object by using the python set() function. This does not work with a tensor object. When I hard-code the depth parameter to a value of 3, everyting works. I don’t like to hard-code parameters like this, but I don’t know the correct way to determine the number of classes in the tensor objects.
Generally, the data set will have some meta-data that says how many labels there are.
Or, if the data set uses sequential integer values for ‘y’ to indicate the label, then you can use the range of the ‘y’ values, then convert to one-hot encoding.