Path: blob/master/cpd4.8/notebooks/python_sdk/instance-management/Machine Learning artifacts export and import.ipynb
6405 views
Export/Import assets with ibm-watson-machine-learning
This notebook demonstrates an example for exporting/importing assets using Watson Machine Learning service. It contains steps and code to work with ibm-watson-machine-learning library available in PyPI repository.
Learning goals
The learning goals of this notebook are:
Download an externally trained Keras model.
Persist an external model in Watson Machine Learning repository.
Export the model from the space
Import the model to another space( For Cloud Pak for Data 4.0, the space/project where assets are imported has to be empty ) and deploy
Contents
This notebook contains the following parts:
Connection to WML
Authenticate the Watson Machine Learning service on IBM Cloud Pack for Data. You need to provide platform url
, your username
and api_key
.
Alternatively you can use username
and password
to authenticate WML services.
ibm-watson-machine-learning
is packaged in Cloud Pak For Data 4.0
Note: ibm-watson-machine-learning
documentation can be found here.
Create two spaces. One for export and one for import
Tip: You can refer to example for space management apis here.
In this section, you will learn how to store your model in Watson Machine Learning repository by using the Watson Machine Learning Client.
3.1: Publish model
Define model name, type and software specification needed to deploy model later.
3.2: Get model details
3.3 Get all models in the space
space_id is automatically picked up from client.set.default_space() api call before
client.export_assets has these apis. For any help on these apis, type 'help(api_name)' in your notebook Example: help(client.export_assets.start), help(client.export_assets.get_details)
client.export_assets.start: This starts the export job. export job is asynchronously executed
client.export_assets.get_details: Given export_id and corresponding space_id/project_id, this gives the export job details. Usually used for monitoring the export job submitted with start api
client.export_assets.list: Prints summary of all the export jobs
client.export_assets.get_exported_content: Downloads the exported content. This information will be used by the import process
client.export_assets.delete: Deletes the given export job
client.export_assets.cancel: Cancels the given export job if running
4.1: Start the export process
Start the export process for the model created. Either ASSET_IDS or ASSET_TYPES or ALL_ASSETS can be provided. If you have more than one model ids, you need to provide them as array like client.export_assets.ConfigurationMetaNames.ASSET_IDS: [model_id1, model_id2] Refer to the help api above to see different usages and details
4.2: Monitor the export process
4.3: Get the exported content
client.import_assets has these apis. For any help on these apis, type 'help(api_name)' in your notebook Example: help(client.import_assets.start), help(client.import_assets.get_details)
client.import_assets.start: This starts the import job. import job is asynchronously executed
client.import_assets.get_details: Given import_id and corresponding space_id/project_id, this gives the import job details. Usually used for monitoring the import job submitted with start api
client.import_assets.list: Prints summary of all the import jobs
client.import_assets.delete: Deletes the given import job
client.import_assets.cancel: Cancels the given import job if running
5.1: Start the import process
5.2: Monitor the import process
List the import and export jobs
6.1: Create model deployment
Create online deployment for published model
Now you can print an online scoring endpoint.
You can also list existing deployments.
6.2: Get deployment details
6.3: Score
You can use below method to do test scoring request against deployed model.
Let's first visualize two samples from dataset, we'll use for scoring. You must have matplotlib package installed
Prepare scoring payload with records to score.
Use client.deployments.score()
method to run scoring.
If you want to clean up all created assets:
experiments
trainings
pipelines
model definitions
models
functions
deployments
please follow up this sample notebook.
You successfully completed this notebook! You learned how to use export/import assets client apis. Check out our Online Documentation for more samples, tutorials, documentation, how-tos, and blog posts.
Authors
Mithun - [email protected], Software Engineer
Copyright © 2020-2025 IBM. This notebook and its source code are released under the terms of the MIT License.