# Custom output names for keras model

I have a model like this with multiple outputs and i want to change it's output names

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 automatically set output names to output_1, output_2, ... how can i change the output names to my desired names?

• Are you using tensorflow.keras and the associated imports of Model and Dense, or a different source? For imports coming from tensorflow.keras with tensorflow 2 I am unable to reproduce your issue; for me, upon being built, the model in your example yields a model summary with the output names as desired. Similarly, using the functional and sequential apis in a similar way works fine for me. If you'd like, I'm happy to write an answer describing how to verify this. If you are using the same imports as me, in what verifiable sense is your code not changing the output names? May 18, 2020 at 21:43
• I am using tensorflow.keras with tensorflow 2.2 but my output names are output_1, output_2, ... i checked it in kaggle notebook and even in my local computer and i have this issue in both cases. @It'sRecreational May 18, 2020 at 23:44
• Huh, that is odd. In what sense are your output names output_1 and output_2? When you instantiate model = MyModel() and call model.summary()? Or in another context? If you can provide more details about your setup and what precise code is yielding output that is unintended, I can try to be of more help. May 19, 2020 at 1:25

I also have this issue, but didn't have the answer with a customized Model. There is a workaround as follows:

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

• Where or how is 'inputs' defined? Could you show sufficient context for your code snippet? Mar 16 at 14:25

maybe this is better in your case:

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}

• Thanks, this worked for me. After I did this and run model.fit() the losses appeared with the names of the keys. Can you point to a reference in tensorflow documentation that explains that is the way to be done? Sep 24, 2021 at 6:40