def testPadWithIdentityWithMaxTime(self): tensor = [ [[1], [-1], [-1], [-1]], [[1], [2], [3], [-1]], [[1], [2], [-1], [-1]]] expected = [ [[1], [1], [1], [1], [0], [0]], [[1], [2], [3], [1], [1], [0]], [[1], [2], [0], [0], [0], [0]]] lengths = [1, 3, 2] max_lengths = [4, 5, 2] maxlen = 6 padded = reducer.pad_with_identity( tf.constant(tensor, dtype=tf.float32), tf.constant(lengths), tf.constant(max_lengths), identity_values=1, maxlen=maxlen) self.assertEqual(1, padded.get_shape().as_list()[-1]) with self.test_session() as sess: padded = sess.run(padded) self.assertAllEqual(expected, padded)
def testPadWithIdentityWithMaxTime(self): tensor = [ [[1], [-1], [-1], [-1]], [[1], [2], [3], [-1]], [[1], [2], [-1], [-1]], ] expected = [ [[1], [1], [1], [1], [0], [0]], [[1], [2], [3], [1], [1], [0]], [[1], [2], [0], [0], [0], [0]], ] lengths = [1, 3, 2] max_lengths = [4, 5, 2] maxlen = 6 padded = reducer.pad_with_identity( tf.constant(tensor, dtype=tf.float32), tf.constant(lengths), tf.constant(max_lengths), identity_values=1, maxlen=maxlen, ) self.assertEqual(1, padded.shape[-1]) self.assertAllEqual(expected, self.evaluate(padded))
def testPadWithIdentity(self): tensor = [[[1], [-1], [-1]], [[1], [2], [3]], [[1], [2], [-1]]] expected = [[[1], [1], [1], [1], [0]], [[1], [2], [3], [1], [1]], [[1], [2], [0], [0], [0]]] lengths = [1, 3, 2] max_lengths = [4, 5, 2] padded = reducer.pad_with_identity(tf.constant(tensor, dtype=tf.float32), tf.constant(lengths), tf.constant(max_lengths), identity_values=1) self.assertEqual(1, padded.get_shape().as_list()[-1]) self.assertAllEqual(expected, self.evaluate(padded))