Guest User

Untitled

a guest
Oct 17th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. #%from tensorflow.examples.tutorials.mnist import input_data
  2. #mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
  3. #x = tf.placeholder(tf.float32, [None, 784])
  4. #W = tf.Variable(tf.zeros([784, 10]))
  5. #b = tf.Variable(tf.zeros([10]))
  6. #y = tf.nn.softmax(tf.matmul(x, W) + b)
  7. #y_ = tf.placeholder(tf.float32, [None, 10])
  8. #cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
  9. #train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
  10. #sess = tf.InteractiveSession()
  11. #tf.global_variables_initializer().run()
  12. #for _ in range(1000):
  13. # batch_xs, batch_ys = mnist.train.next_batch(100)
  14. #sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
  15. # correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
  16. #accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
  17. #print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))%
  18.  
  19.  
  20. import tensorflow as tf
  21. import numpy as np
  22. import matplotlib.pyplot as plt
  23. try:
  24. from scipy import misc
  25. except ImportError:
  26. !pip install scipy
  27. from scipy import misc
  28.  
  29. ############################################ train
  30. training_size = 300
  31. img_size = 20*20*3
  32.  
  33. class Struct:
  34. "A structure that can have any fields defined."
  35. def __init__(self, **entries): self.__dict__.update(entries)
  36. training_images=[];
  37. training_labels=[];
  38. training_data= Struct(training_set=training_images, labels=training_labels)
  39. training_images = np.empty(shape=(training_size,20,20,3))
  40. import glob
  41. i = 0
  42. for filename in glob.glob('D:/Minutia/PrincipleWrinkleMinutia/*.jpg'):
  43. image = misc.imread(filename)
  44. training_images[i] = image
  45. i+=1
  46. print(training_images[0].shape)
  47.  
  48. a= [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  49. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  50. 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
  51. training_labels = tf.one_hot(a,3)
  52. sess = tf.Session()
  53. sess.run(training_labels)
  54.  
  55. #################################################### test
  56. test_size = 300
  57. img_size = 20*20*3
  58. class Struct:
  59. "A structure that can have any fields defined."
  60. def __init__(self, **entries): self.__dict__.update(entries)
  61. test_images=[];
  62. test_labels=[];
  63. test_data= Struct(training_set=test_images, labels=test_labels)
  64.  
  65. test_images = np.empty(shape=(test_size,20,20,3))
  66. import glob
  67. i = 0
  68. for filename in glob.glob('D:/Minutia/PrincipleWrinkleMinutia/*.jpg'):
  69. image = misc.imread(filename)
  70. test_images[i] = image
  71. i+=1
  72. print(test_images[0].shape)
  73. a= [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  74. 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  75. 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
  76. test_labels = tf.one_hot(a,3)
  77. sess = tf.Session()
  78. sess.run(test_labels)
  79.  
  80. x = tf.placeholder(tf.float64, [None, img_size])
  81. W = tf.Variable(tf.zeros([img_size, 3], dtype=tf.float64))
  82. b = tf.Variable(tf.zeros([3], dtype=tf.float64))
  83. y = tf.nn.softmax(tf.matmul(x, W) + b)
  84. y_ = tf.placeholder(tf.float64, [None, 3])
  85. cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
  86. train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
  87. sess = tf.InteractiveSession()
  88. tf.global_variables_initializer().run()
  89.  
  90. for _ in range(300):
  91. batch_xs, batch_ys = training_data.next_batch(100)
  92. sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
  93. correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
  94. correct_prediction = tf.equal(training_images, training_labels)
  95. accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float64))
  96. print(sess.run(accuracy, feed_dict={x: test_images, y_: test_labels}))
Advertisement
Add Comment
Please, Sign In to add comment