Created
March 20, 2017 00:50
-
-
Save grantwwoodford/646dcaf6288ff47f153daae27afaa596 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create first network with Keras | |
from keras.models import Sequential | |
from keras.layers import Dense | |
import numpy | |
import threading as t | |
import tensorflow as tf | |
graph = tf.get_default_graph() | |
def t_thread(): | |
with graph.as_default(): | |
# create model | |
model = Sequential() | |
model.add(Dense(12, input_dim=8, init='uniform', activation='relu')) | |
model.add(Dense(8, init='uniform', activation='relu')) | |
model.add(Dense(1, init='uniform', activation='sigmoid')) | |
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) | |
# evaluate the model | |
scores = model.evaluate(numpy.array([[0,0,0,0,0,0,0,0]]), numpy.array([[1]])) | |
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100)) | |
# versus thread - does not work | |
th = t.Thread(target=t_thread) | |
th.start() | |
th.join() | |
th2 = t.Thread(target=t_thread) | |
th2.start() | |
th2.join() | |
th3 = t.Thread(target=t_thread) | |
th3.start() | |
th3.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment