No project description provided
Project description
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
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,
)
SAHI + Segment Anything
from metaseg import sahi_sliced_predict, SahiAutoSegmentation
image_path = "test.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().predict(
source=image_path,
model_type="vit_b",
input_box=boxes,
multimask_output=False,
random_color=False,
show=True,
save=False,
)
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
Project details
Release history Release notifications | RSS feed
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.5.6.tar.gz
(37.1 kB
view hashes)