OpenVocabSAM<T>

Models & Types · AiDotNet.ComputerVision.Segmentation.OpenVocabulary

Open-Vocabulary SAM: SAM with text-based open-vocabulary recognition.

Inheritance: NeuralNetworkBase<T> → SegmentationModelBase<T> → OpenVocabSegmentationBase<T> → OpenVocabSAM<T>

For Beginners

Text-prompted SAM segmentation. Open-vocabulary interactive segmentation.

Common use cases:

  • Text-prompted SAM segmentation
  • Open-vocabulary interactive segmentation
  • Large-vocabulary object segmentation
  • Combining SAM masks with CLIP recognition

How It Works

Technical Details:

  • SAM encoder-decoder with CLIP text alignment
  • Supports 20,000+ categories via open vocabulary
  • Interactive segmentation with automatic class labels
  • Region-level CLIP feature extraction for classification

Reference: Yuan et al., “Open-Vocabulary SAM: Segment and Recognize Twenty-thousand Classes Interactively”, ECCV 2024.

Example

// Create an OpenVocabSAM model for text-prompted interactive segmentation
// Any CLIP-style ITextEncoder supplies the text embeddings, e.g. a CLIP model from VisionLanguage.Encoders.
ITextEncoder<double> textEncoder = clipModel;
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.ThreeDimensional,
    taskType: NeuralNetworkTaskType.BinaryClassification,
    inputHeight: 1024, inputWidth: 1024, inputDepth: 3, outputSize: 1);
var model = new OpenVocabSAM<double>(architecture, textEncoder);
// Every tunable is now set through the options object; these are the defaults:
var custom = new OpenVocabSAM<double>(architecture, textEncoder,
    options: new OpenVocabSAMOptions { NumClasses = 1, DropRate = 0 });
            
// Or load a pre-trained ONNX model for 20,000+ category segmentation
var onnxModel = new OpenVocabSAM<double>(architecture, "openvocabsam.onnx", textEncoder, options: null);

Constructors

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

Methods

Method Summary
ModelMetadata<T> GetModelMetadata() Collects metadata describing this model’s configuration.