This repo is a packaged version of the segment-anything model.
Installation
pip install metaseg
Usage
from metaseg import SegAutoMaskPredictor, SegManualMaskPredictor
# If gpu memory is not enough, reduce the points_per_side and points_per_batch.
# For image
results = SegAutoMaskPredictor().image_predict(
source="image.jpg",
model_type="vit_l", # vit_l, vit_h, vit_b
points_per_side=16,
points_per_batch=64,
min_area=0,
output_path="output.jpg",
show=True,
save=False,
)
# For video
results = SegAutoMaskPredictor().video_predict(
source="video.mp4",
model_type="vit_l", # vit_l, vit_h, vit_b
points_per_side=16,
points_per_batch=64,
min_area=1000,
output_path="output.mp4",
)
# For manuel box and point selection
# For image
results = SegManualMaskPredictor().image_predict(
source="image.jpg",
model_type="vit_l", # vit_l, vit_h, vit_b
input_point=[[100, 100], [200, 200]],
input_label=[0, 1],
input_box=[100, 100, 200, 200], # or [[100, 100, 200, 200], [100, 100, 200, 200]]
multimask_output=False,
random_color=False,
show=True,
save=False,
)
# For video
results = SegManualMaskPredictor().video_predict(
source="video.mp4",
model_type="vit_l", # vit_l, vit_h, vit_b
input_point=[0, 0, 100, 100],
input_label=[0, 1],
input_box=None,
multimask_output=False,
random_color=False,
output_path="output.mp4",
)
SAHI + Segment Anything
pip install sahi metaseg
from metaseg.sahi_predict import SahiAutoSegmentation, sahi_sliced_predict
image_path = "image.jpg"
boxes = sahi_sliced_predict(
image_path=image_path,
detection_model_type="yolov5", # yolov8, detectron2, mmdetection, torchvision
detection_model_path="yolov5l6.pt",
conf_th=0.25,
image_size=1280,
slice_height=256,
slice_width=256,
overlap_height_ratio=0.2,
overlap_width_ratio=0.2,
)
SahiAutoSegmentation().image_predict(
source=image_path,
model_type="vit_b",
input_box=boxes,
multimask_output=False,
random_color=False,
show=True,
save=False,
)
FalAI(Cloud GPU) + Segment Anything
pip install metaseg fal_serverless
fal-serverless auth login
# For Auto Mask
from metaseg import falai_automask_image
image = falai_automask_image(
image_path="image.jpg",
model_type="vit_b",
points_per_side=16,
points_per_batch=32,
min_area=0,
)
image.show() # Show image
image.save("output.jpg") # Save image
# For Manual Mask
from metaseg import falai_manuelmask_image
image = falai_manualmask_image(
image_path="image.jpg",
model_type="vit_b",
input_point=[[100, 100], [200, 200]],
input_label=[0, 1],
input_box=[100, 100, 200, 200], # or [[100, 100, 200, 200], [100, 100, 200, 200]],
multimask_output=False,
random_color=False,
)
image.show() # Show image
image.save("output.jpg") # Save image
Extra Features
- Support for Yolov5/8, Detectron2, Mmdetection, Torchvision models
- Support for video and web application(Huggingface Spaces)
- Support for manual single multi box and point selection
- Support for pip installation
- Support for SAHI library
- Support for FalAI
Metadata
Release files for metaseg 0.7.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| metaseg-0.7.8.tar.gz | 39.2 kB | Without provenance | Details for metaseg-0.7.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| metaseg-0.7.8-py3-none-any.whl | Python 3 | none | any | Details for metaseg-0.7.8-py3-none-any.whl |
Total release size: 87.1 kB
Release files / metaseg-0.7.8.tar.gz
| Download URL | metaseg-0.7.8.tar.gz |
|---|---|
| Size | 39.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d36c7638439cbfd92fafa0649cc77735be1799e1fa1c74497e23e9e3d7011ad2
|
|
BLAKE2b-256 checksum How to use checksums |
399465bc228f518bcc4839e8432802c6d53431a44c4bd771b270bc090eabf663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Release files / metaseg-0.7.8-py3-none-any.whl
| Download URL | metaseg-0.7.8-py3-none-any.whl |
|---|---|
| Size | 47.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3706d5936952a64a144baaf900c275f630b9c6f05222fa50087f7ede32a2989
|
|
BLAKE2b-256 checksum How to use checksums |
bcdb1f9944d64793d1aab9aa279fb833be2669ee3a5ec9233fd8349858e2bcd7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.4
|
Security for metaseg 0.7.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.