LoginSignup
3
3

More than 5 years have passed since last update.

TensorFlow > link > mnist.train.next_batch()の定義 @ github

Last updated at Posted at 2016-10-21

mnist_with_summaries.py
にある以下の定義。

xs, ys = mnist.train.next_batch(100, fake_data=FLAGS.fake_data)

QMCを組込むにはこのあたりを改変する必要がある。
関連 http://qiita.com/7of9/items/f9e243d23240c3316f28

githubでは以下でnext_batch()のdefを見つけた。
tensorflow/tensorflow/contrib/learn/python/learn/datasets/mnist.py
https://github.com/tensorflow/tensorflow/blob/754048a0453a04a761e112ae5d99c149eb9910dd/tensorflow/contrib/learn/python/learn/datasets/mnist.py

def next_batch(self, batch_size, fake_data=False):
    """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
    self._index_in_epoch += batch_size
    if self._index_in_epoch > self._num_examples:
      # Finished epoch
      self._epochs_completed += 1
      # Shuffle the data
      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
      assert batch_size <= self._num_examples
    end = self._index_in_epoch
    return self._images[start:end], self._labels[start:end]

fake_dataでない時はstartとendを計算して、tupleで返している。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3