Weird layer suffix issue running in Jupyter Notebook The Next CEO of Stack OverflowKeras - 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”

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

Novel about a guy who is possessed by the divine essence and the world ends?

Can I equip Skullclamp on a creature I am sacrificing?

Written every which way

What was the first Unix version to run on a microcomputer?

What flight has the highest ratio of time difference to flight time?

How do I reset passwords on multiple websites easily?

Is there a difference between "Fahrstuhl" and "Aufzug"

Why do professional authors make "consistency" mistakes? And how to avoid them?

Multiple labels for a single equation

How does the Z80 determine which peripheral sent an interrupt?

I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin

What's the best way to handle refactoring a big file?

Why do remote companies require working in the US?

Is 'diverse range' a pleonastic phrase?

Is it possible to search for a directory/file combination?

Would a completely good Muggle be able to use a wand?

Which tube will fit a -(700 x 25c) wheel?

Does it take more energy to get to Venus or to Mars?

Geometry problem - areas of triangles (contest math)

Would a galaxy be visible from outside, but nearby?

Received an invoice from my ex-employer billing me for training; how to handle?

What happens if you roll doubles 3 times then land on "Go to jail?"

Grabbing quick drinks



Weird layer suffix issue running in Jupyter Notebook



The Next CEO of Stack OverflowKeras - 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.

    – zs2020
    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.

    – zs2020
    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.

    – zs2020
    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.

    – zs2020
    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

20.4k74379




20.4k74379










asked Mar 7 at 15:39









zs2020zs2020

45.2k23133194




45.2k23133194







  • 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.

    – zs2020
    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.

    – zs2020
    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.

    – zs2020
    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.

    – zs2020
    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.

– zs2020
Mar 7 at 15:47






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

– zs2020
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.

– zs2020
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.

– zs2020
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

    – zs2020
    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

    – zs2020
    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

    – zs2020
    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

32.2k45681




32.2k45681












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

    – zs2020
    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

    – zs2020
    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

– zs2020
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

– zs2020
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

Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved