(batch, height, width, is_homogeneous=True)
return coords
Construct a 2D meshgrid.

    Args:
      batch: batch size
      height: height of the grid
      width: width of the grid
      is_homogeneous: whether to return in homogeneous coordinates
    Returns:
      x,y grid coordinates [batch, 2 (3 if homogeneous), height, width]
Construct a 2D meshgrid.
Construct a 2D meshgrid .
def meshgrid(batch, height, width, is_homogeneous=True):
    """Construct a 2D meshgrid.

    Args:
      batch: batch size
      height: height of the grid
      width: width of the grid
      is_homogeneous: whether to return in homogeneous coordinates
    Returns:
      x,y grid coordinates [batch, 2 (3 if homogeneous), height, width]
    """
    x_t = tf.matmul(tf.ones(shape=tf.stack([height, 1])),
                    tf.transpose(tf.expand_dims(
                        tf.linspace(-1.0, 1.0, width), 1), [1, 0]))
    y_t = tf.matmul(tf.expand_dims(tf.linspace(-1.0, 1.0, height), 1),
                    tf.ones(shape=tf.stack([1, width])))
    x_t = (x_t + 1.0) * 0.5 * tf.cast(width - 1, tf.float32)
    y_t = (y_t + 1.0) * 0.5 * tf.cast(height - 1, tf.float32)
    if is_homogeneous:
        ones = tf.ones_like(x_t)
        coords = tf.stack([x_t, y_t, ones], axis=0)
    else:
        coords = tf.stack([x_t, y_t], axis=0)
    coords = tf.tile(tf.expand_dims(coords, 0), [batch, 1, 1, 1])
    return coords
def meshgrid ( batch , height , width , is_homogeneous = True ) : x_t = tf . matmul ( tf . ones ( shape = tf . stack ( [ height , 1 ] ) ) , tf . transpose ( tf . expand_dims ( tf . linspace ( - 1.0 , 1.0 , width ) , 1 ) , [ 1 , 0 ] ) ) y_t = tf . matmul ( tf . expand_dims ( tf . linspace ( - 1.0 , 1.0 , height ) , 1 ) , tf . ones ( shape = tf . stack ( [ 1 , width ] ) ) ) x_t = ( x_t + 1.0 ) * 0.5 * tf . cast ( width - 1 , tf . float32 ) y_t = ( y_t + 1.0 ) * 0.5 * tf . cast ( height - 1 , tf . float32 ) if is_homogeneous : ones = tf . ones_like ( x_t ) coords = tf . stack ( [ x_t , y_t , ones ] , axis = 0 ) else : coords = tf . stack ( [ x_t , y_t ] , axis = 0 ) coords = tf . tile ( tf . expand_dims ( coords , 0 ) , [ batch , 1 , 1 , 1 ] ) return coords