需自行准备 SAM 权重,代码里通过 model_type 指定 vit_l/vit_h/vit_b;显存不足时要手动降低 points_per_side 和 points_per_batch;用 SAHI 或 FalAI 需额外安装 sahi、fal_serverless 并登录授权。
segment-anything-video
kadirnarApache-2.0活跃维护把 Meta 的 Segment Anything 打包成开箱即用的视频目标分割工具,配合 YOLOv5~v8 做检测后分割,省去自己搭环境的麻烦。
MetaSeg: Packaged version of the Segment Anything repository
pip install metasegREADME 未给出具体显存数值,仅提示显存不足时调小 points_per_side 和 points_per_batch;支持通过 FalAI 云端 GPU 运行。
把 Meta 的 Segment Anything 打包成 pip 包,支持图片和视频自动或手动分割
把 Meta 的 Segment Anything 打包成开箱即用的视频目标分割工具,配合 YOLOv5~v8 做检测后分割,省去自己搭环境的麻烦。
核心能力
- 用 pip 安装即可调用 SAM 做图像与视频分割
- 支持 vit_b/vit_l/vit_h 三种模型规格
- 自动掩码模式可调 points_per_side 与 points_per_batch
- 手动模式支持点选与框选,可多框多点多掩码输出
- 可结合 SAHI 切片检测或 FalAI 云端 GPU 推理
容易踩的坑
- v0.7.9Segment-Anything v0.7.9最新正式版2023-11-07 · 2023-11-07 11:38 UTC
What's Changed
- fix(pre_commit): ⬆ pre_commit autoupdate by @pre-commit-ci in https://github.com/kadirnar/segment-anything-video/pull/87
- fix(pre_commit): ⬆ pre_commit autoupdate by @pre-commit-ci in https://github.com/kadirnar/segment-anything-video/pull/89
- fix(pre_commit): ⬆ pre_commit autoupdate by @pre-commit-ci in https://github.com/kadirnar/segment-anything-video/pull/96
New Contributors
- @pre-commit-ci made their first contribution in https://github.com/kadirnar/segment-anything-video/pull/87
Full Changelog: https://github.com/kadirnar/segment-anything-video/compare/v0.7.8...v0.7.9
- v0.7.8Segment-Anything v0.7.82023-06-29 · 2023-06-29 14:40 UTC
查看更新说明
What's Changed
- fix: 🛠️ import movement and function clean up by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/80
- feat: 🚀 better model/file download function with md5 check by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/81
- feat: ✨ OpenCV image support by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/84
- ci(py-install-test): 🚧 initial github action python install test by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/85
Full Changelog: https://github.com/kadirnar/segment-anything-video/compare/v0.7.7...v0.7.8
- v0.7.6Segment-Anything v0.7.62023-06-27 · 2023-06-27 15:07 UTC
查看更新说明
What's Changed
- Project structure and pre-commit changes by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/72
- ci: 🎉 pypi release github action added by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/74
- ci: 🎉 conventional commits github action added by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/75
- onnx script fix and added as main package by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/73
- metaseg initial examples by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/76
- docs: 📝 Contributor Covenant Code of Conduct added by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/78
- feat(example): 🚀 sahi_slice_predict example added and .pt ignored by @onuralpszr in https://github.com/kadirnar/segment-anything-video/pull/79
Full Changelog: https://github.com/kadirnar/segment-anything-video/compare/v0.7.0...v0.7.6
- v0.7.0Segment-Anything v0.7.02023-04-23 · 2023-04-23 14:54 UTC
查看更新说明
What's Changed
- add video support for manuel_mask by @kadirnar in https://github.com/kadirnar/segment-anything-video/pull/50
- add falai(server) support by @kadirnar in https://github.com/kadirnar/segment-anything-video/pull/56
- add manuel mask for server by @kadirnar in https://github.com/kadirnar/segment-anything-video/pull/57
- update version by @kadirnar in https://github.com/kadirnar/segment-anything-video/pull/58
Full Changelog: https://github.com/kadirnar/segment-anything-video/compare/v0.6.0...v0.7.0
- v0.6.0Segment-Anything v0.6.02023-04-12 · 2023-04-12 12:08 UTC
查看更新说明
What's Changed
- update readme by @kadirnar in https://github.com/kadirnar/segment-anything-video/pull/41
- Update save by @kadirnar in https://github.com/kadirnar/segment-anything-video/pull/44
- update web demo by @kadirnar in https://github.com/kadirnar/segment-anything-video/pull/47
Full Changelog: https://github.com/kadirnar/segment-anything-video/compare/v0.5.0...v0.6.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
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