change the Model: <name> given automatically by keras in model.summary() output

Viewed 1017

When calling the command:

print(model.summary())

I get the following output:

enter image description here

How can I rename the highlighted field, which is generated automatically by Keras?

Thank you in advance for your help.

2 Answers

there is the argument 'name'

in functional format

inp = Input((10,))
out = Dense(1)(inp)

m = Model(inp, out, name='model_XXX')
m.summary()

in sequential format

m = Sequential([Dense(1, input_dim=10)], name='model_XXX')
m.summary()

if u have a pre-trained model you can simply do

m.fit(...)
m._name = 'model_XXX' # try with m.name if it raise error due to TF version
m.summary()

If you want to rename an already built model, it can be done like this:

model.name = 'yourname'
Related