MedicalSAM2Options
Options & Configuration · AiDotNet.ComputerVision.Segmentation.Medical
Configuration options for MedicalSAM2, Medical SAM 2 (Zhu et al. 2024): SAM 2 with a self-sorting memory
bank for sets of medical images, and SAM 2’s tracking for volumes.
Inheritance: ModelOptions → NeuralNetworkOptions → ModelHyperparameterOptions → SegmentationModelOptions → MedicalSAM2Options
For Beginners
Leave these at their defaults; set ConfidenceThreshold only if you want low-quality
predictions kept out of the bank.
How It Works
The paper fixes the 256-pixel input, the bank’s update (keep the K most mutually dissimilar confident memories) and its
resampling (draws in proportion to similarity), AdamW with a linear warmup into cosine decay, and SAM 2’s prompt
simulation. Where it is silent the defaults follow SAM 2’s recipe (Ravi et al. 2024, Table 12b), which it builds on, and
the official code (the Hiera-S model, a 16-memory bank). The code’s own bank rule and resampling are available as
MemoryBankRule and MemoryResampling.
Constructors
| Constructor | Summary |
|---|---|
MedicalSAM2Options() |
Initializes a new instance with default values. |
MedicalSAM2Options(MedicalSAM2Options other) |
Initializes a new instance by copying from another instance. |
Properties
| Property | Summary |
|---|---|
MedicalSAM2ModelSize ModelSize { get; set; } |
The SAM 2 size (default: Small, as the official training scripts use). |
MemoryBankResampling MemoryResampling { get; set; } |
How the bank draws an image’s memories (default: the paper’s normalized similarity, eq. |
MemoryBankUpdateRule MemoryBankRule { get; set; } |
How the bank decides what to keep (default: the paper’s top-K total dissimilarity). |
double FocalAlpha { get; set; } |
Focal loss’s α (0.25, the RetinaNet value SAM uses). |
double FocalGamma { get; set; } |
Focal loss’s γ (2, the RetinaNet value SAM uses). |
double ImageEncoderLearningRate { get; set; } |
The image encoder’s learning rate (paper: 6e-5). |
double IouLossWeight { get; set; } |
The ℓ1 IoU-loss weight (paper: 1). |
double LearningRate { get; set; } |
The learning rate of everything but the image encoder (paper: 3e-4). |
double MaskDiceWeight { get; set; } |
The dice-loss weight (paper: 1). |
double MaskFocalWeight { get; set; } |
The focal-loss weight (paper: 20). |
double MaxGradientNorm { get; set; } |
The gradient-norm clip (paper: 0.1). |
double OcclusionLossWeight { get; set; } |
The occlusion cross-entropy weight (paper: 1). |
double WeightDecay { get; set; } |
AdamW’s decoupled weight decay (paper: 0.1). |
double? ConfidenceThreshold { get; set; } |
The predicted IoU a memory needs to be considered for the bank (the paper’s c_thresh, for which it gives no value; null considers every memory). |
double? DropPath { get; set; } |
The largest stochastic-depth rate of the Hiera blocks (null: the paper’s 0.1 for Tiny and Small, 0.2 for Base+, 0.3 for Large). |
double? LayerDecay { get; set; } |
The per-block layer-wise decay of the Hiera learning rates (null: the paper’s 0.8 for Tiny and Small, 0.9 for Base+, 0.925 for Large). |
int CorrectionPoints { get; set; } |
Corrective clicks per corrected training frame (paper: 7). |
int MemoryBankCapacity { get; set; } |
K, the memories the self-sorting bank keeps and draws per image (the official code’s 16; the paper gives no value). |
int MemoryBankSize { get; set; } |
The memory bank: the prompted frames and up to MemoryBankSize − 1 recent frames (default: 7). |
int TrainingSteps { get; set; } |
The training steps the cosine schedule spans (paper: about 150k). |
int WarmupSteps { get; set; } |
The linear warmup steps (paper: 7.5k). |
int? DecoderHeadCount { get; set; } |
The mask decoder’s attention heads (null: 8). |
int? HieraEmbeddingDimension { get; set; } |
The Hiera stem width (null: Tiny’s and Small’s 96); it doubles per stage. |
int? HieraInitialHeadCount { get; set; } |
The first stage’s attention heads (null: Tiny’s and Small’s 1); they double per stage. |
int? ImageSize { get; set; } |
The square size images are resized to for the image encoder (null: the paper’s 256). |
int? MaskDecoderMlpDimension { get; set; } |
The mask decoder’s MLP width (null: 2048). |
int? MemoryAttentionFeedForwardDimension { get; set; } |
The memory attention’s feed-forward width (null: 2048). |
int? MemoryAttentionLayerCount { get; set; } |
The memory attention layers (null: 4). |
int? MemoryDimension { get; set; } |
The memory width (null: 64). |
int? MemoryFuserDimension { get; set; } |
The memory fuser’s hidden width (null: 1024). |
int? ModelDimension { get; set; } |
The FPN, prompt and mask-decoder width (null: 256). |
int[] HieraGlobalAttentionBlockIndexes { get; set; } |
The blocks (0-based over all stages) with global attention (null: the size’s). |
int[] HieraStageDepths { get; set; } |
The Hiera blocks per stage (four values; null: the size’s). |
int[] HieraWindowSizes { get; set; } |
The windowed-attention size per stage (four values; null: the size’s). |
Methods
| Method | Summary |
|---|---|
void Validate() |
Throws if a setting is out of range. |