Keras中的model.evaluate()返回什么值? [英] What values are returned from model.evaluate() in Keras?
问题描述
我的模型从多个密集层获得了多个输出.我的模型将'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_1
和dense_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屋!