繁体   English   中英

打印或保存 tf.keras 模型的输出,与输入配对

[英]Print or save output of tf.keras model, paired with inputs

def locations_model(...):
    input_shape = image_shape + (3,)
    base_model = tf.keras.applications.MobileNetV2(...)                                                                base_model.trainable = False 
    inputs = tf.keras.Input(...)  
... ...     
    outputs = tfl.Dense(5, activation = "softmax")(x)
    model = tf.keras.Model(inputs, outputs)
 
    return model

上面的代码只是显示 tf.keras 模型中的输入和输出,该模型将输入图像分为 5 个类别。 如何保存每个输入图像的输出类别(“y_pred”)?

简单语句ypreds = model(inputs)ypreds = model.predict(inputs)生成一组 5 元素数组,它们相加为 1,即概率。
因此,问题是如何输出预测的类别,在这种情况下是整数:0-4,而不是概率。 更新:这是 Apostolova 对 Lodzz 的“从 Keras 功能模型获取类标签”问题的回答,如 test_probas = model.predict(test_data) test_classes = probas.argmax(axis = -1)

感谢@EduardoriosChicago的确认。 为了社区的利益,我在这里提到您的答案。

代码是

probas = model(x_in); x_classes = probas.argmax( axis = - 1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM