コード例 #1
0
  def test_unweighted_ragged_reduction(self, reduction_str, expected_output):
    data = ragged_factory_ops.constant([[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]],
                                        [[3.0, 1.0], [1.0, 2.0]]])
    input_tensor = keras.Input(shape=(None, None), ragged=True)

    output_tensor = reduction.Reduction(reduction=reduction_str)(input_tensor)
    model = keras.Model(input_tensor, output_tensor)

    output = model.predict(data)

    self.assertAllClose(expected_output, output)
コード例 #2
0
  def test_unweighted_dense_reduction(self, reduction_str, expected_output):
    data = np.array([[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]],
                     [[3.0, 1.0], [1.0, 2.0], [0.0, 0.0]]])
    input_tensor = keras.Input(shape=(None, None))

    output_tensor = reduction.Reduction(reduction=reduction_str)(input_tensor)
    model = keras.Model(input_tensor, output_tensor)

    output = model.predict(data)

    self.assertAllClose(expected_output, output)
コード例 #3
0
    def test_weighted_dense_reduction_with_different_dimensionality(self):
        data = np.array([[[1.0, 1.0], [2.0, 2.0], [3.0, 3.0]],
                         [[3.0, 1.0], [1.0, 2.0], [0.0, 0.0]]])
        input_tensor = keras.Input(shape=(None, None))

        weights = np.array([[1.0, 2.0, 1.0], [1.0, 1.0, 0.0]])
        weight_input_tensor = keras.Input(shape=(None, ))

        output_tensor = reduction.Reduction(reduction="mean")(
            input_tensor, weights=weight_input_tensor)
        model = keras.Model([input_tensor, weight_input_tensor], output_tensor)

        output = model.predict([data, weights])
        expected_output = [[2.0, 2.0], [2.0, 1.5]]
        self.assertAllClose(expected_output, output)
コード例 #4
0
    def test_weighted_ragged_reduction_with_different_dimensionality(self):
        data = ragged_factory_ops.constant([[[1.0, 1.0], [2.0, 2.0],
                                             [3.0, 3.0]],
                                            [[3.0, 1.0], [1.0, 2.0]]])
        input_tensor = keras.Input(shape=(None, None), ragged=True)

        weights = ragged_factory_ops.constant([[1.0, 2.0, 1.0], [1.0, 1.0]])
        weight_input_tensor = keras.Input(shape=(None, ), ragged=True)

        output_tensor = reduction.Reduction(reduction="mean")(
            input_tensor, weights=weight_input_tensor)
        model = keras.Model([input_tensor, weight_input_tensor], output_tensor)

        output = model.predict([data, weights])
        expected_output = [[2.0, 2.0], [2.0, 1.5]]
        self.assertAllClose(expected_output, output)
コード例 #5
0
 def test_sqrtn_fails_on_unweighted_dense(self):
     input_tensor = keras.Input(shape=(None, None))
     with self.assertRaisesRegex(ValueError, ".*sqrtn.*"):
         _ = reduction.Reduction(reduction="sqrtn")(input_tensor)