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
- Understand how to upload a built model to H2O MLOps through the H2O Hydrogen Torch UI.
- Learn how to deploy the uploaded model and score new data with it in H2O MLOps.
Prerequisites
- Access to H2O Hydrogen Torch v1.7.0
- Intermediate understanding of H2O MLOps
- Basic understanding of Python and how to run a Python script
- Complete Tutorial 1A: Default hyperparameter values
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.
- Open the import dataset wizard
In the H2O Hydrogen Torch navigation menu, click Import dataset.
- Select the dataset file
In the File name list, select coins_image_regression.zip.
Click Continue.
Click Continue.
Click Continue.
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.
- Start a new experiment
In the H2O Hydrogen Torch navigation menu, click Create experiment.
- Select the dataset
In the Dataset list, select coins_image_regression.
- Name the experiment
In the Experiment name box, enter
tutorial-4b. - 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:
- Open the experiments list
In the H2O Hydrogen Torch navigation menu, click View experiments.
- Open the built experiment
In the Experiments table, click tutorial-4b.
- Go to the MLOps tab
Click the MLOps tab.
- Select an H2O MLOps workspace
In the Workspace list, select an H2O MLOps workspace.
noteEach 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.
- Upload the model
Click Upload to MLOps.
noteH2O 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.

- To access the H2O MLOps Wave application, consider the following steps:
- In the H2O AI Cloud navigation menu, click APP STORE.
- In the search bar, enter
H2O MLOps.
- Click the H2O MLOps tile.
- Click Visit.

- To access the H2O MLOps legacy UI in the H2O AI Cloud, click MY MODELS.
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:
- In H2O MLOps, open the workspace you uploaded the model to.
- 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.
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]))
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.
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:
- Tutorial 1B: Model deployment in the H2O Hydrogen Torch UI
- Tutorial 2B: Model deployment with a model's H2O MLOps pipeline
- Tutorial 3B: Model deployment with a model's Python scoring pipeline
- Submit and view feedback for this page
- Send feedback about H2O Hydrogen Torch to cloud-feedback@h2o.ai