예제 #1
0
 def test_dense_2d_3d_squeezable(self):
   x = tf.constant([[1, 2], [3, 4]])
   y = tf.constant([[[1], [2]], [[3], [4]]])
   _, y_p = losses_utils.remove_squeezable_dimensions(x, y)
   y_p.shape.assert_is_compatible_with(x.shape)
   self.assertEqual(y_p.shape.ndims, x.shape.ndims)
   x_p, _ = losses_utils.remove_squeezable_dimensions(y, x)
   x_p.shape.assert_is_compatible_with(x.shape)
예제 #2
0
 def test_placeholder(self):
   """Test dynamic rank tensors."""
   with tf.Graph().as_default():
     x = tf.compat.v1.placeholder_with_default([1., 2., 3.], shape=None)
     y = tf.compat.v1.placeholder_with_default([[1.], [2.], [3.]], shape=None)
     _, y_p = losses_utils.remove_squeezable_dimensions(x, y)
     y_p.shape.assert_is_compatible_with(x.shape)
     self.assertAllEqual(tf.shape(x), tf.shape(y_p))
     x_p, _ = losses_utils.remove_squeezable_dimensions(y, x)
     x_p.shape.assert_is_compatible_with(x.shape)
예제 #3
0
  def test_ragged_3d_4d_squeezable(self):
    """ shapes:

        x: (2, (sequence={1, 2}), 3)
        y: (2, (sequence={1, 2}), 3, 1)
    """
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    y = tf.expand_dims(x, axis=-1)
    self.assertEqual(x.shape.ndims, 3)
    self.assertEqual(y.shape.ndims, 4)
    _, y_p = losses_utils.remove_squeezable_dimensions(x, y)
    y_p.shape.assert_is_compatible_with(x.shape)
    self.assertEqual(y_p.shape.ndims, 3)

    x_p, _ = losses_utils.remove_squeezable_dimensions(y, x)
    x_p.shape.assert_is_compatible_with(x.shape)
    self.assertEqual(x_p.shape.ndims, 3)
예제 #4
0
 def test_ragged_3d_same_shape(self):
   """ shape (2, (sequence={1, 2}), 3)"""
   x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
   rank = x.shape.ndims
   x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
   self.assertEqual(x_p.shape.ndims, rank)