@combinations.generate(strategy_combinations())
def test_metric_correctness(self, distribution):
    with self.cached_session():
        keras.backend.set_image_data_format('channels_last')
        num_samples = 10000
        x_train = np.random.randint(0, 2, num_samples)
        x_train = np.reshape(x_train, (num_samples, 1))
        y_train = x_train
        x_train = x_train.astype('float32')
        y_train = y_train.astype('float32')
        model = keras.Sequential()
        model.add(keras.layers.Dense(1, input_shape=(1,), kernel_initializer='ones'))
        model.compile(loss=keras.losses.mean_squared_error, optimizer=gradient_descent.GradientDescentOptimizer(0.5), metrics=[keras.metrics.BinaryAccuracy()], distribute=distribution)
        batch_size = 64
        batch_size //= distribution.num_replicas_in_sync
        train_dataset = dataset_ops.Dataset.from_tensor_slices((x_train, y_train))
        train_dataset = batch_wrapper(train_dataset, batch_size, distribution)
        history = model.fit(x=train_dataset, epochs=1, steps_per_epoch=10)
        self.assertEqual(history.history['binary_accuracy'], [1.0])
@combinations.generate(strategy_combinations())
def test_metric_correctness(self, distribution):
    with self.cached_session():
        keras.backend.set_image_data_format('channels_last')
        num_samples = 10000
        x_train = np.random.randint(0, 2, num_samples)
        x_train = np.reshape(x_train, (num_samples, 1))
        y_train = x_train
        x_train = x_train.astype('float32')
        y_train = y_train.astype('float32')
        model = keras.Sequential()
        model.add(keras.layers.Dense(1, input_shape=(1,), kernel_initializer='ones'))
        model.compile(loss=keras.losses.mean_squared_error, optimizer=gradient_descent.GradientDescentOptimizer(0.5), metrics=[keras.metrics.BinaryAccuracy()], distribute=distribution)
        batch_size = 64
        batch_size //= distribution.num_replicas_in_sync
        train_dataset = dataset_ops.Dataset.from_tensor_slices((x_train, y_train))
        train_dataset = batch_wrapper(train_dataset, batch_size, distribution)
        history = model.fit(x=train_dataset, epochs=1, steps_per_epoch=10)
        self.assertEqual(history.history['binary_accuracy'], [1.0])