Fingerprint detection

来源:互联网 发布:彩虹6号 知乎 编辑:程序博客网 时间:2024/06/05 05:40

1、数据集的构建:将图像转化成相应的格式:01.1.png,01表示假的,1表示图像的编号。由于假指纹spoof中图像的标注是一样,因此需要分别构建10标签,并且图像的递增的顺序是按照1--200, 201--400, 401--600, 601-800的顺序;


http://stackoverflow.com/questions/40994583/how-to-implement-tensorflows-next-batch-for-own-data


import numpy as np

def next_batch(num, data):
    """
    Return a total of `num` samples from the array `data`.
    """
    idx = np.arange(0, len(data))  # get all possible indexes
    np.random.shuffle(idx)  # shuffle indexes
    idx = idx[0:num]  # use only `num` random indexes
    data_shuffle = [data[i] for i in idx]  # get list of `num` random samples
    data_shuffle = np.asarray(data_shuffle)  # get back numpy array

    return data_shuffle

# demo data, 1d and 2d array
Xtr, Ytr = np.arange(0, 10), np.arange(0, 100).reshape(10, 10)
print(Xtr)
print(Ytr)

print("\n5 randnom samples from 1d array:")
print(next_batch(5, Xtr))
print("5 randnom samples from 2d array:")
print(next_batch(5, Ytr))




import numpy as np

class Dataset:

  def __init__(self,data):
      self._index_in_epoch = 0
      self._epochs_completed = 0
      self._data = data
      self._num_examples = data.shape[0]
      pass


  @property
  def data(self):
      return self._data

  def next_batch(self,batch_size,shuffle = True):
      start = self._index_in_epoch
      if start == 0 and self._epochs_completed == 0:
          idx = np.arange(0, self._num_examples)  # get all possible indexes
          np.random.shuffle(idx)  # shuffle indexe
          self._data = self.data[idx]  # get list of `num` random samples

      # go to the next batch
      if start + batch_size > self._num_examples:
          self._epochs_completed += 1
          rest_num_examples = self._num_examples - start
          data_rest_part = self.data[start:self._num_examples]
          idx0 = np.arange(0, self._num_examples)  # get all possible indexes
          np.random.shuffle(idx0)  # shuffle indexes
          self._data = self.data[idx0]  # get list of `num` random samples

          start = 0
          self._index_in_epoch = batch_size - rest_num_examples #avoid the case where the #sample != integar times of batch_size
          end =  self._index_in_epoch  
          data_new_part =  self._data[start:end]  
          return np.concatenate((data_rest_part, data_new_part), axis=0)
      else:
          self._index_in_epoch += batch_size
          end = self._index_in_epoch
          return self._data[start:end]

dataset = Dataset(np.arange(0, 10))
for i in range(10):
  print(dataset.next_batch(5))

0 0