EfficientSAM<T>
Models & Types · AiDotNet.ComputerVision.Segmentation.Efficient
EfficientSAM: Leveraged Masked Image Pretraining for efficient SAM.
Inheritance: NeuralNetworkBase<T> → SegmentationModelBase<T> → PromptableSegmentationBase<T> → EfficientSAM<T>
For Beginners
Efficient segment anything with strong pre-training. Interactive segmentation.
Common use cases:
- Efficient segment anything with strong pre-training
- Interactive segmentation
- Automatic mask generation
- Production SAM deployment
How It Works
Technical Details:
- SAMI (SAM Image) pre-training with masked autoencoder
- Lightweight ViT encoder with MAE knowledge transfer
- Cross-attention decoder for mask prediction
- Better quality-efficiency trade-off than MobileSAM
Reference: Xiong et al., “EfficientSAM: Leveraged Masked Image Pretraining for Efficient Segment Anything”, CVPR 2024.
Example
// Create an EfficientSAM model for efficient promptable segmentation
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.ThreeDimensional,
taskType: NeuralNetworkTaskType.ImageSegmentation,
inputHeight: 1024, inputWidth: 1024, inputDepth: 3, outputSize: 1);
var model = new EfficientSAM<double>(architecture);
// Every tunable is now set through the options object; these are the defaults:
var custom = new EfficientSAM<double>(architecture,
options: new EfficientSAMOptions { NumClasses = 1, DropRate = 0 });
Constructors
| Constructor | Summary |
|---|---|
EfficientSAM(NeuralNetworkArchitecture<T> architecture, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, EfficientSAMOptions options) |
Initializes EfficientSAM in native (trainable) mode. |
EfficientSAM(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, EfficientSAMOptions options) |
Initializes EfficientSAM in ONNX (inference-only) mode. |
Methods
| Method | Summary |
|---|---|
List<PromptedSegmentationResult<T>> SegmentEverything() |
|
ModelMetadata<T> GetModelMetadata() |
Collects metadata describing this model’s configuration. |
PromptedSegmentationResult<T> SegmentFromBox(Tensor<T> box) |
|
PromptedSegmentationResult<T> SegmentFromMask(Tensor<T> mask) |
|
PromptedSegmentationResult<T> SegmentFromPoints(Tensor<T> points, Tensor<T> labels) |
|
Tensor<T> ForwardForTraining(Tensor<T> input) |
Uses the same encoder/decoder graph for autodiff training as inference. |
void SetImage(Tensor<T> image) |