FastSAM<T>
Models & Types · AiDotNet.ComputerVision.Segmentation.Efficient
FastSAM: Fast Segment Anything Model based on YOLOv8-Seg.
Inheritance: NeuralNetworkBase<T> → SegmentationModelBase<T> → PromptableSegmentationBase<T> → FastSAM<T>
For Beginners
Real-time segment anything. Interactive segmentation on edge devices.
Common use cases:
- Real-time segment anything
- Interactive segmentation on edge devices
- Fast automatic mask generation
- Lightweight alternative to SAM
How It Works
Technical Details:
- YOLOv8-Seg backbone trained on SA-1B dataset
- 50x faster than original SAM
- CNN-based architecture (no vision transformer)
- Supports point and box prompts
Reference: Zhao et al., “Fast Segment Anything”, arXiv 2023.
Example
// Create a FastSAM model for real-time segment anything via YOLOv8
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.ThreeDimensional,
taskType: NeuralNetworkTaskType.ImageSegmentation,
inputHeight: 1024, inputWidth: 1024, inputDepth: 3, outputSize: 1);
var model = new FastSAM<double>(architecture);
// Every tunable is now set through the options object; these are the defaults:
var custom = new FastSAM<double>(architecture,
options: new FastSAMOptions { NumClasses = 1, DropRate = 0 });
Constructors
| Constructor | Summary |
|---|---|
FastSAM(NeuralNetworkArchitecture<T> architecture, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction, FastSAMOptions options) |
Initializes FastSAM in native (trainable) mode. |
FastSAM(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, FastSAMOptions options) |
Initializes FastSAM 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 native encoder/decoder graph for tape-based training. |
void SetImage(Tensor<T> image) |