-
-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for SAM 2 #312
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🚀 Deployed on https://66e87055e71a803c2aff3721--opengeos.netlify.app |
from samgeo import SamGeo2
sam2 = SamGeo2(
model_id="sam2-hiera-large",
apply_postprocessing=False,
points_per_side=32,
points_per_batch=64,
pred_iou_thresh=0.7,
stability_score_thresh=0.92,
stability_score_offset=0.7,
crop_n_layers=1,
box_nms_thresh=0.7,
crop_n_points_downscale_factor=2,
min_mask_region_area=25.0,
use_m2m=True,
)
image = "images/satellite.tif"
masks = sam2.generate(image) |
Peek.2024-09-13.15-56.mp4 |
What an exciting time we are in! |
Closed
|
@brendancol Yes, we should be able to add support for LangSAM. |
from samgeo import SamGeo2
predictor = SamGeo2(video=True)
video_path = "input_video.mp4"
predictor.set_video(video_path)
prompts = {
1: {
"points": [[200, 300], [275, 175]],
"labels": [1, 0],
"frame_idx": 0,
},
2: {
"points": [[400, 150]],
"labels": [1],
"frame_idx": 0,
},
}
predictor.predict_video(prompts)
predictor.save_video_segments_blended(
"blended", output_video="output_video.mp4", fps=30
) input video input_video.mp4output video output_video.mp4 |
from samgeo import SamGeo2
predictor = SamGeo2(video=True)
video_path = "input_video.mp4"
predictor.set_video(video_path, frame_rate=3)
prompts = {
1: {
"points": [[200, 300], [275, 175]],
"labels": [1, 0],
"frame_idx": 0,
},
2: {
"points": [[400, 150]],
"labels": [1],
"frame_idx": 0,
},
}
predictor.show_prompts(prompts, frame_idx=0) |
from samgeo import SamGeo2
predictor = SamGeo2(video=True)
video_path = "landsat_ts"
predictor.set_video(video_path)
prompts = {
1: {
"points": [[1582, 933], [1287, 905], [1473, 998]],
"labels": [1, 1, 1],
"frame_idx": 0,
},
}
predictor.show_prompts(prompts, frame_idx=0)
predictor.predict_video(prompts)
predictor.save_video_segments("segments") Input GeoTIFFs landsat_images.mp4Point prompts Output GeoTIFFs landsat_water.mp4Blended mode landsat_water_blended.mp4 |
Input points can be either XY or lon/lat pairs. from samgeo import SamGeo2
predictor = SamGeo2(video=True)
video_path = "landsat_ts"
predictor.set_video(video_path)
prompts = {
1: {
"points": [[-74.3713, -8.5218], [-74.2973, -8.5306], [-74.3230, -8.5495]],
"labels": [1, 1, 1],
"frame_idx": 0,
},
}
predictor.show_prompts(prompts, frame_idx=0, point_crs="EPSG:4326")
predictor.predict_video()
predictor.save_video_segments_blended(
"blended", fps=5, output_video="landsat_water_blended.mp4"
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for Meta's Segment Anything Model 2 (SAM 2).
https://github.com/facebookresearch/segment-anything-2
https://github.com/IDEA-Research/Grounded-SAM-2?tab=readme-ov-file#grounded-sam-2-video-object-tracking-demo
Work in progress