keras 模型的自定义输出名称

数据挖掘 喀拉斯 张量流 多输出
2021-09-24 12:45:32

我有一个这样的模型,有多个输出,我想更改它的输出名称

class MyModel(Model):
    def __init__(self):
        super(MyModel, self).__init__()
        self.layer_one = Dense(1, name='output_name_one')
        self.layer_two = Dense(1, name='output_name_two')
    def call(self, inputs):
        output_name_one = self.layer_one(inputs)  
        output_name_two = self.layer_two(inputs)  
        return output_name_one, output_name_two

keras 自动将输出名称设置为output_1, output_2, ...如何将输出名称更改为我想要的名称?

2个回答

我也有这个问题,但没有定制模型的答案。有一个解决方法如下:

 model = Model(inputs=inputs,
                  outputs={'ctr_output': ctr_pred, 'ctcvr_pred': ctcvr_pred, 'cvr_output': cvr_pred})

也许这对你来说更好:

class MyModel(Model):
    def __init__(self):
        super(MyModel, self).__init__()
        self.layer_one = Dense(1, name='output_name_one')
        self.layer_two = Dense(1, name='output_name_two')
    def call(self, inputs):
        output_name_one = self.layer_one(inputs)  
        output_name_two = self.layer_two(inputs)  
        return {'custom_name_one': output_name_one,'custom_name_two': output_name_two}