SegmentationTensorOps

Helpers & Utilities · AiDotNet.ComputerVision.Segmentation.Common

Static helper methods for common segmentation tensor operations (argmax, softmax, etc.) used by models implementing segmentation interfaces.

Methods

Method Summary
Tensor<T> ArgmaxAlongClassDim(Tensor<T> logits) Computes argmax along the class dimension, producing a per-pixel class index map.
Tensor<T> BoxMask(int height, int width, int x1, int y1, int x2, int y2) Creates a spatial mask that is 1.0 inside the box [x1, y1, x2, y2) and 0.0 outside.
Tensor<T> EnsureUnbatched(Tensor<T> tensor) Removes the batch dimension from a tensor if present, keeping only batch index 0.
Tensor<T> EnsureUnbatchedClassMap(Tensor<T> classMap) Removes the leading batch dimension from a class-index map, returning [H, W].
Tensor<T> GaussianMask(int height, int width, double cx, double cy, double sigma) Generates a 2D Gaussian attention mask centered at (cx, cy) with given sigma.
Tensor<T> PixelAffinity(Tensor<T> features1, Tensor<T> features2) Computes per-pixel cosine similarity between two feature maps [C, H, W] or [B, C, H, W].
Tensor<T> Sigmoid(Tensor<T> input) Applies element-wise sigmoid to a tensor: 1 / (1 + exp(-x)).
Tensor<T> SoftmaxAlongClassDim(Tensor<T> logits)
Tensor<T> ThresholdMask(Tensor<T> values, double threshold) Thresholds a tensor to produce a binary {0, 1} mask.
Tensor<T> WarpMasksByAffinity(Tensor<T> refMasks, Tensor<T> affinity) Warps masks from a reference frame to a target frame using pixel-wise affinity scores.
Tensor<T> WeightedChannelSum(Tensor<T> features, double[] weights) Computes weighted sum across the channel dimension.
ValueTuple<Tensor<T>, int> LabelConnectedComponents(Tensor<T> classMap, int targetClass) Labels connected components of pixels matching a target class in the class map.
double[] TextToWeights(string text, int numChannels) Generates deterministic channel weights from text using character-level hashing.