Assume that as an output of the function softmax has the following tensor t:
t = tf.constant(value=[[0.2,0.8], [0.6, 0.4]])
>> [ 0.2, 0.8]
[ 0.6, 0.4]
Now, I would like to convert this matrix tto a matrix that looks like a OneHot encoded matrix:
Y.eval()
>> [ 0, 1]
[ 1, 0]
I am familiar with c = tf.argmax(t)that which will give me the indices in the row t, which should be equal to 1. But moving from cto Yseems rather complicated.
I have already tried converting tto tf.SparseTensorusing c, and then using tf.sparse_tensor_to_dense()get Y. But this transformation involves quite a few steps and seems too complicated for the task - I have not even finished it completely, but I am sure that it can work.
Is there a more suitable / easy way to do this conversion that I am missing.
The reason I need this is because I have my own OneHot encoder in Python where I can feed Y. tf.one_hot()not extensive enough - does not allow you to configure the encoding.
Related questions:
source
share