UniverSeg<T>
Models & Types · AiDotNet.ComputerVision.Segmentation.Medical
UniverSeg: Universal Medical Image Segmentation via cross-attention.
Inheritance: NeuralNetworkBase<T> → SegmentationModelBase<T> → MedicalSegmentationBase<T> → UniverSeg<T>
For Beginners
Few-shot medical segmentation without fine-tuning. Cross-domain medical image segmentation.
Common use cases:
- Few-shot medical segmentation without fine-tuning
- Cross-domain medical image segmentation
- Label-efficient medical AI
- New task adaptation from a few examples
How It Works
Technical Details:
- CrossBlock: each (query, support example) pair is convolved jointly and the query stream takes the
interaction averaged over the support set
- A U-Net of CrossBlocks (64 features at four encoder and three decoder levels, LeakyReLU)
- No fine-tuning needed for new segmentation tasks; set the support set with SetSupportSet
- Trained on diverse medical segmentation datasets
Reference: Butoi et al., “UniverSeg: Universal Medical Image Segmentation”, ICCV 2023.
Example
// Create a UniverSeg model for few-shot medical segmentation
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.ThreeDimensional,
taskType: NeuralNetworkTaskType.BinaryClassification,
inputHeight: 128, inputWidth: 128, inputDepth: 1, outputSize: 1);
var model = new UniverSeg<double>(architecture);
// Every tunable is now set through the options object; these are the defaults:
var custom = new UniverSeg<double>(architecture,
options: new UniverSegOptions { NumClasses = 1, DropRate = 0 });
// Or load a pre-trained ONNX model for cross-domain medical segmentation
var onnxModel = new UniverSeg<double>(architecture, "universeg.onnx");
Constructors
| Constructor | Summary |
|---|---|
UniverSeg(NeuralNetworkArchitecture<T> architecture, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, UniverSegOptions options) |
Initializes UniverSeg in native (trainable) mode. |
UniverSeg(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, UniverSegOptions options) |
Initializes UniverSeg in ONNX (inference-only) mode. |
Properties
| Property | Summary |
|---|---|
bool Supports3D { get; } |
UniverSeg operates on 2D slices only. |
bool SupportsFewShot { get; } |
UniverSeg is a few-shot model: its whole point is segmenting from a support set. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
MedicalSegmentationResult<T> SegmentSlice(Tensor<T> slice) |
Segments a single 2D medical slice against the current support set. |
MedicalSegmentationResult<T> SegmentVolume(Tensor<T> volume) |
Segments a volume by treating it as a single slice (UniverSeg is a 2D model). |
ModelMetadata<T> GetModelMetadata() |
Collects metadata describing this model’s configuration. |
Tensor<T> ForwardForTraining(Tensor<T> input) |
The training forward is the CrossBlock network. |
void ClearSupportSet() |
Removes the support set; predictions then throw until a new one is set. |
void SetSupportSet(Tensor<T> images, Tensor<T> labels) |
Sets the support set every prediction is conditioned on. |