EdgeSAM<T>
Models & Types · AiDotNet.ComputerVision.Segmentation.Efficient
EdgeSAM: Prompt-in-the-Loop Distillation for SAM on edge devices.
Inheritance: NeuralNetworkBase<T> → SegmentationModelBase<T> → PromptableSegmentationBase<T> → EdgeSAM<T>
For Beginners
Edge-device segment anything. On-device interactive segmentation.
Common use cases:
- Edge-device segment anything
- On-device interactive segmentation
- Mobile and IoT segmentation
- Real-time promptable segmentation
How It Works
Technical Details:
- RepViT encoder for edge-optimized inference
- Prompt-in-the-loop distillation from SAM ViT-H
- End-to-end encoder + decoder distillation
- Runs on iPhone 14 at interactive speeds
Reference: Zhou et al., “EdgeSAM: Prompt-In-the-Loop Distillation for On-Device Deployment of SAM”, arXiv 2024.
Example
// Create an EdgeSAM model for edge-device interactive segmentation
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.ThreeDimensional,
taskType: NeuralNetworkTaskType.ImageSegmentation,
inputHeight: 1024, inputWidth: 1024, inputDepth: 3, outputSize: 1);
var model = new EdgeSAM<double>(architecture);
// Every tunable is now set through the options object; these are the defaults:
var custom = new EdgeSAM<double>(architecture,
options: new EdgeSAMOptions { NumClasses = 1, DropRate = 0 });
// Or load a pre-trained ONNX model for mobile deployment
var onnxModel = new EdgeSAM<double>(architecture, "edgesam_model.onnx");
Constructors
| Constructor | Summary |
|---|---|
EdgeSAM(NeuralNetworkArchitecture<T> architecture, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, EdgeSAMOptions options) |
Initializes EdgeSAM in native (trainable) mode. |
EdgeSAM(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, EdgeSAMOptions options) |
Initializes EdgeSAM 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) |
|
void SetImage(Tensor<T> image) |