Exemple #1
0
 def test_reshape_inputs(self):
     """Test that layers can automatically reshape inconsistent inputs."""
     value1 = np.random.uniform(size=(2, 3)).astype(np.float32)
     value2 = np.random.uniform(size=(1, 6, 1)).astype(np.float32)
     with self.session() as sess:
         out_tensor = ReduceSquareDifference()(tf.constant(value1),
                                               tf.constant(value2))
         result = out_tensor.eval()
         diff = value1.reshape((1, 6, 1)) - value2
         loss = np.mean(diff**2)
         assert (loss - result) / loss < 1e-6
Exemple #2
0
 def test_reshape_inputs(self):
   """Test that layers can automatically reshape inconsistent inputs."""
   value1 = np.random.uniform(size=(2, 3)).astype(np.float32)
   value2 = np.random.uniform(size=(1, 6, 1)).astype(np.float32)
   with self.session() as sess:
     out_tensor = ReduceSquareDifference()(tf.constant(value1),
                                           tf.constant(value2))
     result = out_tensor.eval()
     diff = value1.reshape((1, 6, 1)) - value2
     loss = np.mean(diff**2)
     assert (loss - result) / loss < 1e-6
Exemple #3
0
 def test_reduce_square_difference(self):
     """Test that ReduceSquareDifference can be invoked."""
     batch_size = 10
     n_features = 5
     in_tensor_1 = np.random.rand(batch_size, n_features)
     in_tensor_2 = np.random.rand(batch_size, n_features)
     with self.session() as sess:
         in_tensor_1 = tf.convert_to_tensor(in_tensor_1, dtype=tf.float32)
         in_tensor_2 = tf.convert_to_tensor(in_tensor_2, dtype=tf.float32)
         out_tensor = ReduceSquareDifference()(in_tensor_1, in_tensor_2)
         out_tensor = out_tensor.eval()
         assert isinstance(out_tensor, np.float32)
Exemple #4
0
 def test_reduce_square_difference(self):
   """Test that ReduceSquareDifference can be invoked."""
   batch_size = 10
   n_features = 5
   in_tensor_1 = np.random.rand(batch_size, n_features)
   in_tensor_2 = np.random.rand(batch_size, n_features)
   with self.session() as sess:
     in_tensor_1 = tf.convert_to_tensor(in_tensor_1, dtype=tf.float32)
     in_tensor_2 = tf.convert_to_tensor(in_tensor_2, dtype=tf.float32)
     out_tensor = ReduceSquareDifference()(in_tensor_1, in_tensor_2)
     out_tensor = out_tensor.eval()
     assert isinstance(out_tensor, np.float32)