Skip to main content
Version: v1.7.0

Tutorial 4B: Model deployment to H2O MLOps through the H2O Hydrogen Torch UI

Overview​

This tutorial explores one of the options available to deploy a built model. In particular, this tutorial builds an image regression model to explore how you can deploy a model to H2O MLOps through the H2O Hydrogen Torch UI.

Objectives​

  1. Understand how to upload a built model to H2O MLOps through the H2O Hydrogen Torch UI.
  2. Learn how to deploy the uploaded model and score new data with it in H2O MLOps.

Prerequisites​

Step 1: Import dataset​

For this tutorial, let's utilize the demo out-of-the-box preprocessed coins_image_regression.zip dataset. The dataset contains a collection of 6,028 images with one or more coins. Each image has been labeled to indicate the sum of its coins. The currency of the coins is the Brazilian Real (R$). Let's import the dataset.

  1. Open the import dataset wizard

    In the H2O Hydrogen Torch navigation menu, click Import dataset.

  2. Select the dataset file

    In the File name list, select coins_image_regression.zip.

  3. Click Continue.

  4. Click Continue.

  5. Click Continue.

Four Brazilian Real coins image called 150_1479430290.jpg

150_1479430290.jpg

Step 2: Build model​

Let's quickly build an image regression model capable of predicting the sum of Brazilian Real (R$) coins in images. After creating the model, we will deploy it to H2O MLOps through the H2O Hydrogen Torch UI.

  1. Start a new experiment

    In the H2O Hydrogen Torch navigation menu, click Create experiment.

  2. Select the dataset

    In the Dataset list, select coins_image_regression.

  3. Name the experiment

    In the Experiment name box, enter tutorial-4b.

  4. Run the experiment

    Click Run experiment.

Step 3: Upload model to H2O MLOps through the H2O Hydrogen Torch UI​

After a few minutes/seconds, you can upload the model to H2O MLOps. To upload the model through the H2O Hydrogen Torch UI, consider the following instructions:

  1. Open the experiments list

    In the H2O Hydrogen Torch navigation menu, click View experiments.

  2. Open the built experiment

    In the Experiments table, click tutorial-4b.

  3. Go to the MLOps tab

    Click the MLOps tab.

  4. Select an H2O MLOps workspace

    In the Workspace list, select an H2O MLOps workspace.

    note

    Each entry shows the workspace name followed by its UID. To upload the model to a new workspace, create the workspace in the H2O MLOps UI first.

  5. Upload the model

    Click Upload to MLOps.

    note

    H2O Hydrogen Torch registers the model in H2O MLOps under the experiment's name. After the upload completes, H2O Hydrogen Torch displays a success message and records the upload in the Uploaded models table. When H2O Hydrogen Torch can resolve the address of the H2O MLOps UI, the message also includes an Open in H2O MLOps button that opens the uploaded model in H2O MLOps. You can access your H2O MLOps account through the H2O MLOps legacy UI or the H2O MLOps Wave application.

    • To access the H2O MLOps legacy UI in the H2O AI Cloud, click MY MODELS. Legacy UI
    • To access the H2O MLOps Wave application, consider the following steps:
      1. In the H2O AI Cloud navigation menu, click APP STORE.
      2. In the search bar, enter H2O MLOps. Wave application
      3. Click the H2O MLOps tile.
      4. Click Visit. Visit

Step 4: Deploy the model and score new data​

Deployments are created and configured in H2O MLOps, where you can select a scoring runtime, turn on security and monitoring, and set Kubernetes resource requests and limits. To deploy the uploaded model, consider the following instructions:

  1. In H2O MLOps, open the workspace you uploaded the model to.
  2. Create a deployment of the registered tutorial-4b model. To learn how to create a deployment, see the H2O MLOps documentation.

After the deployment achieves a HEALTHY status, you can score new data with it. H2O MLOps provides the deployment's endpoint URL and sample scoring requests through its quick scoring feature. For instance, let's score the following image: 150_1479430290.jpg.

Four Brazilian Real coins image called 150_1479430290.jpg

150_1479430290.jpg

For image models, the image needs to be sent as a Base64-encoded string in the scoring request. For example, using Python:

import base64
import json

import cv2
import requests

URL = "<the deployment's endpoint URL>"

img = cv2.imread("150_1479430290.jpg")
_, buffer = cv2.imencode(".png", img)
data = base64.b64encode(buffer).decode()

response = requests.post(
url=URL,
json={"fields": ["image_path"], "rows": [[data]]},
)
if response.status_code != 200:
raise ValueError(
f"Error in the H2O MLOps deployment with a status code: {response.status_code}. "
"Check the H2O MLOps deployment logs."
)

print(json.loads(response.json()["score"][0][0]))
note

The sample code calls json.loads() on the scored value, which assumes the JSON-encoded string output format. If you built the experiment with the Native MLOps output training setting turned on, remove that call: the scored value is already a JSON object.

413 Request Entity Too Large

If you obtain the following error after running the scoring request, you need to reduce the image size: 413 Request Entity Too Large. For example:

img = cv2.imread("150_1479430290.jpg")
img = cv2.resize(img, (200, 150)) # From 640x480 to 200x150

For example, scoring the 150_1479430290.jpg image, we receive the following response:

{'predictions': [143.6985321044922], 'labels': [['label']]}

Summary​

In this tutorial, we learned how to upload a built model to H2O MLOps through the H2O Hydrogen Torch UI, deploy it in H2O MLOps, and score new data with the deployed model.

Next​

Now that you know how to deploy a built model to H2O MLOps through the H2O Hydrogen Torch UI, consider the following tutorials to learn about the other options to deploy a built model:


Feedback