Issue 1:
Hi ,

I have the same issue as #5601 (I am unable to force Keras + Theano to use more than 1 thread using OpenBLAS.) I have applied all suggestion mentioned on issue #5601, It works on:

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)

but it doesn't work on :

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

I don't really know what the problem is. I would really appreciate any help. Thanks

Issue 2:
Environment:

>>> import sys
>>> print(sys.version)
3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)]
>>> import tensorflow
>>> tensorflow.__version__
'1.4.0'
>>> import keras
Using TensorFlow backend.
>>> keras.__version__
'2.0.9'

I can run this code:

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())

It prints:

Using TensorFlow backend.
loading first model...
loading second model...

looks fine.

And this code:

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') # <--- 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())

It prints:

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) -> (device: 0, name: GeForce GTX 950M, pci bus id: 0000:01:00.0, compute capability: 5.0)
loading second model...

So far so good.

However, I run this code:

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') # <--- add this line

It doesn't work.

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) -> (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 <module>
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.

I'm trying to duplicate the solution found here.

These two models are good if and only if they're not in each other's way.