Ejemplo n.º 1
0
 def testL2NormalizeDimArray(self):
   x_shape = [20, 7, 3]
   np.random.seed(1)
   x_np = np.random.random_sample(x_shape).astype(np.float32)
   dim = [1, 2]
   y_np = self._l2Normalize(x_np, dim)
   x_tf = constant_op.constant(x_np, name="x")
   y_tf = nn_impl.l2_normalize_v2(x_tf, dim)
   self.assertAllClose(y_np, self.evaluate(y_tf))
Ejemplo n.º 2
0
 def testL2NormalizeDimArray(self):
   x_shape = [20, 7, 3]
   np.random.seed(1)
   x_np = np.random.random_sample(x_shape).astype(np.float32)
   dim = [1, 2]
   y_np = self._l2Normalize(x_np, dim)
   x_tf = constant_op.constant(x_np, name="x")
   y_tf = nn_impl.l2_normalize_v2(x_tf, dim)
   self.assertAllClose(y_np, self.evaluate(y_tf))
Ejemplo n.º 3
0
 def testL2NormalizeGradient(self):
   x_shape = [20, 7, 3]
   np.random.seed(1)
   x_np = np.random.random_sample(x_shape).astype(np.float64)
   for dim in range(len(x_shape)):
     with self.cached_session():
       x_tf = constant_op.constant(x_np, name="x")
       y_tf = nn_impl.l2_normalize_v2(x_tf, dim)
       err = gradient_checker.compute_gradient_error(x_tf, x_shape, y_tf,
                                                     x_shape)
     print("L2Normalize gradient err = %g " % err)
     self.assertLess(err, 1e-4)
Ejemplo n.º 4
0
 def testL2NormalizeGradient(self):
   x_shape = [20, 7, 3]
   np.random.seed(1)
   x_np = np.random.random_sample(x_shape).astype(np.float64)
   for dim in range(len(x_shape)):
     with self.cached_session():
       x_tf = constant_op.constant(x_np, name="x")
       y_tf = nn_impl.l2_normalize_v2(x_tf, dim)
       err = gradient_checker.compute_gradient_error(x_tf, x_shape, y_tf,
                                                     x_shape)
     print("L2Normalize gradient err = %g " % err)
     self.assertLess(err, 1e-4)