Been looking, but can't seem to find any examples of how to decode or convert back to a single integer from a one-hot value in TensorFlow.
I used tf.one_hot
and was able to train my model but am a bit confused on how to make sense of the label after my classification. My data is being fed in via a TFRecords
file that I created. I thought about storing a text label in the file but wasn't able to get it to work. It appeared as if TFRecords
couldn't store text string or maybe I was mistaken.
You can find out the index of the largest element in the matrix using
tf.argmax
. Since your one hot vector will be one dimensional and will have just one1
and other0
s, This will work assuming you are dealing with a single vector.For the more standard matrix of
batch_size * num_classes
, useaxis=1
to get a result of sizebatch_size * 1
.