x-segment-anything


Namex-segment-anything JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/Jordan-Pierce/xSAM
SummaryNone
upload_time2024-12-11 14:21:57
maintainerNone
docs_urlNone
authorJordan Pierce
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # xSAM

Segment Anything Model (SAM) variants including:
- CoralSCOP
- RepViT-SAM 
- EdgeSAM
- MobileSAM
- SAM (original) 

combined in the same API (to make life easier).

For more information on different SAM variants, please see the following:
- [_On Efficient Variants of Segment Anything Model: A Survey_](https://arxiv.org/html/2410.04960v1)

## Installation

The code requires `python>=3.8`, as well as `pytorch>=1.7` and `torchvision>=0.8`. 
Please follow the instructions [here](https://pytorch.org/get-started/locally/) to install both PyTorch and TorchVision 
dependencies. Installing both PyTorch and TorchVision with CUDA support is strongly recommended.

Install xSAM:

```bash
pip install x-segment-anything
```

## Getting Started
The SAM models can be loaded in the following ways:

```python
from x_segment_anything import sam_model_registry, SamPredictor

model_type = "vit_b_coralscop"
model_type = "repvit"
model_type = "edge_sam"
model_type = "vit_t"
model_type = "vit_b"
model_type = "vit_l"
model_type = "vit_h"

sam_checkpoint = "path_to_checkpoints/model_x_weights.pt"

device = "cuda" if torch.cuda.is_available() else "cpu"

x_sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)
x_sam.to(device=device)
x_sam.eval()

predictor = SamPredictor(x_sam)
predictor.set_image(<your_image>)
masks, _, _ = predictor.predict(<input_prompts>)
```

or generate masks for an entire image:

```python
from x_segment_anything import SamAutomaticMaskGenerator

mask_generator = SamAutomaticMaskGenerator(x_sam)
masks = mask_generator.generate(<your_image>)
```

## Model Checkpoints
For convenience, The following model checkpoints are available in the `sam_model_urls` dictionary and can be downloaded 
in python:

```python
import requests
from x_segment_anything.build_sam import sam_model_urls

def download_asset(asset_url, asset_path):
    response = requests.get(asset_url)
    with open(asset_path, 'wb') as f:
        f.write(response.content)

model_path = "vit_b_coral_scop.pt"
model_path = "repvit.pt"
model_path = "edge_sam.pt"
model_path = "edge_sam_3x.pt"
model_path = "vit_t.pt"
model_path = "vit_b.pt"
model_path = "vit_l.pt"
model_path = "vit_h.pt"

model = model_path.split(".")[0]
model_url = sam_model_urls[model]

download_asset(model_url, model_path)

```

### Model Checkpoint URLs:
- [coralscop](https://github.com/Jordan-Pierce/CoralSCOP/releases/download/v0.0.1/vit_b_coralscop.pth)
- [repvit](https://huggingface.co/spaces/jameslahm/repvit-sam/resolve/main/repvit_sam.pt)
- [edge_sam](https://huggingface.co/spaces/chongzhou/EdgeSAM/resolve/main/weights/edge_sam.pth)
- [edge_sam_3x](https://huggingface.co/spaces/chongzhou/EdgeSAM/resolve/main/weights/edge_sam_3x.pth)
- [vit_t](https://huggingface.co/spaces/dhkim2810/MobileSAM/resolve/main/mobile_sam.pt)
- [vit_b](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth)
- [vit_l](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth)
- [vit_h](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth)

### Acknowledgements:
- [CoralSCOP](https://github.com/zhengziqiang/CoralSCOP)
- [RepViT-SAM](https://github.com/THU-MIG/RepViT/tree/main)
- [EdgeSAM](https://github.com/chongzhou96/EdgeSAM)
- [MobileSAM](https://github.com/ChaoningZhang/MobileSAM)
- [SAM](https://github.com/facebookresearch/segment-anything)

--- 
## Disclaimer

This repository is a scientific product and is not official communication of the National 
Oceanic and Atmospheric Administration, or the United States Department of Commerce. All NOAA 
GitHub project code is provided on an 'as is' basis and the user assumes responsibility for its 
use. Any claims against the Department of Commerce or Department of Commerce bureaus stemming from 
the use of this GitHub project will be governed by all applicable Federal law. Any reference to 
specific commercial products, processes, or services by service mark, trademark, manufacturer, or 
otherwise, does not constitute or imply their endorsement, recommendation or favoring by the 
Department of Commerce. The Department of Commerce seal and logo, or the seal and logo of a DOC 
bureau, shall not be used in any manner to imply endorsement of any commercial product or activity 
by DOC or the United States Government.


## License 

Software code created by U.S. Government employees is not subject to copyright in the United States 
(17 U.S.C. ยง105). The United States/Department of Commerce reserve all rights to seek and obtain 
copyright protection in countries other than the United States for Software authored in its 
entirety by the Department of Commerce. To this end, the Department of Commerce hereby grants to 
Recipient a royalty-free, nonexclusive license to use, copy, and create derivative works of the 
Software outside of the United States.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Jordan-Pierce/xSAM",
    "name": "x-segment-anything",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jordan Pierce",
    "author_email": "jordan.pierce@noaa.gov",
    "download_url": "https://files.pythonhosted.org/packages/aa/42/59d6024a9dba044b4ade003c8d043e394a46d750c6923c9f1c1093da2dda/x_segment_anything-0.0.7.tar.gz",
    "platform": null,
    "description": "# xSAM\n\nSegment Anything Model (SAM) variants including:\n- CoralSCOP\n- RepViT-SAM \n- EdgeSAM\n- MobileSAM\n- SAM (original) \n\ncombined in the same API (to make life easier).\n\nFor more information on different SAM variants, please see the following:\n- [_On Efficient Variants of Segment Anything Model: A Survey_](https://arxiv.org/html/2410.04960v1)\n\n## Installation\n\nThe code requires `python>=3.8`, as well as `pytorch>=1.7` and `torchvision>=0.8`. \nPlease follow the instructions [here](https://pytorch.org/get-started/locally/) to install both PyTorch and TorchVision \ndependencies. Installing both PyTorch and TorchVision with CUDA support is strongly recommended.\n\nInstall xSAM:\n\n```bash\npip install x-segment-anything\n```\n\n## Getting Started\nThe SAM models can be loaded in the following ways:\n\n```python\nfrom x_segment_anything import sam_model_registry, SamPredictor\n\nmodel_type = \"vit_b_coralscop\"\nmodel_type = \"repvit\"\nmodel_type = \"edge_sam\"\nmodel_type = \"vit_t\"\nmodel_type = \"vit_b\"\nmodel_type = \"vit_l\"\nmodel_type = \"vit_h\"\n\nsam_checkpoint = \"path_to_checkpoints/model_x_weights.pt\"\n\ndevice = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n\nx_sam = sam_model_registry[model_type](checkpoint=sam_checkpoint)\nx_sam.to(device=device)\nx_sam.eval()\n\npredictor = SamPredictor(x_sam)\npredictor.set_image(<your_image>)\nmasks, _, _ = predictor.predict(<input_prompts>)\n```\n\nor generate masks for an entire image:\n\n```python\nfrom x_segment_anything import SamAutomaticMaskGenerator\n\nmask_generator = SamAutomaticMaskGenerator(x_sam)\nmasks = mask_generator.generate(<your_image>)\n```\n\n## Model Checkpoints\nFor convenience, The following model checkpoints are available in the `sam_model_urls` dictionary and can be downloaded \nin python:\n\n```python\nimport requests\nfrom x_segment_anything.build_sam import sam_model_urls\n\ndef download_asset(asset_url, asset_path):\n    response = requests.get(asset_url)\n    with open(asset_path, 'wb') as f:\n        f.write(response.content)\n\nmodel_path = \"vit_b_coral_scop.pt\"\nmodel_path = \"repvit.pt\"\nmodel_path = \"edge_sam.pt\"\nmodel_path = \"edge_sam_3x.pt\"\nmodel_path = \"vit_t.pt\"\nmodel_path = \"vit_b.pt\"\nmodel_path = \"vit_l.pt\"\nmodel_path = \"vit_h.pt\"\n\nmodel = model_path.split(\".\")[0]\nmodel_url = sam_model_urls[model]\n\ndownload_asset(model_url, model_path)\n\n```\n\n### Model Checkpoint URLs:\n- [coralscop](https://github.com/Jordan-Pierce/CoralSCOP/releases/download/v0.0.1/vit_b_coralscop.pth)\n- [repvit](https://huggingface.co/spaces/jameslahm/repvit-sam/resolve/main/repvit_sam.pt)\n- [edge_sam](https://huggingface.co/spaces/chongzhou/EdgeSAM/resolve/main/weights/edge_sam.pth)\n- [edge_sam_3x](https://huggingface.co/spaces/chongzhou/EdgeSAM/resolve/main/weights/edge_sam_3x.pth)\n- [vit_t](https://huggingface.co/spaces/dhkim2810/MobileSAM/resolve/main/mobile_sam.pt)\n- [vit_b](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth)\n- [vit_l](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth)\n- [vit_h](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth)\n\n### Acknowledgements:\n- [CoralSCOP](https://github.com/zhengziqiang/CoralSCOP)\n- [RepViT-SAM](https://github.com/THU-MIG/RepViT/tree/main)\n- [EdgeSAM](https://github.com/chongzhou96/EdgeSAM)\n- [MobileSAM](https://github.com/ChaoningZhang/MobileSAM)\n- [SAM](https://github.com/facebookresearch/segment-anything)\n\n--- \n## Disclaimer\n\nThis repository is a scientific product and is not official communication of the National \nOceanic and Atmospheric Administration, or the United States Department of Commerce. All NOAA \nGitHub project code is provided on an 'as is' basis and the user assumes responsibility for its \nuse. Any claims against the Department of Commerce or Department of Commerce bureaus stemming from \nthe use of this GitHub project will be governed by all applicable Federal law. Any reference to \nspecific commercial products, processes, or services by service mark, trademark, manufacturer, or \notherwise, does not constitute or imply their endorsement, recommendation or favoring by the \nDepartment of Commerce. The Department of Commerce seal and logo, or the seal and logo of a DOC \nbureau, shall not be used in any manner to imply endorsement of any commercial product or activity \nby DOC or the United States Government.\n\n\n## License \n\nSoftware code created by U.S. Government employees is not subject to copyright in the United States \n(17 U.S.C. \u00a7105). The United States/Department of Commerce reserve all rights to seek and obtain \ncopyright protection in countries other than the United States for Software authored in its \nentirety by the Department of Commerce. To this end, the Department of Commerce hereby grants to \nRecipient a royalty-free, nonexclusive license to use, copy, and create derivative works of the \nSoftware outside of the United States.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": null,
    "version": "0.0.7",
    "project_urls": {
        "Homepage": "https://github.com/Jordan-Pierce/xSAM"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b9bc9a78afa327cdc3d29b57687a984d8a7e511be8e68b09783bbb386b8f6a45",
                "md5": "fd243800198069937b58ac0f5ac7a17d",
                "sha256": "2886fc8c3c97e872765b998ec6bf15a7c6ea59d9be24927fd6a347c929d07f42"
            },
            "downloads": -1,
            "filename": "x_segment_anything-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fd243800198069937b58ac0f5ac7a17d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 50312,
            "upload_time": "2024-12-11T14:21:54",
            "upload_time_iso_8601": "2024-12-11T14:21:54.872030Z",
            "url": "https://files.pythonhosted.org/packages/b9/bc/9a78afa327cdc3d29b57687a984d8a7e511be8e68b09783bbb386b8f6a45/x_segment_anything-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aa4259d6024a9dba044b4ade003c8d043e394a46d750c6923c9f1c1093da2dda",
                "md5": "1cacc6be665c7821b10c65b64dfd8986",
                "sha256": "191125a7e919f4e00905760dfa678c16c663b0957b8c7b2d6b4cf44c5729a612"
            },
            "downloads": -1,
            "filename": "x_segment_anything-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "1cacc6be665c7821b10c65b64dfd8986",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 40605,
            "upload_time": "2024-12-11T14:21:57",
            "upload_time_iso_8601": "2024-12-11T14:21:57.247388Z",
            "url": "https://files.pythonhosted.org/packages/aa/42/59d6024a9dba044b4ade003c8d043e394a46d750c6923c9f1c1093da2dda/x_segment_anything-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-11 14:21:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Jordan-Pierce",
    "github_project": "xSAM",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "x-segment-anything"
}
        
Elapsed time: 0.40279s