Skip to content

The repository provides code for running inference with the Meta Segment Anything Model 2 (SAM 2), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.

License

Apache-2.0, BSD-3-Clause licenses found

Licenses found

Apache-2.0
LICENSE
BSD-3-Clause
LICENSE_cctorch
Notifications You must be signed in to change notification settings

axinc-ai/segment-anything-2

 
 

SAM 2 Export to ONNX and TFLITE

Download model

cd checkpoints && \
./download_ckpts.sh && \
cd ..

Requirements

onnx

torch 2.2.1
onnx 1.16.2

tflite

torch 2.4.0
ai-edge-torch 0.2.0
tf-nightly 2.18.0.dev20240905

Export and Inference

onnx

python3 export_image_predictor.py --framework onnx
python3 export_video_predictor.py --framework onnx

tflite

export PJRT_DEVICE=CPU
python3 export_image_predictor.py --framework tflite
python3 export_video_predictor.py --framework tflite

Inference only

onnx

python3 export_image_predictor.py --framework onnx --mode import
python3 export_video_predictor.py --framework onnx --mode import

tflite not supported inference only yet.

Test

Replacing the complex tensor of RotaryEnc with matmul. To test this behavior, you can also run it with torch.

python3 export_video_predictor.py --framework torch

Artifacts

The deliverables will be stored below.

output/*
model/*

You can also download it from the following.

ONNX

TFLITE

The memory attention in tflite does not support dynamic shapes, so num_maskmem and max_obj_ptrs_in_encoder need to be fixed to 1.

Inference Example

Original document

About

The repository provides code for running inference with the Meta Segment Anything Model 2 (SAM 2), links for downloading the trained model checkpoints, and example notebooks that show how to use the model.

Resources

License

Apache-2.0, BSD-3-Clause licenses found

Licenses found

Apache-2.0
LICENSE
BSD-3-Clause
LICENSE_cctorch

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 98.8%
  • Python 1.2%