有没有一种方法可以重命名Keras模型的指标和损失? [英] Is there a way of renaming the metrics and losses of a Keras model?

查看:196
本文介绍了有没有一种方法可以重命名Keras模型的指标和损失?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的模型,有很多损失和指标. 当我做print(np.array(self.model.metrics_names)) 我明白了:

I have a very big model with many losses and metrics. When I do print(np.array(self.model.metrics_names)) I get this:

['loss' 'autoencoder_loss' 'autoencoder_loss' 'autoencoder_loss'
 'autoencoder_loss' 's_regularisation_phase_loss'
 'gen_regularisation_phase_loss' 's_regularisation_phase_loss'
 'z_regularisation_phase_loss' 'gen_regularisation_phase_loss'
 'z_regularisation_phase_loss' 'gen_regularisation_phase_loss'
 'gen_regularisation_phase_loss' 'autoencoder_categorical_accuracy'
 'autoencoder_output' 'autoencoder_categorical_accuracy_1'
 'autoencoder_output_1' 'autoencoder_categorical_accuracy_2'
 'autoencoder_output_2' 'autoencoder_categorical_accuracy_3'
 'autoencoder_output_3' 's_regularisation_phase_categorical_accuracy'
 's_regularisation_phase_output'
 'gen_regularisation_phase_categorical_accuracy'
 'gen_regularisation_phase_output'
 's_regularisation_phase_categorical_accuracy_1'
 's_regularisation_phase_output_1'
 'z_regularisation_phase_categorical_accuracy'
 'z_regularisation_phase_output'
 'gen_regularisation_phase_categorical_accuracy_1'
 'gen_regularisation_phase_output_1'
 'z_regularisation_phase_categorical_accuracy_1'
 'z_regularisation_phase_output_1'
 'gen_regularisation_phase_categorical_accuracy_2'
 'gen_regularisation_phase_output_2'
 'gen_regularisation_phase_categorical_accuracy_3'
 'gen_regularisation_phase_output_3']

有没有办法给他们起更有意义的名字?

Is there a way to give them more meaningful names?

推荐答案

每个_loss_accuracy之前的名称均来自输出层的名称.如果要修改此名称,则应重命名输出层.

The names before each _loss and _accuracy came from the names of output layers. If you want to modify this names you should rename the output layers.

请考虑以下模型.

input_ =  keras.layers.Input(shape=(8,))
x =  keras.layers.Dense(16)(input_)
output1 = keras.layers.Dense(32, name="output1")(x)
output2 = keras.layers.Dense(32, name="output2")(x)
model = keras.models.Model(inputs=input_, outputs=[output1, output2])
model.compile(loss=["mse", "mae"], optimizer="adam", metrics={"output1":"accuracy","output2":"accuracy"})

现在model.metrics_names将为您提供以下列表

Now model.metrics_names will give you the following list

['loss', 'output1_loss', 'output2_loss', 'output1_acc', 'output2_acc']

这篇关于有没有一种方法可以重命名Keras模型的指标和损失?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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