sleap.nn.data.inference

Transformers for performing inference.

class sleap.nn.data.inference.GlobalPeakFinder(confmaps_key: str = 'predicted_instance_confidence_maps', confmaps_stride: int = 1, peak_threshold: float = 0.2, peaks_key: str = 'predicted_center_instance_points', peak_vals_key: str = 'predicted_center_instance_confidences', keep_confmaps: bool = True, device_name: Optional[str] = None, integral: bool = True, integral_patch_size: int = 5)[source]

Global peak finding transformer.

class sleap.nn.data.inference.KerasModelPredictor(keras_model: tensorflow.python.keras.engine.training.Model, model_input_keys='instance_image', model_output_keys='predicted_instance_confidence_maps', device_name: Optional[str] = None)[source]

Transformer for performing tf.keras model inference.

class sleap.nn.data.inference.LocalPeakFinder(confmaps_key: str = 'centroid_confidence_maps', confmaps_stride: int = 1, peak_threshold: float = 0.2, peaks_key: str = 'predicted_centroids', peak_vals_key: str = 'predicted_centroid_confidences', peak_sample_inds_key: str = 'predicted_centroid_sample_inds', peak_channel_inds_key: str = 'predicted_centroid_channel_inds', keep_confmaps: bool = True, device_name: Optional[str] = None, integral: bool = True)[source]

Local peak finding transformer.

class sleap.nn.data.inference.MockGlobalPeakFinder(all_peaks_in_key: str = 'instances', peaks_out_key: str = 'predicted_center_instance_points', peak_vals_key: str = 'predicted_center_instance_confidences', keep_confmaps: bool = True, confmaps_in_key: str = 'instance_confidence_maps', confmaps_out_key: str = 'predicted_instance_confidence_maps')[source]

Transformer that mimics GlobalPeakFinder but passes ground truth data.

class sleap.nn.data.inference.PredictedCenterInstanceNormalizer(centroid_key: str = 'centroid', centroid_confidence_key: str = 'centroid_confidence', peaks_key: str = 'predicted_center_instance_points', peak_confidences_key: str = 'predicted_center_instance_confidences', new_centroid_key: str = 'predicted_centroid', new_centroid_confidence_key: str = 'predicted_centroid_confidence', new_peaks_key: str = 'predicted_instance', new_peak_confidences_key: str = 'predicted_instance_confidences')[source]

Transformer for adjusting centered instance coordinates.

property input_keys

Return the keys that incoming elements are expected to have.

property output_keys

Return the keys that outgoing elements will have.

transform_dataset(input_ds: tensorflow.python.data.ops.dataset_ops.DatasetV2) → tensorflow.python.data.ops.dataset_ops.DatasetV2[source]

Create a dataset that contains instance cropped data.

sleap.nn.data.inference.find_global_peaks(img: tensorflow.python.framework.ops.Tensor, threshold: float = 0.1) → tensorflow.python.framework.ops.Tensor[source]

Find the global maximum for each sample and channel.

Parameters
  • img – Tensor of shape (samples, height, width, channels).

  • threshold – Scalar float specifying the minimum confidence value for peaks. Peaks with values below this threshold will be replaced with NaNs.

Returns

A tuple of (peak_points, peak_vals).

peak_points: float32 tensor of shape (samples, channels, 2), where the last axis indicates peak locations in xy order.

peak_vals: float32 tensor of shape (samples, channels) containing the values at the peak points.

sleap.nn.data.inference.find_global_peaks_integral(cms: tensorflow.python.framework.ops.Tensor, crop_size: int = 5, threshold: float = 0.2) → Tuple[tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor][source]

Find local peaks with integral refinement.

Parameters
  • cms – Confidence maps.

  • threshold – Minimum confidence threshold.

Returns

A tuple of (peak_points, peak_vals).

peak_points: float32 tensor of shape (n_peaks, 2), where the last axis indicates peak locations in xy order.

peak_vals: float32 tensor of shape (n_peaks,) containing the values at the peak points.

sleap.nn.data.inference.find_local_peaks(img: tensorflow.python.framework.ops.Tensor, threshold: float = 0.2) → Tuple[tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor][source]

Find local maxima via non-maximum suppresion.

Parameters
  • img – Tensor of shape (samples, height, width, channels).

  • threshold – Scalar float specifying the minimum confidence value for peaks. Peaks with values below this threshold will not be returned.

Returns

A tuple of (peak_points, peak_vals, peak_sample_inds, peak_channel_inds).

peak_points: float32 tensor of shape (n_peaks, 2), where the last axis indicates peak locations in xy order.

peak_vals: float32 tensor of shape (n_peaks,) containing the values at the peak points.

peak_sample_inds: int32 tensor of shape (n_peaks,) containing the indices of the sample each peak belongs to.

peak_channel_inds: int32 tensor of shape (n_peaks,) containing the indices of the channel each peak belongs to.

sleap.nn.data.inference.find_local_peaks_integral(cms: tensorflow.python.framework.ops.Tensor, crop_size: int = 3, threshold: float = 0.2) → Tuple[tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor][source]

Find local peaks with integral refinement.

Parameters
  • cms – Confidence maps.

  • threshold – Minimum confidence threshold.

Returns

A tuple of (peak_points, peak_vals, peak_sample_inds, peak_channel_inds).

peak_points: float32 tensor of shape (n_peaks, 2), where the last axis indicates peak locations in xy order.

peak_vals: float32 tensor of shape (n_peaks,) containing the values at the peak points.

peak_sample_inds: int32 tensor of shape (n_peaks,) containing the indices of the sample each peak belongs to.

peak_channel_inds: int32 tensor of shape (n_peaks,) containing the indices of the channel each peak belongs to.

sleap.nn.data.inference.integral_regression(cms: tensorflow.python.framework.ops.Tensor, xv: tensorflow.python.framework.ops.Tensor, yv: tensorflow.python.framework.ops.Tensor) → Tuple[tensorflow.python.framework.ops.Tensor, tensorflow.python.framework.ops.Tensor][source]

Compute regression by integrating over the confidence maps on a grid.

Parameters
  • cms – Confidence maps.

  • xv – X grid vector.

  • yv – Y grid vector.

Returns

A tuple of (x_hat, y_hat) with the regressed x- and y-coordinates for each channel of the confidence maps.