one-hot编码

两种实现方式:

方式一:Numpy

def to_one_hot(labels, dimension=64):

results = np.zeros((len(labels), dimension))

for i, label in enumerate(labels):

results[i, label] = 1.

return results

方式二:

from keras.utils.np_utils import to_categorical

one_hot_train_labels = to_categorical(train_labels)

one_hot_test_labels = to_categorical(test_labels)

你可能感兴趣的:(keras,tensorflow)