Convert a tensor string label to one hot encoding

def to_one_hot(image,label):
return image,tf.one_hot(classes_to_indices[label],depth=14)

train_ds = train_ds.map(to_one_hot)

calsses_to_indices is a simple python dictionary containing { label_name: indices }

this code is showing an error:-
Tensor is unhashable. Instead, use tensor.ref() as the key.

is there any way to do one_hot encoding while using tf.data API ?

Can you check:

https://tensorflow-prod.ospodiscourse.com/t/one-hot-encoding/2103/

Ya, I have checked it but it is for NumPy data. I want to convert my string labels to integer labels using python dictionary calsses_to_indices but we cannot use tensor data in the python dictionary.

Is that dataset Map transforms are executed in graph mode.

More details at: