Keras 中的 model.evaluate() 返回什么值? [英] What values are returned from model.evaluate() in Keras?

查看:77
本文介绍了Keras 中的 model.evaluate() 返回什么值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型从多个 Dense 层获得了多个输出.我的模型将 'accuracy' 作为编译中的唯一指标.我想知道每个输出的损失和准确性.这是我代码的一部分.

I've got multiple outputs from my model from multiple Dense layers. My model has 'accuracy' as the only metric in compilation. I'd like to know the loss and accuracy for each output. This is some part of my code.

scores = model.evaluate(X_test, [y_test_one, y_test_two], verbose=1)

当我打印出分数时,这是结果.

When I printed out the scores, this is the result.

[0.7185557290413819, 0.3189622712272771, 0.39959345855771927, 0.8470299135229717, 0.8016634374641469]

这些数字代表什么?

我是 Keras 的新手,这可能是一个微不足道的问题.但是,我已经阅读了 Keras 的文档,但我仍然不确定.

I'm new to Keras and this might be a trivial question. However, I have read the docs from Keras but I'm still not sure.

推荐答案

引自 <代码>evaluate() 方法文档:

Quoted from evaluate() method documentation:

退货

标量测试损失(如果模型只有一个输出且没有指标)或标量列表(如果模型有多个输出和/或指标).属性 model.metrics_names 将为您提供显示标签用于标量输出.

Scalar test loss (if the model has a single output and no metrics) or list of scalars (if the model has multiple outputs and/or metrics). The attribute model.metrics_names will give you the display labels for the scalar outputs.

因此,您可以使用模型的 metrics_names 属性来找出每个值对应的内容.例如:

Therefore, you can use metrics_names property of your model to find out what each of those values corresponds to. For example:

from keras import layers
from keras import models
import numpy as np

input_data = layers.Input(shape=(100,)) 
out_1 = layers.Dense(1)(input_data)
out_2 = layers.Dense(1)(input_data)

model = models.Model(input_data, [out_1, out_2])
model.compile(loss='mse', optimizer='adam', metrics=['mae'])

print(model.metrics_names)

输出以下内容:

['loss', 'dense_1_loss', 'dense_2_loss', 'dense_1_mean_absolute_error', 'dense_2_mean_absolute_error']

表示您在 evaluate 方法的输出中看到的每个数字对应的内容.

which indicates what each of those numbers you see in the output of evaluate method corresponds to.

此外,如果您有很多层,那么那些 dense_1dense_2 名称可能有点含糊.要解决这种歧义,您可以使用 name 图层参数(不一定在所有图层上,但仅在输入和输出图层上)为图层指定名称:

Further, if you have many layers then those dense_1 and dense_2 names might be a bit ambiguous. To resolve this ambiguity, you can assign names to your layers using name argument of layers (not necessarily on all of them but only on the input and output layers):

# ...
out_1 = layers.Dense(1, name='output_1')(input_data)
out_2 = layers.Dense(1, name='output_2')(input_data)
# ...

print(model.metrics_names)

输出更清晰的描述:

['loss', 'output_1_loss', 'output_2_loss', 'output_1_mean_absolute_error', 'output_2_mean_absolute_error']

这篇关于Keras 中的 model.evaluate() 返回什么值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