Exemple #1
0
    def test_sparsemax_layer_against_numpy(self, dtype=None):
        """check sparsemax kernel against numpy."""
        random = np.random.RandomState(1)

        z = random.uniform(low=-3, high=3, size=(test_obs, 10)).astype(dtype)

        test_utils.layer_test(layer_cls=Sparsemax,
                              input_data=z,
                              expected_output=_np_sparsemax(z).astype(dtype))
Exemple #2
0
    def test_unknown(self):
        inputs = np.random.random((5, 4, 2, 18)).astype('float32')
        test_utils.layer_test(Maxout,
                              kwargs={'num_units': 3},
                              input_shape=(5, 4, 2, None),
                              input_data=inputs)

        test_utils.layer_test(Maxout,
                              kwargs={'num_units': 3},
                              input_shape=(None, None, None, None),
                              input_data=inputs)
Exemple #3
0
    def test_nchw(self):
        test_utils.layer_test(Maxout,
                              kwargs={
                                  'num_units': 4,
                                  'axis': 1
                              },
                              input_shape=(2, 20, 3, 6))

        test_utils.layer_test(Maxout,
                              kwargs={
                                  'num_units': 4,
                                  'axis': -3
                              },
                              input_shape=(2, 20, 3, 6))
Exemple #4
0
 def test_weightnorm_keras(self):
     input_data = np.random.random((10, 3, 4)).astype(np.float32)
     outputs = test_utils.layer_test(wrappers.WeightNormalization,
                                     kwargs={
                                         'layer': tf.keras.layers.Dense(2),
                                         'input_shape': (3, 4)
                                     },
                                     input_data=input_data)
Exemple #5
0
    def testPoincareNormalizeDimArray(self):
        x_shape = [20, 7, 3]
        epsilon = 1e-5
        tol = 1e-6
        np.random.seed(1)
        inputs = np.random.random_sample(x_shape).astype(np.float32)
        dim = [1, 2]

        outputs_expected = self._PoincareNormalize(inputs, dim, epsilon)

        outputs = test_utils.layer_test(
            PoincareNormalize,
            kwargs={
                'axis': dim,
                'epsilon': epsilon
            },
            input_data=inputs,
            expected_output=outputs_expected)
        for y in outputs_expected, outputs:
            norm = np.linalg.norm(y, axis=tuple(dim))
            self.assertLessEqual(norm.max(), 1. - epsilon + tol)
Exemple #6
0
 def test_invalid_shape(self):
     with self.assertRaisesRegexp(ValueError, r'number of features'):
         test_utils.layer_test(Maxout,
                               kwargs={'num_units': 3},
                               input_shape=(5, 4, 2, 7))
Exemple #7
0
 def test_simple(self):
     test_utils.layer_test(Maxout,
                           kwargs={'num_units': 3},
                           input_shape=(5, 4, 2, 18))