<p dir="auto">I tried the example in the file "neural_style_transfer.py". I want to see the outputs features of relu units for a single image in VGG network. I do not want to trouble to modify the code so I simply duplicated the same image for three times and inputs them together to the net (using K.function to extract three outputs). But the output has negative numbers.</p>
<p dir="auto">However, when I tried to extract the output of only one image (still kept three image as inputs, but using three K.fucntion() to extract their outputs seperately) the problem is gone.</p>
<p dir="auto">Even for the positive values, joint outputs are still different from individual outputs.</p>
<p dir="auto">This is weird, I worry if it may cause serious problem. See below for the code segments (I do not modify other codes)<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/13939832/13708151/05f39c94-e7e8-11e5-9915-b5421acdef20.png"><img src="https://cloud.githubusercontent.com/assets/13939832/13708151/05f39c94-e7e8-11e5-9915-b5421acdef20.png" alt="2016-03-11 11 00 27 pm" style="max-width: 100%;"></a></p>
<p dir="auto">A shared layer is represented by a single in-memory object. However, in the case shown below, saving then loading the model leads to the creation of duplicate layers - this means that training the loaded model will lead to different results. This is because one use of the shared layer is in a (sub-)model, which in turn is included as a layer in the full model.</p>
<ul class="contains-task-list">
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Check that you are up-to-date with the master branch of Keras. You can update with:<br>
pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found <a href="https://www.tensorflow.org/get_started/os_setup" rel="nofollow">here</a>.</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).</p>
</li>
</ul>
<p dir="auto">Minimal example showing the issue:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from keras.layers import Input, Dense
from keras.models import Model
from keras.models import load_model, save_model

x = Input((10,))
dense = Dense(10)
submodel = Model(x, dense(x))
model = Model(x, dense(submodel(x)))

save_model(model, 'test.model')
model2 = load_model('test.model')

print('Layer name is shared in original model:', model.layers[1].layers[-1].name == model.layers[-1].name)
print('Layer is shared in original model:', model.layers[1].layers[-1] is model.layers[-1])
print('Layer name is shared in loaded model:', model2.layers[1].layers[-1].name == model2.layers[-1].name)
print('Layer is shared in loaded model:', model2.layers[1].layers[-1] is model2.layers[-1])"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">keras</span>.<span class="pl-s1">layers</span> <span class="pl-k">import</span> <span class="pl-v">Input</span>, <span class="pl-v">Dense</span>
<span class="pl-k">from</span> <span class="pl-s1">keras</span>.<span class="pl-s1">models</span> <span class="pl-k">import</span> <span class="pl-v">Model</span>
<span class="pl-k">from</span> <span class="pl-s1">keras</span>.<span class="pl-s1">models</span> <span class="pl-k">import</span> <span class="pl-s1">load_model</span>, <span class="pl-s1">save_model</span>

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-v">Input</span>((<span class="pl-c1">10</span>,))
<span class="pl-s1">dense</span> <span class="pl-c1">=</span> <span class="pl-v">Dense</span>(<span class="pl-c1">10</span>)
<span class="pl-s1">submodel</span> <span class="pl-c1">=</span> <span class="pl-v">Model</span>(<span class="pl-s1">x</span>, <span class="pl-en">dense</span>(<span class="pl-s1">x</span>))
<span class="pl-s1">model</span> <span class="pl-c1">=</span> <span class="pl-v">Model</span>(<span class="pl-s1">x</span>, <span class="pl-en">dense</span>(<span class="pl-en">submodel</span>(<span class="pl-s1">x</span>)))

<span class="pl-en">save_model</span>(<span class="pl-s1">model</span>, <span class="pl-s">'test.model'</span>)
<span class="pl-s1">model2</span> <span class="pl-c1">=</span> <span class="pl-en">load_model</span>(<span class="pl-s">'test.model'</span>)

<span class="pl-en">print</span>(<span class="pl-s">'Layer name is shared in original model:'</span>, <span class="pl-s1">model</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">1</span>].<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>].<span class="pl-s1">name</span> <span class="pl-c1">==</span> <span class="pl-s1">model</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>].<span class="pl-s1">name</span>)
<span class="pl-en">print</span>(<span class="pl-s">'Layer is shared in original model:'</span>, <span class="pl-s1">model</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">1</span>].<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>] <span class="pl-c1">is</span> <span class="pl-s1">model</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>])
<span class="pl-en">print</span>(<span class="pl-s">'Layer name is shared in loaded model:'</span>, <span class="pl-s1">model2</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">1</span>].<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>].<span class="pl-s1">name</span> <span class="pl-c1">==</span> <span class="pl-s1">model2</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>].<span class="pl-s1">name</span>)
<span class="pl-en">print</span>(<span class="pl-s">'Layer is shared in loaded model:'</span>, <span class="pl-s1">model2</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">1</span>].<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>] <span class="pl-c1">is</span> <span class="pl-s1">model2</span>.<span class="pl-s1">layers</span>[<span class="pl-c1">-</span><span class="pl-c1">1</span>])</pre></div>
<p dir="auto">returns:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Layer name is shared in original model: True
Layer is shared in original model: True
Layer name is shared in loaded model: True
Layer is shared in loaded model: False"><pre class="notranslate"><code class="notranslate">Layer name is shared in original model: True
Layer is shared in original model: True
Layer name is shared in loaded model: True
Layer is shared in loaded model: False
</code></pre></div>