我在SO中的問題與this question相同。然而,當我嘗試使用probas_to_classes()效用函數,**它已經丟失在當前代碼:獲取Keras預測函數的類標籤訂單
"""Numpy-related utilities."""
from __future__ import absolute_import
import numpy as np
def to_categorical(y, num_classes=None):
"""Converts a class vector (integers) to binary class matrix.
E.g. for use with categorical_crossentropy.
# Arguments
y: class vector to be converted into a matrix
(integers from 0 to num_classes).
num_classes: total number of classes.
# Returns
A binary matrix representation of the input.
"""
y = np.array(y, dtype='int').ravel()
if not num_classes:
num_classes = np.max(y) + 1
n = y.shape[0]
categorical = np.zeros((n, num_classes))
categorical[np.arange(n), y] = 1
return categorical
def normalize(x, axis=-1, order=2):
"""Normalizes a Numpy array.
# Arguments
x: Numpy array to normalize.
axis: axis along which to normalize.
order: Normalization order (e.g. 2 for L2 norm).
# Returns
A normalized copy of the array.
"""
l2 = np.atleast_1d(np.linalg.norm(x, order, axis))
l2[l2 == 0] = 1
return x/np.expand_dims(l2, axis)
你有沒有爲了得到與輸出相關的類的任何其他替代品該模型?
謝謝你的回答。但是,我不知道我的類在輸出中的順序。另外,我的計劃是通過模型獲得前兩名的猜測。你能幫我麼? – noobalert