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?

Topic multi-output keras tensorflow

Category Data Science


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}

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})

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.