LoginSignup
3
1

More than 3 years have passed since last update.

Watson Machine Learningのコマンドラインインターフェイス

Last updated at Posted at 2018-06-26

はじめに

Watson Machine Learningにいつの間にかコマンドラインができていました。
UIからはTraining Definitionとか消せないので、何度もテストしてゴミがたまってくるととても便利です。
その利用メモを残しておきます。

(2019-07-08) 最新コマンドに更新
(2019-09-03) わかりにくかった箇所に画面コピー追加

前提

IBM Cloudのibmcloudコマンドが使えることが前提です。
まだの場合はIBM Cloud CLIから導入して下さい。

導入手順

次のコマンドで導入します。

$ ibmcloud plugin install machine-learning

設定

まず、IBM CloudのダッシュボードからWatson MLの管理画面に入り、認証情報を取得します。
次にその認証情報をコマンドラインの環境変数として設定します。

Windowsの場合

setenv.bat
set ML_ENV=https://us-south.ml.cloud.ibm.com
set ML_USERNAME=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
set ML_PASSWORD=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
set ML_INSTANCE=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Macの場合

setenv.sh
export ML_ENV=https://us-south.ml.cloud.ibm.com
export ML_USERNAME=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export ML_PASSWORD=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export ML_INSTANCE=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

MACの場合は、上のバッチファイルを用意して次のコマンドを実行

$ source ./setenv.sh

GUIDの取得/設定

GUIDは、IBM Cloud 管理画面のWatson Machine Learningの行で、一番左の名称(ここがリンクになっている)以外の部分をクリックすると表示されます。

スクリーンショット 2019-09-03 12.51.36.png

下の画面のようにGUIDの右側にある、クリップボートアイコンをクリックすると、クリップボードにコピーされます。

スクリーンショット 2019-07-08 19.15.36.png

取得したGUIDを使って、今のように設定を行います。

$ ibmcloud ml set instance xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

実行

ここまでの準備ができれば、後はコマンドを実行するだけです。

$ ibmcmoud ml help

こんな結果がかえってくるはずです

名前:
   ibmcloud ml - Manage machine learning lifecycle on IBM Cloud
使用法:
   ibmcloud ml command [arguments...] [command options]

コマンド:
   cancel              Cancel training a model
   delete              Delete a model/deployment/training-run/training-definitions/experiments/experiment-runs/libraries/runtimes
   deploy              Deploy a model for scoring
   experiments         Run/Update an experiment stored in WML Repository
   generate-manifest   Generate a sample manifest for training-definitions/experiments/training-runs/update-experiments/batch/libraries/runtimes
   libraries           Download content from(to the present working directory)/Update a library stored in WML Repository
   list                List the models/deployments/training-runs/experiments/training-definitions/experiment-runs/libraries/runtimes
   models              Download model from(both metadata and content of the model to the present working directory) WML repository
   monitor             Start fetching status/metric messages of a training-run/experiment
   runtimes            Download content from(to the present working directory)/Update a runtime stored in WML Repository
   score               Score the model. Sample scoring json format -  {"modelId": "sample", "deploymentId": "sample","payload": {"fields": [],"values": []}}
   set                 Set ML instance 
   show                Get detailed information about models/deployments/training-runs/training-definitions/experiments/experiment-runs/libraries/runtimes
   store               Store a model/training-definition/experiment/training-runs/libraries/runtimes to WML repository
   train               Start training a model
   version             show git hash and build time of cli
   help, h             ヘルプを表示します

コマンドについて詳しくは、'ibmcloud ml help [command]' と入力してください。

コマンド例

(Training定義のうち、いらないものを消すための手順)

$ ibmcloud ml list training-definitions
Fetching the list of training-definitions ...
SI No   Name                        guid                                   framework    version   created-at   
1       Kidney-1                    6c017f34-3cef-4aa1-b5c2-deae7783b9ac   wml          1.1       2018-06-23T05:58:15.874Z   
2       simgle-cnn-on-mnist-v1      d41adc03-85a9-466c-8115-5e9ca3df0e95   tensorflow   1.5       2018-06-23T06:41:13.116Z   
3       simgle-cnn-on-mnist-v2      52a7ac4d-42ae-4d90-871c-5df178dec7e8   tensorflow   1.5       2018-06-23T08:04:18.637Z   
4       simgle-cnn-on-mnist-v3      679db41a-cf94-45a7-99c3-6e4127f94fee   tensorflow   1.5       2018-06-23T08:35:52.351Z   
5       cnn from nnd v4             5a6488d0-096b-4d90-86e9-11597fa9708d   tensorflow   1.5       2018-06-26T00:09:44.957Z   
6       cnn from kaggle epoch=200   734e226a-1338-4319-8ebe-8e1008073ae6   tensorflow   1.5       2018-06-26T00:30:18.238Z   
7       cnn from kaggle w adam      d9d0cac3-297a-4285-b5d7-16c556c1fbc1   tensorflow   1.5       2018-06-26T01:26:57.072Z   
8       aka zip                     306dfd8e-ed09-4e71-afd1-c106badef5d4   tensorflow   1.5       2018-06-26T02:18:01.358Z   
9       cnn-cifar10-kaggle          ec9379f5-5b1b-4530-a2db-4e67e1e4541d   tensorflow   1.5       2018-06-26T03:43:43.863Z   

9 records found.
OK
List all training-definitions successful

$ ibmcloud ml delete training-definitions 306dfd8e-ed09-4e71-afd1-c106badef5d4
Deleting the training-definition '306dfd8e-ed09-4e71-afd1-c106badef5d4' ...
OK
Delete training-definition successful

おまけ オブジェクト間の関係図

Experimentsから使っているとWatson Machine Learningのオブジェクト間の関係はとてもわかりにくいです。
自分の理解のため、こんな図を作ってみました。

スクリーンショット 2018-06-26 13.15.42.png

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1