SwinUNETR<T>

Models & Types · AiDotNet.ComputerVision.Segmentation.Medical

Swin UNETR: Swin Transformer encoder for 3D medical segmentation.

Inheritance: NeuralNetworkBase<T> → SegmentationModelBase<T> → MedicalSegmentationBase<T> → SwinUNETR<T>

For Beginners

3D medical volume segmentation. Brain tumor segmentation from MRI.

Common use cases:

  • 3D medical volume segmentation
  • Brain tumor segmentation from MRI
  • CT organ segmentation
  • Self-supervised pre-trained medical segmentation

How It Works

Technical Details:

  • Swin Transformer encoder with shifted window attention
  • U-Net style decoder with skip connections from encoder stages
  • Designed for 3D volumetric medical data
  • Self-supervised pre-training on large medical datasets

Reference: Hatamizadeh et al., “Swin UNETR: Swin Transformers for Semantic Segmentation of Brain Tumors in MRI Images”, BrainLes 2022.

Example

// Create a SwinUNETR model for 3D brain tumor segmentation
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.ThreeDimensional,
    taskType: NeuralNetworkTaskType.MultiClassClassification,
    inputHeight: 256, inputWidth: 256, inputDepth: 1, outputSize: 14);
var model = new SwinUNETR<double>(architecture);
// Every tunable is now set through the options object; these are the defaults:
var custom = new SwinUNETR<double>(architecture,
    options: new SwinUNETROptions { NumClasses = 14, DropRate = 0.1, ModelSize = SwinUNETRModelSize.Tiny });
            
// Or load a pre-trained ONNX model for brain MRI segmentation
var onnxModel = new SwinUNETR<double>(architecture, "swinunetr.onnx");

Constructors

Constructor Summary
SwinUNETR(NeuralNetworkArchitecture<T> architecture, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, SwinUNETROptions options) Initializes SwinUNETR in native (trainable) mode.
SwinUNETR(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, SwinUNETROptions options) Initializes SwinUNETR in ONNX (inference-only) mode.

Methods

Method Summary
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
MedicalSegmentationResult<T> SegmentFewShot(Tensor<T> queryImage, Tensor<T> supportImages, Tensor<T> supportMasks)
MedicalSegmentationResult<T> SegmentSlice(Tensor<T> slice) Segments a single 2D medical slice.
MedicalSegmentationResult<T> SegmentVolume(Tensor<T> volume) Segments a 3D volume slice-by-slice and aggregates the per-structure statistics.
ModelMetadata<T> GetModelMetadata() Collects metadata describing this model’s configuration.