tfg.geometry.representation.grid.generate

Generates a M-D uniform axis-aligned grid.

tfg.geometry.representation.grid.generate(
    starts,
    stops,
    nums,
    name=None
)

Defined in geometry/representation/grid.py.

Warning:

This op is not differentiable. Indeed, the gradient of tf.linspace and tf.meshgrid are currently not defined.

Note:

In the following, B is an optional batch dimension.

Args:

  • starts: A tensor of shape [M] or [B, M], where the last dimension represents a M-D start point.
  • stops: A tensor of shape [M] or [B, M], where the last dimension represents a M-D end point.
  • nums: A tensor of shape [M] representing the number of subdivisions for each dimension.
  • name: A name for this op. Defaults to "grid_generate".

Returns:

A tensor of shape [nums[0], ..., nums[M-1], M] containing an M-D uniform grid or a tensor of shape [B, nums[0], ..., nums[M-1], M]` containing B M-D uniform grids. Please refer to the example below for more details.

Raises:

  • ValueError: If the shape of starts, stops, or 'nums' is not supported.

Examples:

generate((-1.0, -2.0), (1.0, 2.0), (3, 5))
>>> [[[-1. -2.]
      [-1. -1.]
      [-1.  0.]
      [-1.  1.]
      [-1.  2.]]
     [[ 0. -2.]
      [ 0. -1.]
      [ 0.  0.]
      [ 0.  1.]
      [ 0.  2.]]
     [[ 1. -2.]
      [ 1. -1.]
      [ 1.  0.]
      [ 1.  1.]
      [ 1.  2.]]]

Generates a 3x5 2d grid from -1.0 to 1.0 with 3 subdivisions for the x axis and from -2.0 to 2.0 with 5 subdivisions for the y axis. This lead to a tensor of shape (3, 5, 2).