예제 #1
0
  def testArrayFeedFnBatchTwoWithOneEpoch(self):
    array = np.arange(5) + 10
    placeholders = ["index_placeholder", "value_placeholder"]
    aff = ff._ArrayFeedFn(placeholders, array, batch_size=2, num_epochs=1)

    expected = {
        "index_placeholder": [0, 1],
        "value_placeholder": [10, 11]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))

    expected = {
        "index_placeholder": [2, 3],
        "value_placeholder": [12, 13]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))

    expected = {
        "index_placeholder": [4],
        "value_placeholder": [14]
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
예제 #2
0
  def testArrayFeedFnBatchOneHundred(self):
    array = np.arange(32).reshape([16, 2])
    placeholders = ["index_placeholder", "value_placeholder"]
    aff = ff._ArrayFeedFn(placeholders, array, 100)

    expected = {"index_placeholder": list(range(0, 16)) * 6 + list(range(0, 4)),
                "value_placeholder": np.arange(32).reshape([16, 2]).tolist() * 6
                                     + [[0, 1], [2, 3], [4, 5], [6, 7]]}
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
예제 #3
0
  def testArrayFeedFnBatchOneHundredWithSmallerArrayAndMultipleEpochs(self):
    array = np.arange(2) + 10
    placeholders = ["index_placeholder", "value_placeholder"]
    aff = ff._ArrayFeedFn(placeholders, array, batch_size=100, num_epochs=2)

    expected = {
        "index_placeholder": [0, 1, 0, 1],
        "value_placeholder": [10, 11, 10, 11],
    }
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))
예제 #4
0
  def testArrayFeedFnBatchOne(self):
    array = np.arange(32).reshape([16, 2])
    placeholders = ["index_placeholder", "value_placeholder"]
    aff = ff._ArrayFeedFn(placeholders, array, 1)

    # cycle around a couple times
    for x in range(0, 100):
      i = x % 16
      expected = {"index_placeholder": [i],
                  "value_placeholder": [[2 * i, 2 * i + 1]]}
      actual = aff()
      self.assertEqual(expected, vals_to_list(actual))
예제 #5
0
  def testArrayFeedFnBatchFive(self):
    array = np.arange(32).reshape([16, 2])
    placeholders = ["index_placeholder", "value_placeholder"]
    aff = ff._ArrayFeedFn(placeholders, array, 5)

    # cycle around a couple times
    for _ in range(0, 101, 2):
      aff()

    expected = {"index_placeholder": [15, 0, 1, 2, 3],
                "value_placeholder": [[30, 31], [0, 1], [2, 3], [4, 5], [6, 7]]}
    actual = aff()
    self.assertEqual(expected, vals_to_list(actual))