Scripts to export Machine Learning models
You can use one of these scripts to export models.
You can use a script as an alternative to run the process to export a model from Machine Learning.
Linux® get model
Package the following script into a .sh file as linuxgetmodel.sh.
authUrl=https://iam.cloud.ibm.com/identity/token
apiKey=2TGak8Gti_pVRNABC39M_GDL1CoYdZBlvvOTPFsOkcK7
endpointUrl=https://us-south.ml.cloud.ibm.com/ml/v4
deploymentId=40d8211b-47bd-48d1-8b68-3g042474ff91
version=2021-05-01
spaceId=083908d3-6c43-4e67-868d-942b038a6a86
echo _
echo Obtain a security token
curl -s --insecure -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Accept: application/json" --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" --data-urlencode "apikey=$apiKey" "$authUrl" -o tokenResponse.txt
tkn=`grep "token" tokenResponse.txt | head -1 |cut -d \" -f4`
echo token=$tkn
echo _
echo Fetch the artifacts assetid
curl -s -H "Authorization: Bearer $tkn" "$endpointUrl/deployments/$deploymentId?space_id=$spaceId&version=$version" -o assetID.txt
assetid=`grep "id" assetID.txt |head -1 |cut -d \" -f4`
echo assetid=$assetid
echo _
echo Fetch the ML datamodel
curl -s -H "Authorization: Bearer $tkn" "$endpointUrl/models/$assetid?space_id=$spaceId&version=$version" -o model.jsonecho done.
echo _
Windows get model
Package the following script into a .bat files as getmodel.bat.
@echo off
set authUrl=https://iam.cloud.ibm.com/identity/token
set apiKey=2TGak8Gti_pVRNABC39M_GDL1CoYdZBlvvOTPFsOkcK7
set endpointUrl=https://us-south.ml.cloud.ibm.com/ml/v4
set deploymentId=40d8211b-47bd-48d1-8b68-3g042474ff91
set version=2021-05-01
set spaceId=083908d3-6c43-4e67-868d-942b038a6a86
echo _
echo Obtain a security token
curl -s --insecure -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Accept: application/json" --data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" --data-urlencode "apikey=%apiKey%" "%authUrl%" -o tokenResponse.txt
FOR /F delims^=^"^ tokens^=4 %%G IN ('FINDSTR /L "token\"\:\"" "tokenresponse.txt"') DO @set tkn=%%G
echo Token=%tkn%
echo _
echo Fetch the artifacts assetid
curl -s -H "Authorization: Bearer %tkn%" "%endpointUrl%/deployments/%deploymentId%?space_id=%spaceId%&version=%version%" -o assetID.txt
rem extract the asset id from the artifacts data
set assetid=
FOR /F delims^=^"^ tokens^=4 %%G IN ('FINDSTR /L "\"id\"" "assetID.txt"') DO @(if NOT defined assetid (set assetid=%%G))
echo assetid=%assetid%
echo _
echo Fetch the ML datamodel
curl -s -H "Authorization: Bearer %tkn%" "%endpointUrl%/models/%assetid%?space_id=%spaceId%&version=%version%" -o model.json
echo done.
echo _
pause