{"id":24565033,"url":"https://github.com/mikeesto/sam2-coreml-python","last_synced_at":"2025-03-17T01:44:58.980Z","repository":{"id":270547434,"uuid":"910040718","full_name":"mikeesto/sam2-coreml-python","owner":"mikeesto","description":"Run Segment Anything 2 (SAM 2) on macOS using Core ML models","archived":false,"fork":false,"pushed_at":"2025-01-06T06:00:36.000Z","size":13,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T11:36:13.786Z","etag":null,"topics":["coreml","python","sam2","segment-anything"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikeesto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-12-30T10:51:05.000Z","updated_at":"2025-01-06T06:00:39.000Z","dependencies_parsed_at":"2025-01-01T08:20:16.122Z","dependency_job_id":"78092fa1-7457-4b41-a04e-d29fb3b27950","html_url":"https://github.com/mikeesto/sam2-coreml-python","commit_stats":null,"previous_names":["mikeesto/sam2-coreml-python"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeesto%2Fsam2-coreml-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeesto%2Fsam2-coreml-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeesto%2Fsam2-coreml-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeesto%2Fsam2-coreml-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikeesto","download_url":"https://codeload.github.com/mikeesto/sam2-coreml-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243960435,"owners_count":20375101,"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","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":["coreml","python","sam2","segment-anything"],"created_at":"2025-01-23T11:31:49.318Z","updated_at":"2025-03-17T01:44:58.958Z","avatar_url":"https://github.com/mikeesto.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Segment Anything 2 - Core ML\n\nRun Segment Anything 2 (SAM 2) on macOS using Core ML models.\n\n## Installation\n\n1. Clone this repository\n2. Install dependencies:\n\n```bash\npip install coremltools numpy pillow opencv-python\n```\n\n## Directory Structure\n\n```\nsam2-coreml-python/\n├── models/\n│   ├── SAM2_1SmallImageEncoderFLOAT16.mlpackage\n│   ├── SAM2_1SmallPromptEncoderFLOAT16.mlpackage\n│   └── SAM2_1SmallMaskDecoderFLOAT16.mlpackage\n├── script.py\n└── README.md\n```\n\n## Usage\n\n1. Download the Core ML models and place them in the `models` directory\n2. Place your input image in the project directory\n3. Update the `script.py` file with the input image path\n4. Run the script:\n\n```bash\npython script.py\n```\n\nThe script will generate `output_mask.png` containing the segmentation mask and `output_segmented.png` containing the segmented image.\n\n## Models\n\nThe script expects the SAM 2 Core ML models. These need to be downloaded separately and placed in your file system following the above directory structure.\n\nYou can find the models here on [Hugging Face](https://huggingface.co/collections/apple/core-ml-segment-anything-2-66e4571a7234dc2560c3db26). I used the `coreml-sam2.1-small` models on my MacBook Pro M3 and the inference time was around 4 seconds. The script will work with other models as well.\n\n## Credit\n\nI took regular inspiration when writing this script from the implementation of [sam2-studio](https://github.com/huggingface/sam2-studio), a SwiftUI app that uses the same Core ML models.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikeesto%2Fsam2-coreml-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikeesto%2Fsam2-coreml-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikeesto%2Fsam2-coreml-python/lists"}