def test_masking(self):
    with self.cached_session():
        np.random.seed(1337)
        x = np.array([[[1], [1]], [[0], [0]]])
        model = keras.models.Sequential()
        model.add(keras.layers.Masking(mask_value=0, input_shape=(2, 1)))
        model.add(keras.layers.TimeDistributed(keras.layers.Dense(1, kernel_initializer='one')))
        strategy = mirrored_strategy.MirroredStrategy(['/device:GPU:1', '/device:GPU:0'])
        model.compile(loss='mse', optimizer=gradient_descent.GradientDescentOptimizer(0.01), distribute=strategy)
        y = np.array([[[1], [1]], [[1], [1]]])
        dataset = dataset_ops.Dataset.from_tensor_slices((x, y))
        dataset = dataset.repeat(100)
        dataset = dataset.batch(10)
        hist = model.fit(x=dataset, epochs=1, steps_per_epoch=2)
        self.assertEqual(hist.history['loss'][0], 0)
def test_masking(self):
    with self.cached_session():
        np.random.seed(1337)
        x = np.array([[[1], [1]], [[0], [0]]])
        model = keras.models.Sequential()
        model.add(keras.layers.Masking(mask_value=0, input_shape=(2, 1)))
        model.add(keras.layers.TimeDistributed(keras.layers.Dense(1, kernel_initializer='one')))
        strategy = mirrored_strategy.MirroredStrategy(['/device:GPU:1', '/device:GPU:0'])
        model.compile(loss='mse', optimizer=gradient_descent.GradientDescentOptimizer(0.01), distribute=strategy)
        y = np.array([[[1], [1]], [[1], [1]]])
        dataset = dataset_ops.Dataset.from_tensor_slices((x, y))
        dataset = dataset.repeat(100)
        dataset = dataset.batch(10)
        hist = model.fit(x=dataset, epochs=1, steps_per_epoch=2)
        self.assertEqual(hist.history['loss'][0], 0)