TransWikia.com

Custom output names for keras model

Data Science Asked by amin msh on April 11, 2021

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?

2 Answers

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

Answered by Zheng Ye on April 11, 2021

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}

Answered by Zheng Ye on April 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP