Weird layer suffix issue running in Jupyter Notebook2019 Community Moderator ElectionKeras - All layer names should be uniquewrap a general python function in tensorflowError when checking model target: expected dense_2 to have shape (None, 29430) but got array with shape (1108, 1)Getting the output of layer as a feature vector (KERAS)Keras Sequential model input layerWhat is the role of TimeDistributed layer in Keras?How does Keras read input data?Keras Model - Functional API - adding layers to existing modelKerras the definition of a model changes when the input tensor of the model is the output of another modelUse Glove vectors without Embedding layers in LSTMKeras functional api gives error “expected ndim=3, found ndim=4”

Relationship between sampajanna definitions in SN 47.2 and SN 47.35

How could an airship be repaired midflight?

A diagram about partial derivatives of f(x,y)

Is there a symmetric-key algorithm which we can use for creating a signature?

Bacteria contamination inside a thermos bottle

Knife as defense against stray dogs

What exactly is this small puffer fish doing and how did it manage to accomplish such a feat?

Non-trivial topology where only open sets are closed

What is the adequate fee for a reveal operation?

Could the Saturn V actually have launched astronauts around Venus?

Print a physical multiplication table

Are ETF trackers fundamentally better than individual stocks?

Do I need life insurance if I can cover my own funeral costs?

Why do tuner card drivers fail to build after kernel update to 4.4.0-143-generic?

How could a scammer know the apps on my phone / iTunes account?

When to use a slotted vs. solid turner?

Why is a white electrical wire connected to 2 black wires?

Why did it take so long to abandon sail after steamships were demonstrated?

Is it good practice to use Linear Least-Squares with SMA?

Is Manda another name for Saturn (Shani)?

What is the relationship between relativity and the Doppler effect?

How to make healing in an exploration game interesting

Do I need to be arrogant to get ahead?

English sentence unclear



Weird layer suffix issue running in Jupyter Notebook



2019 Community Moderator ElectionKeras - All layer names should be uniquewrap a general python function in tensorflowError when checking model target: expected dense_2 to have shape (None, 29430) but got array with shape (1108, 1)Getting the output of layer as a feature vector (KERAS)Keras Sequential model input layerWhat is the role of TimeDistributed layer in Keras?How does Keras read input data?Keras Model - Functional API - adding layers to existing modelKerras the definition of a model changes when the input tensor of the model is the output of another modelUse Glove vectors without Embedding layers in LSTMKeras functional api gives error “expected ndim=3, found ndim=4”










1















from keras import layers as KL
def create_model():
inp = KL.Input(shape=(None,), name='input')
embedding = KL.Embedding(input_dim=10, output_dim=10)(inp)
out = KL.Dense(1, activation='sigmoid', name='dense')(embedding)
model = KM.Model(inputs=[inp], outputs=[out])

return model

model1 = create_model()
model1.summary()
model2 = create_model()
model2.summary()


The output for model1:



embedding_1 (Embedding) 


model2:



embedding_2 (Embedding) 


Why the name of the layer is not fixed? If I run create_model() again, the name will be suffixed with _3.



Any idea? Does this has anything to do with running in Jupyter? Does Jupyter kernel somehow cache the variables? Thanks!










share|improve this question



















  • 1





    Keras does this, because layer names have to be unique.

    – Matias Valdenegro
    Mar 7 at 15:45











  • Does Keras maintain the layer names globally? create_model() defines a new model every time it is called.

    – zsong
    Mar 7 at 15:47












  • It creates them so they are globally unique but they don't have to. Note that this has nothing to do with variable names.

    – Matias Valdenegro
    Mar 7 at 15:49











  • Is there a way to reset the counter? I need the layer names to be fixed because I need to port the model as tensforflow format and use it in C#. If the name of the layer is changed every time when the model is trained, I have to update the code.

    – zsong
    Mar 7 at 15:52











  • Possibly of help: Keras - All layer names should be unique

    – desertnaut
    Mar 7 at 15:56















1















from keras import layers as KL
def create_model():
inp = KL.Input(shape=(None,), name='input')
embedding = KL.Embedding(input_dim=10, output_dim=10)(inp)
out = KL.Dense(1, activation='sigmoid', name='dense')(embedding)
model = KM.Model(inputs=[inp], outputs=[out])

return model

model1 = create_model()
model1.summary()
model2 = create_model()
model2.summary()


The output for model1:



embedding_1 (Embedding) 


model2:



embedding_2 (Embedding) 


Why the name of the layer is not fixed? If I run create_model() again, the name will be suffixed with _3.



Any idea? Does this has anything to do with running in Jupyter? Does Jupyter kernel somehow cache the variables? Thanks!










share|improve this question



















  • 1





    Keras does this, because layer names have to be unique.

    – Matias Valdenegro
    Mar 7 at 15:45











  • Does Keras maintain the layer names globally? create_model() defines a new model every time it is called.

    – zsong
    Mar 7 at 15:47












  • It creates them so they are globally unique but they don't have to. Note that this has nothing to do with variable names.

    – Matias Valdenegro
    Mar 7 at 15:49











  • Is there a way to reset the counter? I need the layer names to be fixed because I need to port the model as tensforflow format and use it in C#. If the name of the layer is changed every time when the model is trained, I have to update the code.

    – zsong
    Mar 7 at 15:52











  • Possibly of help: Keras - All layer names should be unique

    – desertnaut
    Mar 7 at 15:56













1












1








1








from keras import layers as KL
def create_model():
inp = KL.Input(shape=(None,), name='input')
embedding = KL.Embedding(input_dim=10, output_dim=10)(inp)
out = KL.Dense(1, activation='sigmoid', name='dense')(embedding)
model = KM.Model(inputs=[inp], outputs=[out])

return model

model1 = create_model()
model1.summary()
model2 = create_model()
model2.summary()


The output for model1:



embedding_1 (Embedding) 


model2:



embedding_2 (Embedding) 


Why the name of the layer is not fixed? If I run create_model() again, the name will be suffixed with _3.



Any idea? Does this has anything to do with running in Jupyter? Does Jupyter kernel somehow cache the variables? Thanks!










share|improve this question
















from keras import layers as KL
def create_model():
inp = KL.Input(shape=(None,), name='input')
embedding = KL.Embedding(input_dim=10, output_dim=10)(inp)
out = KL.Dense(1, activation='sigmoid', name='dense')(embedding)
model = KM.Model(inputs=[inp], outputs=[out])

return model

model1 = create_model()
model1.summary()
model2 = create_model()
model2.summary()


The output for model1:



embedding_1 (Embedding) 


model2:



embedding_2 (Embedding) 


Why the name of the layer is not fixed? If I run create_model() again, the name will be suffixed with _3.



Any idea? Does this has anything to do with running in Jupyter? Does Jupyter kernel somehow cache the variables? Thanks!







keras jupyter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 15:46









desertnaut

19.5k74076




19.5k74076










asked Mar 7 at 15:39









zsongzsong

45.2k22132194




45.2k22132194







  • 1





    Keras does this, because layer names have to be unique.

    – Matias Valdenegro
    Mar 7 at 15:45











  • Does Keras maintain the layer names globally? create_model() defines a new model every time it is called.

    – zsong
    Mar 7 at 15:47












  • It creates them so they are globally unique but they don't have to. Note that this has nothing to do with variable names.

    – Matias Valdenegro
    Mar 7 at 15:49











  • Is there a way to reset the counter? I need the layer names to be fixed because I need to port the model as tensforflow format and use it in C#. If the name of the layer is changed every time when the model is trained, I have to update the code.

    – zsong
    Mar 7 at 15:52











  • Possibly of help: Keras - All layer names should be unique

    – desertnaut
    Mar 7 at 15:56












  • 1





    Keras does this, because layer names have to be unique.

    – Matias Valdenegro
    Mar 7 at 15:45











  • Does Keras maintain the layer names globally? create_model() defines a new model every time it is called.

    – zsong
    Mar 7 at 15:47












  • It creates them so they are globally unique but they don't have to. Note that this has nothing to do with variable names.

    – Matias Valdenegro
    Mar 7 at 15:49











  • Is there a way to reset the counter? I need the layer names to be fixed because I need to port the model as tensforflow format and use it in C#. If the name of the layer is changed every time when the model is trained, I have to update the code.

    – zsong
    Mar 7 at 15:52











  • Possibly of help: Keras - All layer names should be unique

    – desertnaut
    Mar 7 at 15:56







1




1





Keras does this, because layer names have to be unique.

– Matias Valdenegro
Mar 7 at 15:45





Keras does this, because layer names have to be unique.

– Matias Valdenegro
Mar 7 at 15:45













Does Keras maintain the layer names globally? create_model() defines a new model every time it is called.

– zsong
Mar 7 at 15:47






Does Keras maintain the layer names globally? create_model() defines a new model every time it is called.

– zsong
Mar 7 at 15:47














It creates them so they are globally unique but they don't have to. Note that this has nothing to do with variable names.

– Matias Valdenegro
Mar 7 at 15:49





It creates them so they are globally unique but they don't have to. Note that this has nothing to do with variable names.

– Matias Valdenegro
Mar 7 at 15:49













Is there a way to reset the counter? I need the layer names to be fixed because I need to port the model as tensforflow format and use it in C#. If the name of the layer is changed every time when the model is trained, I have to update the code.

– zsong
Mar 7 at 15:52





Is there a way to reset the counter? I need the layer names to be fixed because I need to port the model as tensforflow format and use it in C#. If the name of the layer is changed every time when the model is trained, I have to update the code.

– zsong
Mar 7 at 15:52













Possibly of help: Keras - All layer names should be unique

– desertnaut
Mar 7 at 15:56





Possibly of help: Keras - All layer names should be unique

– desertnaut
Mar 7 at 15:56












1 Answer
1






active

oldest

votes


















0














Each layer has a parameter called name, which sets the layer name. You can use this to put your own fixed names to layers, so you can operate on them later.



For example:



conv1 = Conv2D(..., name='conv1')(some_input)





share|improve this answer























  • This won't work. The name will be embedding_1/embedding or embedding_2/embedding after ported as Tensorflow format

    – zsong
    Mar 7 at 15:59







  • 1





    @zsong I get the feeling that we have a XY problem here, because you don't explain what exactly is the problem, but you are trying to make your solution work. Please state the full problem.

    – Matias Valdenegro
    Mar 7 at 16:04










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047605%2fweird-layer-suffix-issue-running-in-jupyter-notebook%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Each layer has a parameter called name, which sets the layer name. You can use this to put your own fixed names to layers, so you can operate on them later.



For example:



conv1 = Conv2D(..., name='conv1')(some_input)





share|improve this answer























  • This won't work. The name will be embedding_1/embedding or embedding_2/embedding after ported as Tensorflow format

    – zsong
    Mar 7 at 15:59







  • 1





    @zsong I get the feeling that we have a XY problem here, because you don't explain what exactly is the problem, but you are trying to make your solution work. Please state the full problem.

    – Matias Valdenegro
    Mar 7 at 16:04















0














Each layer has a parameter called name, which sets the layer name. You can use this to put your own fixed names to layers, so you can operate on them later.



For example:



conv1 = Conv2D(..., name='conv1')(some_input)





share|improve this answer























  • This won't work. The name will be embedding_1/embedding or embedding_2/embedding after ported as Tensorflow format

    – zsong
    Mar 7 at 15:59







  • 1





    @zsong I get the feeling that we have a XY problem here, because you don't explain what exactly is the problem, but you are trying to make your solution work. Please state the full problem.

    – Matias Valdenegro
    Mar 7 at 16:04













0












0








0







Each layer has a parameter called name, which sets the layer name. You can use this to put your own fixed names to layers, so you can operate on them later.



For example:



conv1 = Conv2D(..., name='conv1')(some_input)





share|improve this answer













Each layer has a parameter called name, which sets the layer name. You can use this to put your own fixed names to layers, so you can operate on them later.



For example:



conv1 = Conv2D(..., name='conv1')(some_input)






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 15:54









Matias ValdenegroMatias Valdenegro

32k45581




32k45581












  • This won't work. The name will be embedding_1/embedding or embedding_2/embedding after ported as Tensorflow format

    – zsong
    Mar 7 at 15:59







  • 1





    @zsong I get the feeling that we have a XY problem here, because you don't explain what exactly is the problem, but you are trying to make your solution work. Please state the full problem.

    – Matias Valdenegro
    Mar 7 at 16:04

















  • This won't work. The name will be embedding_1/embedding or embedding_2/embedding after ported as Tensorflow format

    – zsong
    Mar 7 at 15:59







  • 1





    @zsong I get the feeling that we have a XY problem here, because you don't explain what exactly is the problem, but you are trying to make your solution work. Please state the full problem.

    – Matias Valdenegro
    Mar 7 at 16:04
















This won't work. The name will be embedding_1/embedding or embedding_2/embedding after ported as Tensorflow format

– zsong
Mar 7 at 15:59






This won't work. The name will be embedding_1/embedding or embedding_2/embedding after ported as Tensorflow format

– zsong
Mar 7 at 15:59





1




1





@zsong I get the feeling that we have a XY problem here, because you don't explain what exactly is the problem, but you are trying to make your solution work. Please state the full problem.

– Matias Valdenegro
Mar 7 at 16:04





@zsong I get the feeling that we have a XY problem here, because you don't explain what exactly is the problem, but you are trying to make your solution work. Please state the full problem.

– Matias Valdenegro
Mar 7 at 16:04



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047605%2fweird-layer-suffix-issue-running-in-jupyter-notebook%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived