<p dir="auto">Hi ,<br>
I have the same issue as <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="211924785" data-permission-text="Title is private" data-url="https://github.com/keras-team/keras/issues/5601" data-hovercard-type="issue" data-hovercard-url="/keras-team/keras/issues/5601/hovercard" href="https://github.com/keras-team/keras/issues/5601">#5601</a>  (I am unable to force Keras + Theano to use more than 1 thread using OpenBLAS.) I have applied all suggestion mentioned on issue <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="211924785" data-permission-text="Title is private" data-url="https://github.com/keras-team/keras/issues/5601" data-hovercard-type="issue" data-hovercard-url="/keras-team/keras/issues/5601/hovercard" href="https://github.com/keras-team/keras/issues/5601">#5601</a>, It works on:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="inputs = Input(shape=(1024000,))
x = Dense(256, activation='relu')(inputs)
x = Dense(256, activation='relu')(x)
predictions = Dense(10000, activation='softmax')(x)
model = Model(input=inputs, output=predictions)
model.compile(optimizer='rmsprop',
              loss='categorical_crossentropy',
              metrics=['accuracy'])
data = np.random.rand(100, 1024000)
for i in range(100000):
    print (i)
    model.predict(data)"><pre class="notranslate"><code class="notranslate">inputs = Input(shape=(1024000,))
x = Dense(256, activation='relu')(inputs)
x = Dense(256, activation='relu')(x)
predictions = Dense(10000, activation='softmax')(x)
model = Model(input=inputs, output=predictions)
model.compile(optimizer='rmsprop',
              loss='categorical_crossentropy',
              metrics=['accuracy'])
data = np.random.rand(100, 1024000)
for i in range(100000):
    print (i)
    model.predict(data)
</code></pre></div>
<p dir="auto">but it doesn't work on :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="THEANO_FLAGS='device=cpu,openmp=True,blas.ldflags=-lopenblas'
OMP_NUM_THREADS=8 
KERAS_BACKEND=theano
import pandas as pd
import numpy as np
from tqdm import tqdm
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout
from keras.layers.embeddings import Embedding
from keras.layers.recurrent import LSTM, GRU
from keras.layers.normalization import BatchNormalization
from keras.utils import np_utils
import keras.engine.topology 
from keras.layers import TimeDistributed, Lambda
from keras.layers import Convolution1D, GlobalMaxPooling1D
from keras.callbacks import ModelCheckpoint
from keras import backend as K
from keras.layers.advanced_activations import PReLU
from keras.preprocessing import sequence, text

data = pd.read_csv('data/quora_duplicate_questions.tsv', sep='\t')
y = data.is_duplicate.values
tk = text.Tokenizer(nb_words=200000)
max_len = 40
tk.fit_on_texts(list(data.question1.values) + list(data.question2.values.astype(str)))
x1 = tk.texts_to_sequences(data.question1.values)
x1 = sequence.pad_sequences(x1, maxlen=max_len)
x2 = tk.texts_to_sequences(data.question2.values.astype(str))
x2 = sequence.pad_sequences(x2, maxlen=max_len)
word_index = tk.word_index
ytrain_enc = np_utils.to_categorical(y)
embeddings_index = {}
f = open('data/glove.840B.300d.txt')
values_conv = []
for line in tqdm(f):
    values = line.split()
    for item in values:
        try:
            values_conv.append(float(item))
        except: 
            pass
    word = values_conv[0]
    coefs = np.asarray(values_conv[1:], dtype='float32')
    embeddings_index[word] = coefs
f.close()
print('Found %s word vectors.' % len(embeddings_index))
embedding_matrix = np.zeros((len(word_index) + 1, 300))
for word, i in tqdm(word_index.items()):
    embedding_vector = embeddings_index.get(word)
    if embedding_vector is not None:
        embedding_matrix[i] = embedding_vector"><pre class="notranslate"><code class="notranslate">THEANO_FLAGS='device=cpu,openmp=True,blas.ldflags=-lopenblas'
OMP_NUM_THREADS=8 
KERAS_BACKEND=theano
import pandas as pd
import numpy as np
from tqdm import tqdm
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dropout
from keras.layers.embeddings import Embedding
from keras.layers.recurrent import LSTM, GRU
from keras.layers.normalization import BatchNormalization
from keras.utils import np_utils
import keras.engine.topology 
from keras.layers import TimeDistributed, Lambda
from keras.layers import Convolution1D, GlobalMaxPooling1D
from keras.callbacks import ModelCheckpoint
from keras import backend as K
from keras.layers.advanced_activations import PReLU
from keras.preprocessing import sequence, text

