MobileSAM (ONNX)
This is an unofficial ONNX export of MobileSAM by Chaoning Zhang et al., for Unity Inference Engine. The tools.doji.mobilesam package runs it. The weights are the original float32 weights. The terms of the original Apache License 2.0 apply.
Files
onnx/mobilesam.encoder.onnx(0.026 GiB): the image encoder. Inputinput_imageis a float image of shape [height, width, 3]. The graph normalizes the pixels and moves the channels first. Outputimage_embeddingshas shape [1, 256, 64, 64].onnx/mobilesam.decoder.onnx(0.015 GiB): the prompt encoder and mask decoder. Inputs:image_embeddings,point_coords,point_labels,mask_input,has_mask_input,orig_im_size. Outputs:masks,iou_predictions,low_res_masks.
How the files were made
- The encoder was exported with PyTorch 2.4.0, ONNX opset 17.
- The decoder was exported with PyTorch 2.0.1, ONNX opset 16, with the inputs and outputs of
scripts/export_onnx_model.pyof MobileSAM. - All weights are float32. Both files use standard ONNX operators only.
Usage
Add julienkay/sentis-MobileSAM to the project in Window > AI Model Hub, then:
using Doji.AI.Segmentation;
using UnityEngine;
public class Segment : MonoBehaviour {
public Texture Image;
private MobileSAM _predictor;
private async void Start() {
_predictor = await MobileSAM.CreateAsync();
_predictor.SetImage(Image);
// One foreground point at pixel (200, 150).
_predictor.Predict(new float[] { 200, 150 }, new float[] { 1 });
RenderTexture mask = _predictor.Result;
}
private void OnDestroy() {
_predictor?.Dispose();
}
}
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐ Ask for provider support