sleap.nn.data.offset_regression

sleap.nn.data.offset_regression#

Utilities for creating offset regression maps.

sleap.nn.data.offset_regression.make_offsets(points: Tensor, xv: Tensor, yv: Tensor, stride: int = 1) Tensor[source]#

Make point offset maps on a grid.

Parameters:
  • points – Point locations as a tf.Tensor of shape (n_points, 2) and dtype tf.float32 where each row specifies the x- and y-coordinates of the map centers. Each point will generate a different map.

  • xv – Sampling grid vector for x-coordinates of shape (grid_width,) and dtype tf.float32. This can be generated by sleap.nn.data.utils.make_grid_vectors.

  • yv – Sampling grid vector for y-coordinates of shape (grid_height,) and dtype tf.float32. This can be generated by sleap.nn.data.utils.make_grid_vectors.

  • stride – Scaling factor for offset coordinates. The individual offset vectors will be divided by this value. Useful for adjusting for strided sampling grids so that the offsets point to the smaller grid coordinates.

Returns:

The offset maps as a tf.Tensor of shape (grid_height, grid_width, n_points, 2) and dtype tf.float32. The last axis corresponds to the x- and y-offsets at each grid point for each input point.

See also

sleap.nn.data.utils.make_grid_vectors

sleap.nn.data.offset_regression.mask_offsets(offsets: Tensor, confmaps: Tensor, threshold: float = 0.2) Tensor[source]#

Mask offset maps using a confidence map threshold.

This is useful for restricting offset maps to local neighborhoods around the peaks.

Parameters:
  • offsets – A set of offset maps as a tf.Tensor of shape (grid_height, grid_width, n_points, 2) and dtype tf.float32. This can be generated by make_offsets.

  • confmaps – Confidence maps for the same points as the offset maps as a tf.Tensor of shape (grid_height, grid_width, n_points) and dtype tf.float32. This can be generated by sleap.nn.data.confidence_maps.make_confmaps.

  • threshold – Minimum confidence map value below which offsets will be replaced with zeros.

Returns:

The offset maps with the same shape as the inputs but with zeros where the confidence maps are below the specified threshold.

See also: make_offsets, sleap.nn.data.confidence_maps.make_confmaps