Skip to main content

MetaSeg: Packaged version of the Segment Anything repository

Project description

MetaSeg: Packaged version of the Segment Anything repository

teaser
downloads HuggingFace Spaces

Package version Download Count Supported Python versions Project Status pre-commit.ci

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,
)
teaser

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metaseg-0.7.8.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

metaseg-0.7.8-py3-none-any.whl (47.9 kB view details)

Uploaded Python 3

File details

Details for the file metaseg-0.7.8.tar.gz.

File metadata

  • Download URL: metaseg-0.7.8.tar.gz
  • Upload date:
  • Size: 39.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for metaseg-0.7.8.tar.gz
Algorithm Hash digest
SHA256 d36c7638439cbfd92fafa0649cc77735be1799e1fa1c74497e23e9e3d7011ad2
MD5 2bae95f50f87a9fa3565ea7e58ed55a1
BLAKE2b-256 399465bc228f518bcc4839e8432802c6d53431a44c4bd771b270bc090eabf663

See more details on using hashes here.

File details

Details for the file metaseg-0.7.8-py3-none-any.whl.

File metadata

  • Download URL: metaseg-0.7.8-py3-none-any.whl
  • Upload date:
  • Size: 47.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for metaseg-0.7.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d3706d5936952a64a144baaf900c275f630b9c6f05222fa50087f7ede32a2989
MD5 07fff9002e9318162ffd381fd3c5e2b3
BLAKE2b-256 bcdb1f9944d64793d1aab9aa279fb833be2669ee3a5ec9233fd8349858e2bcd7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page