Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackd committed Feb 5, 2019
1 parent 2383f64 commit df56746
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions tensorflow_datasets/video/moving_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def image_as_moving_sequence(
import tensorflow as tf
import tensorflow_datasets as tfds
from tensorflow_datasets.video import moving_sequence
tf.compat.v1.enable_eager_execution()
def animate(sequence):
import numpy as np
Expand Down Expand Up @@ -199,9 +200,10 @@ def map_fn(image, label):
total_padding = output_size - image_shape[:2]

# cond = tf.assert_greater(total_padding, -1)
# if not tf.executing_eagerly():
# with tf.control_dependencies([cond]):
# total_padding = tf.identity(total_padding)
cond = tf.compat.v1.assert_greater(total_padding, -1)
if not tf.executing_eagerly():
with tf.control_dependencies([cond]):
total_padding = tf.identity(total_padding)

sequence_pad_lefts = tf.cast(
tf.math.round(trajectory * tf.cast(total_padding, tf.float32)), tf.int32)
Expand Down
9 changes: 6 additions & 3 deletions tensorflow_datasets/video/moving_sequence_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tensorflow as tf
from tensorflow_datasets.core import test_utils
import tensorflow_datasets.video.moving_sequence as ms
tf.compat.v1.enable_eager_execution()


class MovingSequenceTest(tf.test.TestCase):
Expand All @@ -29,15 +30,17 @@ def test_images_as_moving_sequence(self):
sequence = tf.cast(sequence.image_sequence, tf.float32)

self.assertAllEqual(
tf.reduce_sum(sequence, axis=(1, 2, 3)),
tf.fill((sequence_length,), tf.reduce_sum(tf.cast(image, tf.float32))))
self.evaluate(tf.reduce_sum(sequence, axis=(1, 2, 3))),
self.evaluate(
tf.fill(
(sequence_length,), tf.reduce_sum(tf.cast(image, tf.float32)))))

for i, full_image in enumerate(tf.unstack(sequence, axis=0)):
j = i // 2
subimage = full_image[i:i+h, j:j+w]
n_true = tf.reduce_sum(subimage)
# allow for pixel rounding errors in each dimension
self.assertAllEqual(n_true >= (h-1)*(w-1), True)
self.assertTrue(self.evaluate(n_true) >= (h-1)*(w-1))


if __name__ == '__main__':
Expand Down

0 comments on commit df56746

Please sign in to comment.