Skip to content

Instantly share code, notes, and snippets.

@mineshpatel1
Created November 2, 2017 14:14
Show Gist options
  • Save mineshpatel1/7b8f9eee3c3a6cbf7c38d2352d1c99c3 to your computer and use it in GitHub Desktop.
Save mineshpatel1/7b8f9eee3c3a6cbf7c38d2352d1c99c3 to your computer and use it in GitHub Desktop.
Sudoku Solver 3 - Appendix 2 #blog #bernard
def simple_network():
x = tf.placeholder(tf.float32, shape=[None, 784]) # Placeholder for input
y_ = tf.placeholder(tf.float32, shape=[None, 10]) # Placeholder for true labels (used in training)
hidden_neurons = 16 # Number of neurons in the hidden layer
# Hidden layer
w_1 = weights([784, hidden_neurons])
b_1 = biases([hidden_neurons])
h_1 = tf.nn.sigmoid(tf.matmul(x, w_1) + b_1) # Order of x and w_1 matters here purely syntactically
# Output layer
w_2 = weights([hidden_neurons, 10])
b_2 = biases([10])
y = tf.matmul(h_1, w_2) + b_2 # Note that we don't use sigmoid here because the next step uses softmax
return x, y, y_
def predict_digits(test_images, model_path):
x, y, y_ = simple_network() # Get our network graph and associated variables
saver = tf.train.Saver()
with tf.Session() as sess:
try:
saver.restore(sess, model_path)
except:
print('Could not load saved model.')
return False
prediction = tf.argmax(y, 1)
out = prediction.eval(feed_dict={x: test_images}) # Feed in our test images
return out # Return a prediction for each image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment