Guest User

Untitled

a guest
Nov 22nd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. x = tf.placeholder(tf.float32, [None, 784])
  2.  
  3. W = tf.Variable(tf.zeros([784, 10]))
  4. b = tf.Variable(tf.zeros([10]))
  5.  
  6. y = tf.nn.softmax(tf.matmul(x, W) + b)
  7.  
  8. y_ = tf.placeholder(tf.float32, [None, 10])
  9.  
  10. cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
  11.  
  12. train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
  13.  
  14. sess = tf.InteractiveSession()
  15. tf.global_variables_initializer().run()
  16.  
  17. correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
  18.  
  19. accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  20.  
  21. print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
  22.  
  23. def train(data):
  24. global train_step, x, y
  25. trd = []
  26.  
  27. # getting a letter from Option Menu
  28. l = dropVar.get()
  29. if l == 'a':
  30. trd = [1, 0, 0]
  31. # and so on
  32.  
  33. sess.run(train_step, feed_dict={x: data, y_: trd})
  34.  
  35. def test(data):
  36. global x, y_, y
  37. trd = []
  38.  
  39. # getting a letter from Option Menu
  40. l = dropVar.get()
  41. if l == 'a':
  42. trd = [1, 0, 0]
  43. # and so on
  44.  
  45. correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
  46. accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  47. print(sess.run(accuracy, feed_dict={x: data, y_: trd}))
  48.  
  49. # data is an image converted into a vector
Add Comment
Please, Sign In to add comment