Path: blob/master/cpd3.5/notebooks/rest_api/curl/experiments/deep_learning/Use Keras to recognize hand-written digits.ipynb
6408 views
Use Keras to recognize hand-written digits with Watson Machine Learning REST API
This notebook contains steps and code to demonstrate support of Keras Deep Learning experiments in Watson Machine Learning Service. It introduces commands for getting data, training experiments, persisting pipelines, publishing models, deploying models and scoring.
Some familiarity with cURL is helpful. This notebook uses cURL examples.
Learning goals
The learning goals of this notebook are:
Working with Watson Machine Learning experiments to train Deep Learning models.
Downloading computed models to local storage.
Online deployment and scoring of trained model.
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 password
.
<a href="https://cpd-spaces-api.eu-gb.cf.appdomain.cloud/#/Spaces/spaces_create" target="_blank" rel="noopener no referrer">Space creation
Space creation is asynchronous. This means that you need to check space creation status after creation call. Make sure that your newly created space is active
.
<a href="https://cpd-spaces-api.eu-gb.cf.appdomain.cloud/#/Spaces/spaces_get" target="_blank" rel="noopener no referrer">Get space information
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Model Definitions/model_definitions_create" target="_blank" rel="noopener no referrer">Store a model definition for Deep Learning experiment
<a href="https://github.com/IBM/watson-machine-learning-samples/raw/master/definitions/keras/mnist/MNIST.zip" target="_blank" rel="noopener no referrer">Download MNIST.zip
Tip: Convert below cell to code and run it to see model deinition's code.
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Model Definitions/model_definitions_upload_model" target="_blank" rel="noopener no referrer">Upload model for the model definition
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Trainings/trainings_create" target="_blank" rel="noopener no referrer">Schedule a training job for Deep Learning experiment
Specify the source files folder where you have stored your training data. The path should point to a local repository on Watson Machine Learning Accelerator that your system administrator has set up for your use.
Action: Change training_data_references: location: path: ...
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Trainings/trainings_get" target="_blank" rel="noopener no referrer">Get information about training job
Get training status
Please make sure that training is completed before you go to the next sections. Monitor state
of your training by running above cell couple of times.
Output should be similar to the output from training creation but you should see more trainings entries. Listing trainings:
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Trainings/trainings_list" target="_blank" rel="noopener no referrer">Get list of historical training jobs information
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Trainings/trainings_delete" target="_blank" rel="noopener no referrer">Canceling training
Before deployment creation, you need store your model in WML repository. Please see below cURL call example how to do it.
Download request.json
with repository request json for model storing.
You can specify user_defined_objects
if keras model used any
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Models/models_create" target="_blank" rel="noopener no referrer">Model storing
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Deployments/deployments_create" target="_blank" rel="noopener no referrer">Create deployment
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Deployments/deployments_get" target="_blank" rel="noopener no referrer">Get deployment details
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Deployment Jobs/deployment_jobs_create" target="_blank" rel="noopener no referrer">Create deployment job
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Deployments/deployments_list" target="_blank" rel="noopener no referrer">List deployments details
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Trainings/trainings_delete" target="_blank" rel="noopener no referrer">Deleting training
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Deployments/deployments_delete" target="_blank" rel="noopener no referrer">Delete deployment
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Models/models_delete" target="_blank" rel="noopener no referrer">Delete model from repository
<a href="https://watson-ml-v4-api.mybluemix.net/wml-restapi-cloud.html#/Model Definitions/model_definitions_delete" target="_blank" rel="noopener no referrer">Delete model definition
Authors
Jan Sołtysik, Intern in Watson Machine Learning at IBM
Copyright © 2020-2025 IBM. This notebook and its source code are released under the terms of the MIT License.