@tf_test_util.run_in_graph_and_eager_modes()
def test_metrics_correctness_with_iterator(self):
    model = keras.Sequential()
    model.add(keras.layers.Dense(8, activation='relu', input_dim=4, kernel_initializer='ones'))
    model.add(keras.layers.Dense(1, activation='sigmoid', kernel_initializer='ones'))
    model.compile(loss='binary_crossentropy', metrics=['accuracy'], optimizer=RMSPropOptimizer(learning_rate=0.001))
    np.random.seed(123)
    x = np.random.randint(10, size=(100, 4)).astype(np.float32)
    y = np.random.randint(2, size=(100, 1)).astype(np.float32)
    dataset = dataset_ops.Dataset.from_tensor_slices((x, y))
    dataset = dataset.batch(10)
    iterator = dataset.make_one_shot_iterator()
    outs = model.evaluate(iterator, steps=10)
    self.assertEqual(np.around(outs[1], decimals=1), 0.5)
    y = np.zeros((100, 1), dtype=np.float32)
    dataset = dataset_ops.Dataset.from_tensor_slices((x, y))
    dataset = dataset.repeat(100)
    dataset = dataset.batch(10)
    iterator = dataset.make_one_shot_iterator()
    outs = model.evaluate(iterator, steps=10)
    self.assertEqual(outs[1], 0.0)
@tf_test_util.run_in_graph_and_eager_modes()
def test_metrics_correctness_with_iterator(self):
    model = keras.Sequential()
    model.add(keras.layers.Dense(8, activation='relu', input_dim=4, kernel_initializer='ones'))
    model.add(keras.layers.Dense(1, activation='sigmoid', kernel_initializer='ones'))
    model.compile(loss='binary_crossentropy', metrics=['accuracy'], optimizer=RMSPropOptimizer(learning_rate=0.001))
    np.random.seed(123)
    x = np.random.randint(10, size=(100, 4)).astype(np.float32)
    y = np.random.randint(2, size=(100, 1)).astype(np.float32)
    dataset = dataset_ops.Dataset.from_tensor_slices((x, y))
    dataset = dataset.batch(10)
    iterator = dataset.make_one_shot_iterator()
    outs = model.evaluate(iterator, steps=10)
    self.assertEqual(np.around(outs[1], decimals=1), 0.5)
    y = np.zeros((100, 1), dtype=np.float32)
    dataset = dataset_ops.Dataset.from_tensor_slices((x, y))
    dataset = dataset.repeat(100)
    dataset = dataset.batch(10)
    iterator = dataset.make_one_shot_iterator()
    outs = model.evaluate(iterator, steps=10)
    self.assertEqual(outs[1], 0.0)