def test_learning_phase_value(self):
    with self.cached_session():
        x = keras.layers.Input(shape=(1,), name='input')
        y = keras.layers.Dense(1, kernel_initializer='ones')(x)
        z = keras.layers.Dropout(0.9999)(y)
        model = keras.Model(x, z)
        initial_weights = model.get_weights()
        optimizer = gradient_descent.GradientDescentOptimizer(0.005)
        loss = 'mse'
        metrics = ['acc']
        strategy = mirrored_strategy.MirroredStrategy(['/device:GPU:0', '/device:GPU:1'])
        model.compile(optimizer, loss, metrics=metrics, distribute=strategy)
        inputs = np.ones((10, 1), dtype=np.float32)
        targets = np.ones((10, 1), dtype=np.float32)
        dataset = dataset_ops.Dataset.from_tensor_slices((inputs, targets))
        dataset = dataset.repeat().batch(8)
        hist = model.fit(dataset, epochs=1, steps_per_epoch=20, verbose=1)
        self.assertAlmostEqual(hist.history['acc'][0], 0, 0)
        model.set_weights(initial_weights)
        inputs = np.ones((10, 1), dtype=np.float32)
        predict_dataset = dataset_ops.Dataset.from_tensor_slices(inputs)
        predict_dataset = predict_dataset.repeat().batch(5)
        output = model.predict(predict_dataset, steps=10)
        ref_output = np.ones((100, 1), dtype=np.float32)
        self.assertArrayNear(output, ref_output, 0.1)
def test_learning_phase_value(self):
    with self.cached_session():
        x = keras.layers.Input(shape=(1,), name='input')
        y = keras.layers.Dense(1, kernel_initializer='ones')(x)
        z = keras.layers.Dropout(0.9999)(y)
        model = keras.Model(x, z)
        initial_weights = model.get_weights()
        optimizer = gradient_descent.GradientDescentOptimizer(0.005)
        loss = 'mse'
        metrics = ['acc']
        strategy = mirrored_strategy.MirroredStrategy(['/device:GPU:0', '/device:GPU:1'])
        model.compile(optimizer, loss, metrics=metrics, distribute=strategy)
        inputs = np.ones((10, 1), dtype=np.float32)
        targets = np.ones((10, 1), dtype=np.float32)
        dataset = dataset_ops.Dataset.from_tensor_slices((inputs, targets))
        dataset = dataset.repeat().batch(8)
        hist = model.fit(dataset, epochs=1, steps_per_epoch=20, verbose=1)
        self.assertAlmostEqual(hist.history['acc'][0], 0, 0)
        model.set_weights(initial_weights)
        inputs = np.ones((10, 1), dtype=np.float32)
        predict_dataset = dataset_ops.Dataset.from_tensor_slices(inputs)
        predict_dataset = predict_dataset.repeat().batch(5)
        output = model.predict(predict_dataset, steps=10)
        ref_output = np.ones((100, 1), dtype=np.float32)
        self.assertArrayNear(output, ref_output, 0.1)