Tensorflow2.0 label與one-hot獨熱編碼向量之間的相互轉換

label 轉 one-hot


import tensorflow as tf

label = tf.stack(5)
one_hot_label = tf.one_hot(label, 10)

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.]
'''


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

 

發佈了27 篇原創文章 · 獲贊 21 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章