Segment Anything Model (SAM) inference

Hi,

I’m working on a project that uses SAM to do image segmentation. I’m trying to deploy the “sam-vit-large” model (found here: facebook/sam-vit-large · Hugging Face) on AWS SageMaker using the code given in the deployment section. I have managed to deploy the endpoint on SageMaker, but I’m not sure what the payload/input I need to give the endpoint is; would it be in json format? If so, what would be the properties?

Thanks!

Did you find an answer to this? I would love to know what you found out if so.

Thanks!

hi it looks like the HuggingFace sagemaker needs to update the transformers images, currently the latest version support is 4.28.1 and SAM is only integrated on transformers 4.29.0 cc @philschmid for an update. Also my guess is SAM my need a custom inference handler, please look https://github.com/huggingface/notebooks/blob/main/sagemaker/17_custom_inference_script/sagemaker-notebook.ipynb

1 Like

I am trying to pass an model to this model like this in sagemaker

with open(“/root/aws-sam/02.JPG”, “rb”) as f:
data = f.read()
#raw_image = Image.open(data).convert(“RGB”)
response = runtime.invoke_endpoint(EndpointName=ENDPOINT_NAME,
ContentType=‘image/jpeg’, #image/jpeg image/x-image’
Body=data)

I am getting this error

2023-10-26T09:42:33.354-07:00

Copy
2023-10-26T16:42:33,265 [INFO ] W-9000-facebook__sam-vit-large-stdout com.amazonaws.ml.mms.wlm.WorkerLifeCycle - raise KeyError(key)
2023-10-26T16:42:33,265 [INFO ] W-9000-facebook__sam-vit-large-stdout com.amazonaws.ml.mms.wlm.WorkerLifeCycle - raise KeyError(key) AllTraffic/i-0dad3e9d16762a67f

2023-10-26T09:42:33.354-07:00

Copy
2023-10-26T16:42:33,265 [INFO ] W-9000-facebook__sam-vit-large-stdout com.amazonaws.ml.mms.wlm.WorkerLifeCycle - KeyError: ‘sam’
2023-10-26T16:42:33,265 [INFO ] W-9000-facebook__sam-vit-large-stdout com.amazonaws.ml.mms.wlm.WorkerLifeCycle - KeyError: ‘sam’ AllTraffic/i-0dad3e9d16762a67f

2023-10-26T09:42:37.363-07:00

Copy
2023-10-26T16:42:33,265 [INFO ] W-9000-facebook__sam-vit-large-stdout com.amazonaws.ml.mms.wlm.WorkerLifeCycle - Model facebook__sam-vit-large loaded io_fd=966296fffe2e23f7-00000015-00000000-a9415483c6ddb70e-6cd401cc
2023-10-26T16:42:33,265 [INFO ] W-9000-facebook__sam-vit-large-stdout com.amazonaws.ml.mms.wlm.WorkerLifeCycle - Model facebook__sam-vit-large loaded io_fd=966296fffe2e23f7-00000015-00000000-a9415483c6ddb70e-6cd401cc