目录
1.label 转 one-hot
import tensorflow as tf
label = tf.stack(5)
one_hot_label = tf.one_hot(label, num_classes)
print("label: ", label.numpy())
print("one_hot_label: ", one_hot_label.numpy())
'''
output:
label: 5
one_hot_label: [0., 0., 0., 0., 0., 1., 0., 0., 0., 0.]
'''
2.tensor 类型one-hot 转 label
label = tf.stack(5)
one_hot_label = tf.one_hot(label, 10)
new_label = tf.argmax(one_hot_label)
print(new_label.numpy())
# output: 5
3.ndarray类型one-hot 转 label
labels.argmax(axis=1)