class_docstr: Shapes moving in a stochastic way.
class_docstr_tok: ["Shapes","moving","in","a","stochastic","way","."]
docstr: Yields one video of a shape moving to a random direction.
  
     The size and color of the shapes are random but
     consistent in a single video. The speed is fixed.
  
  Raises:
     ValueError: The frame size is not square.
docstr_tok: ["Yields","one","video","of","a","shape","moving","to","a","random","direction",".","The","size","and","color","of","the","shapes","are","random","but","consistent","in","a","single","video",".","The","speed","is","fixed",".","Raises",":","ValueError",":","The","frame","size","is","not","square","."]
code: def generate_stochastic_shape_instance(self):
      """Yields one video of a shape moving to a random direction.
  
         The size and color of the shapes are random but
         consistent in a single video. The speed is fixed.
  
      Raises:
         ValueError: The frame size is not square.
      """
      if (
          self.frame_height != self.frame_width
          or self.frame_height % 2 != 0
      ):
          raise ValueError(
              "Generator only supports square frames with even size."
          )
  
      lim = 10.0
      direction = np.array(
          [
              [+1.0, +1.0],
              [+1.0, +0.0],
              [+1.0, -1.0],
              [+0.0, +1.0],
              [+0.0, -1.0],
              [-1.0, +1.0],
              [-1.0, +0.0],
              [-1.0, -1.0],
          ]
      )
  
      sp = np.array([lim / 2.0, lim / 2.0])
      rnd = np.random.randint(len(direction))
      di = direction[rnd]
  
      colors = ["b", "g", "r", "c", "m", "y"]
      color = np.random.choice(colors)
  
      shape = np.random.choice(
          [
              VideoStochasticShapes10k.get_circle,
              VideoStochasticShapes10k.get_rectangle,
              VideoStochasticShapes10k.get_triangle,
          ]
      )
      speed = 1.0
  
      size = np.random.uniform(0.5, 1.5)
  
      back_color = str(0.0)
      plt.ioff()
  
      xy = np.array(sp)
  
      for _ in range(self.video_length):
          fig = plt.figure()
          fig.set_dpi(self.frame_height // 2)
          fig.set_size_inches(2, 2)
          ax = plt.axes(xlim=(0, lim), ylim=(0, lim))
  
          # Background
          ax.add_patch(
              VideoStochasticShapes10k.get_rectangle(
                  0.0, 0.0, -1.0, back_color, 25.0
              )
          )
          # Foreground
          ax.add_patch(shape(xy[0], xy[1], 0.0, color, size))
  
          plt.axis("off")
          plt.tight_layout(pad=-2.0)
          fig.canvas.draw()
          image = np.fromstring(
              fig.canvas.tostring_rgb(), dtype=np.uint8, sep=""
          )
          image = image.reshape(
              fig.canvas.get_width_height()[::-1] + (3,)
          )
          image = np.copy(np.uint8(image))
  
          plt.close()
          xy += speed * di
  
          yield image
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import numpy
  from tensor2tensor.data_generators import video_utils
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import registry
  import tensorflow.compat.v1
label_desc: Use image node_id 15 for calling the VideoStochasticShapes10k obj's underlying member method code with example usage: obj.generate_stochastic_shape_instance() without return types