Created
August 23, 2017 07:18
-
-
Save leechanwoo/79a2e5fb86ca3fce69d95f86a880450d to your computer and use it in GitHub Desktop.
get accuracy
This file contains 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
import tensorflow as tf | |
samples = 1000 | |
up = [i for i in range(10)] | |
down = [9-i for i in range(10)] | |
data = [up if i%2 == 0 else down for i in range(samples)] | |
label = [[1] if i%2 == 0 else [0] for i in range(samples)] | |
tf.reset_default_graph() | |
x = tf.placeholder(tf.float32, shape=[None, 10]) | |
y_ = tf.placeholder(tf.int32) | |
layer1 = tf.layers.dense(x, 20) | |
layer2 = tf.layers.dense(layer1, 15) | |
layer3 = tf.layers.dense(layer2, 30) | |
layer4 = tf.layers.dense(layer3, 10) | |
layer5 = tf.layers.dense(layer4, 5) | |
out = tf.layers.dense(layer5, 1) | |
pred = tf.cast(tf.round(tf.nn.sigmoid(out)), tf.int32) | |
y_ = tf.cast(y_, tf.int32) | |
comp = tf.cast(tf.equal(pred, y_), tf.float32) | |
accuracy = tf.reduce_mean(comp) | |
saver = tf.train.Saver() | |
with tf.Session() as sess: | |
saver.restore(sess, "./checkpoint/simple_neuralnet") | |
_pred, _acc = sess.run([pred, accuracy], {x: data, y_: label}) | |
print("prediction: {}".format(_pred[:10])) | |
print("accuracy: ", _acc) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment