ryouchinsa / sam-cpp-macos

Segment Anything Model 2 CPP Wrapper for macOS and Ubuntu CPU/GPU
MIT License
76 stars 5 forks source link

SAM2.1 #7

Closed sctrueew closed 4 days ago

sctrueew commented 1 week ago

Hi, thanks for your work. Is it possible to support SAM2.1?

ryouchinsa commented 5 days ago

Thanks for writing the issue.

Yes, we are supporting the SAM 2.1 models.

Install Segment Anything Model 2 and download checkpoints.

checkpoints

Copy yaml files in sam2/configs/sam2.1 to sam2.

configs

Put export_onnx.py and david-tomaseti-Vw2HZQ1FGjU-unsplash.jpg to the root folder.

export

To export an ONNX model.

python export_onnx.py --mode export

To check how the ONNX model works.

python export_onnx.py --mode import

You can download exported SAM 2.1 ONNX models.

sctrueew commented 5 days ago

Hi, thanks for the reply. SAM2 Tiny, Is it for SAM2.1 or SAM2?

ryouchinsa commented 5 days ago

Those models are exported from SAM 2.1 checkpoints. You can export SAM 2.1 ONNX models by yourself using export_onnx.py.

model_idx = 0
model_type = ["tiny","small","base_plus","large"][model_idx]
config_type = ["t","s","b+","l"][model_idx]
version_idx = 1
version_type = ["2","2.1"][version_idx]
onnx_output_path = "checkpoints/{}/".format(model_type)
model_config_file = "sam{}_hiera_{}.yaml".format(version_type, config_type)
model_checkpoints_file = "checkpoints/sam{}_hiera_{}.pt".format(version_type, model_type)
sctrueew commented 5 days ago

That sounds great. I will take a look at it.

ryouchinsa commented 4 days ago

To be clear that we are supporting SAM 2.1, we updated our document.

sctrueew commented 4 days ago

Thank you for informing me.