Invoke an Image based model on SageMaker

This topic describes how to invoke an image-based model on AWS SageMaker using an example that upscales the input image. Image upscaling with machine learning typically involves using deep learning models, such as convolutional neural networks (CNNs), to increase the resolution or quality of images.

Note:

The AWS mark and logo are trademarks or registered trademarks of Amazon.com, Inc. and are used for identification purposes only.

A low-resolution image is transformed into a high-resolution image by upscaling the image using stable diffusion in the Amazon AWS SageMaker JumpStart model. The low-resolution image is encoded to a Base64 format and is given to the model for upscaling. The image below provides you with a flow that is followed in this upscaling process. For more information on AWS SageMaker JumpStart model, see AWS SageMaker InvokeEndpoint JumpStart Upscale Images and AWS SageMaker InvokeEndpoint JumpStart Upscaling. AWS SageMaker Image Convertion Process

Procedure

  1. In the Control Room, click Configure using SageMaker endpoints discovery to get the list of endpoints. AWS Invoke SageMaker Endpoint
    1. Enter the credentials as described in Authentication action.
    2. Click Region drop-down to select a region of your AWS instance from where you want to get the endpoints.
    3. Click Connect.
      It connects to the SageMaker and lists the Endpoint available in the region selected.
    4. Click an Endpoint name that corresponds to the model you want to use and click Select. An image-based model is used in this example. A pre-existing and a pre-trained model is used, and you can view the models already deployed by navigating to Inference > Endpoints. If you want to deploy a model of your choice, see AWS SageMaker Deploy models for inference and to train the deployed models, see AWS SageMaker Build, Train, and Deploy models for inference. To get more information on the models, click a model.
    5. Click Select.
      It auto fills the Endpoint Name and Region to the parent screen.
  2. Click Content Type drop-down to select the content payload type you want to input. In this example, select application/json;jpeg as the payload type.
  3. Store the low-resolution image in a folder and use the Base64 Conversion: Base64 Encode action to convert the image into a base64 encoded text. Input the base64 encoded text in a JSON format as shown in the example below:
    {
       "prompt":"a cat",
       "image":encoded_image,
       "num_inference_steps":50,
       "guidance_scale":7.5
    }
    The output of the base64 encode is used in the encoded_image.
  4. Enter Default as the session name or store the session in a Variable.
  5. The response JSON is stored in a variable str-ImageBasedModelResponse.
    The response JSON contains 2 parts:
    • Generated Image: The Generated Image node contains the binary of the upscaled image.
    • Prompt: The input prompt. In this example, it is a cat.
  6. You can use a base 64 decoder to convert the output into an image. In this example bot, each node of the JSON is read and the value of the Generated Image: node is passed to the decoder to generate the upscaled image.