@combinations.generate(strategy_combinations())
def test_batchnorm_correctness(self, distribution):
    with self.cached_session():
        model = keras.models.Sequential()
        norm = keras.layers.BatchNormalization(input_shape=(10,), momentum=0.8)
        model.add(norm)
        model.compile(loss='mse', optimizer=gradient_descent.GradientDescentOptimizer(0.01), distribute=distribution)
        x = np.random.normal(loc=5.0, scale=10.0, size=(1000, 10))
        x = x.astype('float32')
        dataset = dataset_ops.Dataset.from_tensor_slices((x, x))
        dataset = dataset.repeat(100)
        dataset = batch_wrapper(dataset, 32, distribution)
        predict_dataset = dataset_ops.Dataset.from_tensor_slices(x)
        predict_dataset = predict_dataset.repeat(100)
        predict_dataset = batch_wrapper(predict_dataset, 32, distribution)
        model.fit(dataset, epochs=4, verbose=0, steps_per_epoch=10)
        out = model.predict(predict_dataset, steps=2)
        out -= keras.backend.eval(norm.beta)
        out /= keras.backend.eval(norm.gamma)
        np.testing.assert_allclose(out.mean(), 0.0, atol=0.1)
        np.testing.assert_allclose(out.std(), 1.0, atol=0.1)
@combinations.generate(strategy_combinations())
def test_batchnorm_correctness(self, distribution):
    with self.cached_session():
        model = keras.models.Sequential()
        norm = keras.layers.BatchNormalization(input_shape=(10,), momentum=0.8)
        model.add(norm)
        model.compile(loss='mse', optimizer=gradient_descent.GradientDescentOptimizer(0.01), distribute=distribution)
        x = np.random.normal(loc=5.0, scale=10.0, size=(1000, 10))
        x = x.astype('float32')
        dataset = dataset_ops.Dataset.from_tensor_slices((x, x))
        dataset = dataset.repeat(100)
        dataset = batch_wrapper(dataset, 32, distribution)
        predict_dataset = dataset_ops.Dataset.from_tensor_slices(x)
        predict_dataset = predict_dataset.repeat(100)
        predict_dataset = batch_wrapper(predict_dataset, 32, distribution)
        model.fit(dataset, epochs=4, verbose=0, steps_per_epoch=10)
        out = model.predict(predict_dataset, steps=2)
        out -= keras.backend.eval(norm.beta)
        out /= keras.backend.eval(norm.gamma)
        np.testing.assert_allclose(out.mean(), 0.0, atol=0.1)
        np.testing.assert_allclose(out.std(), 1.0, atol=0.1)