tensorflow--之将数字标签转化为one-hot

如果要用到soft_max函数,就必须将数字标签转化为one-hot,之前用caffe是自动转,

这回使用tensoflow是的自己转:

例子代码如下:

import numpy as np
labels=np.asarray([0,4,2,3,2,0])

num_labels = labels_dense.shape[0]
num_classes=5
index_offset = np.arange(num_labels) * num_classes
one_hot = np.zeros((num_labels, num_classes))
one_hot.flat[index_offset + labels] = 1
print labels_one_hot

输出:

参考:https://blog.csdn.net/hzhj2007/article/details/79197693

猜你喜欢

转载自blog.csdn.net/zxyhhjs2017/article/details/82559477