Skip to content
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

Segment anything 2 pipeline image #165

Closed
wants to merge 19 commits into from

Conversation

pschroedl
Copy link
Collaborator

@pschroedl pschroedl commented Aug 21, 2024

This pull request introduces an implementation of the Segment Anything v2 (SAM2) pipeline within the AI worker.

This implements the basic functionality needed to perform segmentation on an image, including specifying points and labels. Returns the scores, logits, and low-res-masks.

In addition, this PR introduces a new method of adding pipelines dependencies without breaking existing implementations present in ai-runner. Example usage for local development:

cd ai-worker/runner
docker build -t livepeer/ai-runner:base .
docker build -f ../cmd/segment-anything-2/Dockerfile.segment_anything_2 -t livepeer/ai-runner:segment-anything-2 .

docker run --name sam2-runnner -e MODEL_DIR=/models -e PIPELINE=segment-anything-2 -e MODEL_ID=facebook/sam2-hiera-large -e HUGGINGFACE_TOKEN={token} --gpus 0 -p 8002:8000 -v ~/.lpData/models:/models livepeer/ai-runner:segment-anything-2

The existing Dockerfile is specified as a 'base' image ( e.g. : FROM livepeer/ai-runner:base ) in cmd/segment-anything-2/Dockerfile.segment_anything_2.

The go-livepeer PR here implements the logic necessary to launch this pipeline-specific container when appropriate : livepeer/go-livepeer#3131

rickstaa and others added 18 commits August 13, 2024 22:53
This commit introduces a prototype implementation of the
[Segment Anything v2](https://github.com/facebookresearch/segment-anything-2)
(SAM2) pipeline within the AI worker. The prototype demonstrates the basic
functionality needed to perform segmentation on an image. Note that video
segmentation is not yet implemented. Additionally, the dependencies were
updated quickly, which may temporarily break other pipelines.
This commit allows nested arrays to be supplied as JSON strings for SAM2
input. It also implements robust error handling to return a 400 error with
a descriptive message when incorrect parameters are provided.
This commit ensures that we return the masks, iou_predictions and
low_res_masks in json format.
This commit replaces the JSON.dump method with a simple str method since
it is highly unlikely that the string contains invalid data.

Co-authored-by: Peter Schroedl <[email protected]>
@pschroedl pschroedl closed this Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants