Skip to content

Deploy an Endpoint for Object detection Mask R-CNN

1. Subscribe to the offering

  1. Log in to AWS with a user with administrative privileges
  2. Navigate to the Object Detection Mask R-CNN listing on the AWS Marketplace
  3. Click Continue to Subscribe
  4. Click on Accept offer (it might take 1 or 2 minutes for AWS to accept the offer)

    Note that there is no charge for subscribing to this offering only when launching the Endpoint on SageMaker.

  5. Once you are subscribed click Continue to Configuration

  6. On the Configure and launch page
    1. Select SageMaker console as the Launch Method (you can also use the AWS CLI)
    2. Select the version and region where you want to launch the model endpoint
    3. On Amazon SageMaker options select Create a real-time inference endpoint
  7. Click on View in Amazon SageMaker

2. Create the endpoint

In the Create endpoint page:

  1. Select a Model name e.g. img-obj-mask-r-cnn
  2. Select or create a new IAM role for executing the model
  3. Under Container definition
    1. Verify Use a model package subscription from AWS Marketplace is selected
  4. Click on Next
  5. Select an Endpoint name e.g. img-obj-mask-r-cnn
  6. Under Attach endpoint configuration select Create a new endpoint configuration
  7. Under New endpoint configuration
    1. Verify the new model (e.g. img-obj-mask-r-cnn) is listed under Production variants
    2. Click on Edit in the Actions column and select the instance types you want for the endpoint. The minimun recommended is ml.c5.xlarge
    3. Click on Create endpoint configuration
  8. Finally click on Submit

A new endpoint will be created (this can take a couple of minutes):

SageMaker efficientnet-b3 endpoint

3. Making a query

With the endpoint ready you will have an URL to make predictions, for example:

https://runtime.sagemaker.us-east-1.amazonaws.com/endpoints/img-obj-mask-r-cnn/invocations

How to query this Endpoint

For complete documentation on how to query this endpoint see the AWS Docs: InvokeEndpoint documentation in AWS.

The key part being how to handlee the AWS Signature Version 4, for example using Python.

A simple example using boto and this photo as input:

Horses

import boto3

# Read image
with open("validation/horse-guard.jpg", "rb") as f:
    payload = bytearray(f.read())

# Make request
content_type = "image/jpeg"
accept_mime_type = "image/jpeg"

response = client.invoke_endpoint(
    EndpointName=endpoint_name,
    ContentType=content_type,
    Accept=accept_mime_type,
    Body=payload,
)

# Write segmented output image
with open("validation/horse-guard.segmented.jpg", "wb") as f:
    f.write(response["Body"].read())

Response:

Horses

Full API docs

For the complete documentation of the API including the different inputs and responses and more ways to query the Invocations endpoint see the API page.