0

我正在使用在 Imagenet 上预训练的 Keras Inception_v3:

base_model = InceptionV3(weights='imagenet', include_top=True)

当我从生成的图像中预测时,我得到的输出向量的形状(n,1000)n给定的图像数量。所以现在如果我想解释结果,我需要用于训练模型的 1000 个输出类的名称……但我找不到!

任何的想法 ?

4

1 回答 1

5

您可以使用decode_predictions方法:

from keras.applications.inception_v3 import decode_predictions

preds = model.predict(x)
print('Predicted:', decode_predictions(preds, top=10))

# Predicted: [(u'n02504013', u'Indian_elephant', 0.0042589349), ...]

源代码

def decode_predictions(preds, top=5, **kwargs):
    """Decodes the prediction of an ImageNet model.
    # Arguments
        preds: Numpy tensor encoding a batch of predictions.
        top: Integer, how many top-guesses to return.
    # Returns
        A list of lists of top class prediction tuples
        `(class_name, class_description, score)`.
        One list of tuples per sample in batch input.
    # Raises
        ValueError: In case of invalid shape of the `pred` array
            (must be 2D).
    """

显然它并不特定于 Inception_V3。您可以导入它并将其用于 Imagenet 上的任何预训练模型。或者,您可以使用以下方法导入它:

from keras.applications.imagenet_utils import decode_predictions
于 2018-08-25T14:39:09.423 回答