{"id":28389069,"url":"https://github.com/zz990099/sam2_cpp","last_synced_at":"2026-03-03T04:40:20.306Z","repository":{"id":291057388,"uuid":"973961688","full_name":"zz990099/sam2_cpp","owner":"zz990099","description":"SAM2 Track implementation with TensorRT \u0026 OnnxRuntime","archived":false,"fork":false,"pushed_at":"2025-05-23T09:06:41.000Z","size":4576,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T16:48:09.955Z","etag":null,"topics":["cpp","onnxruntime","sam","sam2","segment-anything-2","tensorrt","track"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zz990099.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-28T03:45:59.000Z","updated_at":"2025-05-22T09:07:09.000Z","dependencies_parsed_at":"2025-06-27T16:42:48.625Z","dependency_job_id":null,"html_url":"https://github.com/zz990099/sam2_cpp","commit_stats":null,"previous_names":["zz990099/sam2_cpp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zz990099/sam2_cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zz990099%2Fsam2_cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zz990099%2Fsam2_cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zz990099%2Fsam2_cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zz990099%2Fsam2_cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zz990099","download_url":"https://codeload.github.com/zz990099/sam2_cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zz990099%2Fsam2_cpp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267155340,"owners_count":24044382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","onnxruntime","sam","sam2","segment-anything-2","tensorrt","track"],"created_at":"2025-05-31T00:15:58.011Z","updated_at":"2025-10-17T15:03:14.862Z","avatar_url":"https://github.com/zz990099.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sam2_cpp\n\n## About This Project\n\n该项目是`SAM2`算法的c++实现，包括`TensorRT`、`OnnxRuntime`三种硬件平台(推理引擎)，使用[SAM2Export](https://github.com/Aimol-l/SAM2Export)导出onnx模型，并对`MemoryAttention`模块进行了优化。\n\n## Demo\n\n| \u003cimg src=\"./assets/persons.jpg\" alt=\"1\" width=\"300\"\u003e | \u003cimg src=\"./assets/sam2_result.png\" alt=\"1\" width=\"300\"\u003e | \u003cimg src=\"./assets/sam2_track.gif\" alt=\"1\" width=\"300\"\u003e |\n|:----------------------------------------:|:----:|:----:|\n| **image**  | **masks** | **track_result** |\n\n以下带有**opt**标志的代表在模型导出工程[SAM2Export](https://github.com/Aimol-l/SAM2Export)基础上，优化`MemoryAttention`模型结构后导出的onnx模型，具体请查看[pr_link](https://github.com/Aimol-l/SAM2Export/pull/10).\n\n|  jetson-orin-nx-16GB   |   qps   |  cpu   |\n|:---------:|:---------:|:----------------:|\n|  sam2_track(fp16) - origin   |   0.98   |  4%   |\n|  sam2_track(fp16) - **opt**  |   **4.25**   |  17%   |\n\n## Usage\n\n### Download Project\n\n下载git项目\n```bash\ngit clone git@github.com:zz990099/sam2_cpp.git\ncd sam2_cpp\ngit submodule init \u0026\u0026 git submodule update\n```\n\n### Build Enviroment\n\n使用docker构建工作环境\n```bash\ncd sam2_cpp\nbash easy_deploy_tool/docker/easy_deploy_startup.sh\n# Select `jetson` -\u003e `trt10_u2204`/`trt8_u2204`\nbash easy_deploy_tool/docker/into_docker.sh\n```\n\n### Compile Codes\n\n在docker容器内，编译工程. 使用 `-DENABLE_*`宏来启用某种推理框架，可用的有: `-DENABLE_TENSORRT=ON`、`-DENABLE_ORT=ON`，可以兼容。 \n```bash\ncd /workspace\nmdkir build \u0026\u0026 cd build\ncmake .. -DBUILD_TESTING=ON -DENABLE_TENSORRT=ON\nmake -j\n```\n\n### Convert Model\n\n1. 从[google driver](https://drive.google.com/drive/folders/1EBDUN793q9mJwNC1NA5s2nfq0SxMTx4b?usp=drive_link)中下载模型，放到`/workspace/models/`下\n\n2. 在docker容器内，运行模型转换脚本\n```bash\ncd /workspace\nbash tools/cvt_onnx2trt.sh\n```\n\n### Run Test Cases\n\n1. 下载测试数据[link](https://drive.google.com/drive/folders/13PwIl8TBYT54YhSAPmuKI98IB99GElOj?usp=drive_link)，放到`/workspace/test_data`下，文件夹名为`golf`\n\n2. 运行测试用例，具体测试用例请参考代码。\n```bash\ncd /workspace/build\n./bin/test_sam_sam2 --gtest_filter=*correctness\n# 限制GLOG输出\nGLOG_minloglevel=1 ./bin/test_sam_sam2 --gtest_filter=*speed\n# 使用ctest查看可用测试用例\nctest -N\n# 直接使用ctest测试全部用例\nctest\n```\n\n## References\n\n- [sam2](https://github.com/facebookresearch/sam2)\n- [SAM2Export](https://github.com/Aimol-l/SAM2Export)\n- [EasyDeployTool](https://github.com/zz990099/EasyDeployTool)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzz990099%2Fsam2_cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzz990099%2Fsam2_cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzz990099%2Fsam2_cpp/lists"}