data = pd.read_csv('data/quora_duplicate_questions.tsv', sep='\t')
y = data.is_duplicate.values
tk = text.Tokenizer(nb_words=200000)
max_len = 40
tk.fit_on_texts(list(data.question1.values) + list(data.question2.values.astype(str)))
x1 = tk.texts_to_sequences(data.question1.values)
x1 = sequence.pad_sequences(x1, maxlen=max_len)
x2 = tk.texts_to_sequences(data.question2.values.astype(str))
x2 = sequence.pad_sequences(x2, maxlen=max_len)
word_index = tk.word_index
ytrain_enc = np_utils.to_categorical(y)
embeddings_index = {}
f = open('data/glove.840B.300d.txt')
values_conv = []
for line in tqdm(f):
    values = line.split()
    for item in values:
        try:
            values_conv.append(float(item))
        except: 
            pass
    word = values_conv[0]
    coefs = np.asarray(values_conv[1:], dtype='float32')
    embeddings_index[word] = coefs
f.close()
print('Found %s word vectors.' % len(embeddings_index))
embedding_matrix = np.zeros((len(word_index) + 1, 300))
for word, i in tqdm(word_index.items()):
    embedding_vector = embeddings_index.get(word)
    if embedding_vector is not None:
        embedding_matrix[i] = embedding_vector
</code></pre></div>
<p dir="auto">I don't really know what the problem is. I would really appreciate any help. Thanks</p>
<p dir="auto">Environment:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import sys
&gt;&gt;&gt; print(sys.version)
3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)]
&gt;&gt;&gt; import tensorflow
&gt;&gt;&gt; tensorflow.__version__
'1.4.0'
&gt;&gt;&gt; import keras
Using TensorFlow backend.
&gt;&gt;&gt; keras.__version__
'2.0.9'"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import sys
&gt;&gt;&gt; print(sys.version)
3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)]
&gt;&gt;&gt; import tensorflow
&gt;&gt;&gt; tensorflow.__version__
'1.4.0'
&gt;&gt;&gt; import keras
Using TensorFlow backend.
&gt;&gt;&gt; keras.__version__
'2.0.9'
</code></pre></div>
<p dir="auto">I can run this code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from tensorflow import Graph
from keras.models import model_from_json
print('loading first model...')
graph1 = Graph()
with graph1.as_default():
    with open('model1_arch.json') as arch_file:
        model1 = model_from_json(arch_file.read())
print('loading second model...')
graph2 = Graph()
with graph2.as_default():
    with open('model2_arch.json') as arch_file:
        model2 = model_from_json(arch_file.read())"><pre class="notranslate"><code class="notranslate">from tensorflow import Graph
from keras.models import model_from_json
print('loading first model...')
graph1 = Graph()
with graph1.as_default():
    with open('model1_arch.json') as arch_file:
        model1 = model_from_json(arch_file.read())
print('loading second model...')
graph2 = Graph()
with graph2.as_default():
    with open('model2_arch.json') as arch_file:
        model2 = model_from_json(arch_file.read())
</code></pre></div>
<p dir="auto">It prints:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using TensorFlow backend.
loading first model...
loading second model..."><pre class="notranslate"><code class="notranslate">Using TensorFlow backend.
loading first model...
loading second model...
</code></pre></div>
<p dir="auto">looks fine.<br>
And this code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from tensorflow import Graph
from keras.models import model_from_json
print('loading first model...')
graph1 = Graph()
with graph1.as_default():
    with open('model1_arch.json') as arch_file:
        model1 = model_from_json(arch_file.read())
    model1.load_weights('model1_weights.h5')   # &lt;--- add this line
print('loading second model...')
graph2 = Graph()
with graph2.as_default():
    with open('model2_arch.json') as arch_file:
        model2 = model_from_json(arch_file.read())"><pre class="notranslate"><code class="notranslate">from tensorflow import Graph
from keras.models import model_from_json
print('loading first model...')
graph1 = Graph()
with graph1.as_default():
    with open('model1_arch.json') as arch_file:
        model1 = model_from_json(arch_file.read())
    model1.load_weights('model1_weights.h5')   # &lt;--- add this line
print('loading second model...')
graph2 = Graph()
with graph2.as_default():
    with open('model2_arch.json') as arch_file:
        model2 = model_from_json(arch_file.read())
</code></pre></div>
<p dir="auto">It prints:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using TensorFlow backend.
loading first model...
2017-11-19 17:00:05.742339: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2017-11-19 17:00:06.276240: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 950M major: 5 minor: 0 memoryClockRate(GHz): 0.928
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.35GiB
2017-11-19 17:00:06.276809: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -&gt; (device: 0, name: GeForce GTX 950M, pci bus id: 0000:01:00.0, compute capability: 5.0)
loading second model..."><pre class="notranslate"><code class="notranslate">Using TensorFlow backend.
loading first model...
2017-11-19 17:00:05.742339: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2017-11-19 17:00:06.276240: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 950M major: 5 minor: 0 memoryClockRate(GHz): 0.928
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.35GiB
2017-11-19 17:00:06.276809: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -&gt; (device: 0, name: GeForce GTX 950M, pci bus id: 0000:01:00.0, compute capability: 5.0)
loading second model...
</code></pre></div>
<p dir="auto">So far so good.</p>
<p dir="auto">However, I run this code:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from tensorflow import Graph
from keras.models import model_from_json
print('loading first model...')
graph1 = Graph()
with graph1.as_default():
    with open('model1_arch.json') as arch_file:
        model1 = model_from_json(arch_file.read())
    model1.load_weights('model1_weights.h5')
print('loading second model...')
graph2 = Graph()
with graph2.as_default():
    with open('model2_arch.json') as arch_file:
        model2 = model_from_json(arch_file.read())
    model2.load_weights('model2_weights.h5')   # &lt;--- add this line"><pre class="notranslate"><code class="notranslate">from tensorflow import Graph
from keras.models import model_from_json
print('loading first model...')
graph1 = Graph()
with graph1.as_default():
    with open('model1_arch.json') as arch_file:
        model1 = model_from_json(arch_file.read())
    model1.load_weights('model1_weights.h5')
print('loading second model...')
graph2 = Graph()
with graph2.as_default():
    with open('model2_arch.json') as arch_file:
        model2 = model_from_json(arch_file.read())
    model2.load_weights('model2_weights.h5')   # &lt;--- add this line
</code></pre></div>
<p dir="auto">It doesn't work.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using TensorFlow backend.
loading first model...
2017-11-19 17:05:23.982670: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2017-11-19 17:05:24.522351: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 950M major: 5 minor: 0 memoryClockRate(GHz): 0.928
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.35GiB
2017-11-19 17:05:24.522861: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -&gt; (device: 0, name: GeForce GTX 950M, pci bus id: 0000:01:00.0, compute capability: 5.0)
loading second model...
Traceback (most recent call last):
  File &quot;C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py&quot;, line 1064, in _run
    allow_operation=False)
  File &quot;C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py&quot;, line 3035, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File &quot;C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py&quot;, line 3114, in _as_graph_element_locked
    raise ValueError(&quot;Tensor %s is not an element of this graph.&quot; % obj)
ValueError: Tensor Tensor(&quot;Placeholder:0&quot;, shape=(40980, 50), dtype=float32) is not an element of this graph.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;D:/university/django-and-bootstrap-template/mysite/rate/models/test/test.py&quot;, line 15, in &lt;module&gt;
    model2.load_weights('model2_weights.h5')
  File &quot;C:\Program Files\Python35\lib\site-packages\keras\models.py&quot;, line 733, in load_weights
    topology.load_weights_from_hdf5_group(f, layers)
  File &quot;C:\Program Files\Python35\lib\site-packages\keras\engine\topology.py&quot;, line 3142, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File &quot;C:\Program Files\Python35\lib\site-packages\keras\backend\tensorflow_backend.py&quot;, line 2247, in batch_set_value
    get_session().run(assign_ops, feed_dict=feed_dict)
  File &quot;C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py&quot;, line 889, in run
    run_metadata_ptr)
  File &quot;C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py&quot;, line 1067, in _run
    + e.args[0])
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor(&quot;Placeholder:0&quot;, shape=(40980, 50), dtype=float32) is not an element of this graph."><pre class="notranslate"><code class="notranslate">Using TensorFlow backend.
loading first model...
2017-11-19 17:05:23.982670: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2017-11-19 17:05:24.522351: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1030] Found device 0 with properties: 
name: GeForce GTX 950M major: 5 minor: 0 memoryClockRate(GHz): 0.928
pciBusID: 0000:01:00.0
totalMemory: 4.00GiB freeMemory: 3.35GiB
2017-11-19 17:05:24.522861: I C:\tf_jenkins\home\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -&gt; (device: 0, name: GeForce GTX 950M, pci bus id: 0000:01:00.0, compute capability: 5.0)
loading second model...
Traceback (most recent call last):
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1064, in _run
    allow_operation=False)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3035, in as_graph_element
    return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\ops.py", line 3114, in _as_graph_element_locked
    raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("Placeholder:0", shape=(40980, 50), dtype=float32) is not an element of this graph.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/university/django-and-bootstrap-template/mysite/rate/models/test/test.py", line 15, in &lt;module&gt;
    model2.load_weights('model2_weights.h5')
  File "C:\Program Files\Python35\lib\site-packages\keras\models.py", line 733, in load_weights
    topology.load_weights_from_hdf5_group(f, layers)
  File "C:\Program Files\Python35\lib\site-packages\keras\engine\topology.py", line 3142, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "C:\Program Files\Python35\lib\site-packages\keras\backend\tensorflow_backend.py", line 2247, in batch_set_value
    get_session().run(assign_ops, feed_dict=feed_dict)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 889, in run
    run_metadata_ptr)
  File "C:\Program Files\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1067, in _run
    + e.args[0])
TypeError: Cannot interpret feed_dict key as Tensor: Tensor Tensor("Placeholder:0", shape=(40980, 50), dtype=float32) is not an element of this graph.
</code></pre></div>
<p dir="auto">I'm trying to duplicate the solution found <a href="https://stackoverflow.com/a/41991989/5161420" rel="nofollow">here</a>.<br>
These two models are good if and only if they're not in each other's way.</p>