title: Tensorflow unexpectedly caching sub-graph results
body: <p>I'm currently trying to make an augmentation class for TF like so:</p>
  
  <pre><code>    class Augmentations:
  
          def __init__(self, **kwargs):
              # Some Global Kwargs Define Here
              self.transforms = tf.eye(3)
  
              self.img_height = kwargs['img_height']
              self.img_width = kwargs['img_width']
  
          def _generate_random(self, shape, seed, minval, maxval):
              return tf.random_uniform(shape=shape,
                                       minval=minval,
                                       maxval=maxval,
                                       seed=seed,
                                       dtype=tf.float32)
  
          def rotate(self, seed, max_angle):
              random_rotation_value = self._generate_random([1], seed, 0., max_angle)
              rotation_matrix = tf.contrib.image.angles_to_projective_transforms(
                                  random_rotation_value,
                                  self.img_height,
                                  self.img_width)
  
              rotation_matrix = tf.reshape(tf.concat([rotation_matrix, [[1.]]], axis=1),
                                           [3, 3])
  
              self.transforms = tf.matmul(self.transforms, rotation_matrix)
              return self
  
  
          def apply(self, img):
              t = tf.reshape(tf.matmul(self.transforms[0],
                                       self.transforms[1]),
                             [1, 9])[0, :8]
              return tf.contrib.image.transform(img, t)
  </code></pre>
  
  <p>I've tried both the <code>dataset.map</code> and <code>tf.map_fn</code> with both returning a consistent transform, i.e.:</p>
  
  <pre><code>augment = Augment(**kwargs).rotate(None, 30).shear(None, 30)
  dataset = dataset.map(augment.apply, num_parallel_calls=10)
  </code></pre>
  
  <p>and </p>
  
  <pre><code>augment = Augment(**kwargs).rotate(None, 30).shear(None, 30)
  dataset = tf.map_fn(augment.apply)
  </code></pre>
  
  <p>Both of these calls return different images with the same transforms applied.</p>
  
  <p>The only way to return the images with random transforms is call the transform in the <code>map()</code>:</p>
  
  <pre><code>dataset = dataset.map(Augment(**kwargs).rotate(None, 30).shear(None, 30).apply, num_parallel_calls=10)
  </code></pre>
  
  <p>or move all of the random numbers into the <code>apply()</code>.</p>
  
  <p>Does the placement of <code>random_*()</code> calls matter in TF, I was under the idea that the placement would not matter, does it only matter for the <code>map_fn</code>?</p>