import tensorflow as tf import numpy as np import matplotlib.pyplot as plt try: from scipy import misc except ImportError: !pip install scipy from scipy import misc training_size = 300 img_size = 20*20*3 #class Struct: # "A structure that can have any fields defined." # def __init__(self, **entries): self.__dict__.update(entries) #training_images=[]; #training_labels=[]; #training_data= Struct(training_set=training_images, labels=training_labels) training_images = np.empty(shape=(training_size,20,20,3)) import glob i = 0 for filename in glob.glob('D:/Minutia/PrincipleWrinkleMinutia/*.jpg'): image = misc.imread(filename) training_images[i] = image i+=1 print(training_images[0].shape) 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, 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, 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] training_labels = tf.one_hot(a,3) sess = tf.Session() sess.run(training_labels) #################################################### test test_size = 300 img_size = 20*20*3 #class Struct: # "A structure that can have any fields defined." # def __init__(self, **entries): self.__dict__.update(entries) #test_images=[]; #test_labels=[]; #test_data= Struct(training_set=test_images, labels=test_labels) test_images = np.empty(shape=(test_size,20,20,3)) import glob i = 0 for filename in glob.glob('D:/Minutia/PrincipleWrinkleMinutia/*.jpg'): image = misc.imread(filename) test_images[i] = image i+=1 print(test_images[0].shape) 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, 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, 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] test_labels = tf.one_hot(a,3) sess = tf.Session() sess.run(test_labels) #################################################### test test_size = 300 img_size = 20*20*3 #class Struct: # "A structure that can have any fields defined." # def __init__(self, **entries): self.__dict__.update(entries) #test_images=[]; #test_labels=[]; #test_data= Struct(training_set=test_images, labels=test_labels) test_images = np.empty(shape=(test_size,20,20,3)) import glob i = 0 for filename in glob.glob('D:/Minutia/PrincipleWrinkleMinutia/*.jpg'): image = misc.imread(filename) test_images[i] = image i+=1 print(test_images[0].shape) 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, 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, 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] test_labels = tf.one_hot(a,3) sess = tf.Session() sess.run(test_labels) #Similar to MNIST x = tf.placeholder(tf.float64, [None, img_size]) W = tf.Variable(tf.zeros([img_size, 3], dtype=tf.float64)) b = tf.Variable(tf.zeros([3], dtype=tf.float64)) y = tf.nn.softmax(tf.matmul(x, W) + b) y_ = tf.placeholder(tf.float64, [None, 3]) cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1])) train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy) sess = tf.InteractiveSession() #tf.global_variables_initializer().run() tf.local_variables_initializer().run() def next_batch(self, batch_size, fake_data=False, shuffle=True): """Return the next `batch_size` examples from this data set.""" if fake_data: fake_image = [1] * 784 if self.one_hot: fake_label = [1] + [0] * 9 else: fake_label = 0 return [fake_image for _ in xrange(batch_size)], [ fake_label for _ in xrange(batch_size) ] start = self._index_in_epoch # Shuffle for the first epoch if self._epochs_completed == 0 and start == 0 and shuffle: perm0 = numpy.arange(self._num_examples) numpy.random.shuffle(perm0) self._images = self.images[perm0] self._labels = self.labels[perm0] # Go to the next epoch if start + batch_size > self._num_examples: # Finished epoch self._epochs_completed += 1 # Get the rest examples in this epoch rest_num_examples = self._num_examples - start images_rest_part = self._images[start:self._num_examples] labels_rest_part = self._labels[start:self._num_examples] # Shuffle the data if shuffle: perm = numpy.arange(self._num_examples) numpy.random.shuffle(perm) self._images = self.images[perm] self._labels = self.labels[perm] # Start next epoch start = 0 self._index_in_epoch = batch_size - rest_num_examples end = self._index_in_epoch images_new_part = self._images[start:end] labels_new_part = self._labels[start:end] return numpy.concatenate((images_rest_part, images_new_part), axis=0) , numpy.concatenate((labels_rest_part, labels_new_part), axis=0) else: self._index_in_epoch += batch_size end = self._index_in_epoch return self._images[start:end], self._labels[start:end] ######## def next_batch(self): """The `NextQueuedSequenceBatch` providing access to batched output data. Also provides access to the `state` and `save_state` methods. The first time this gets called, it additionally prepares barrier reads and creates `NextQueuedSequenceBatch` / next_batch objects. Subsequent calls simply return the previously created `next_batch`. In order to access data in `next_batch` without blocking, the `prefetch_op` must have been run at least `batch_size` times (ideally in a separate thread, or launched via a `QueueRunner`). After processing a segment in `next_batch()`, `batch.save_state()` must be called which is done by the state_saving_rnn. Without this call, the dequeue op associated with the SQSS will not run. Returns: A cached `NextQueuedSequenceBatch` instance. """ # This is needed to prevent errors if next_batch is called before # prefetch_op is created. if not self._prefetch_op: with ops.name_scope(None), ops.name_scope( self._scope, values=[self._barrier.barrier_ref]): self._create_prefetch_op() if not self._next_batch: with ops.name_scope(None), ops.name_scope( self._scope, values=[self._barrier.barrier_ref]): self._prepare_barrier_reads() return self._next_batch for _ in range(1000): #batch_xs, batch_ys = training_data.next_batch(100) batch_xs, batch_ys = training_images.next_batch(100) sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys}) correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) correct_prediction = tf.equal(training_images, training_labels) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float64)) print(sess.run(accuracy, feed_dict={x: test_images, y_: test_labels}))