-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
46 lines (35 loc) · 1.48 KB
/
deploy.py
File metadata and controls
46 lines (35 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from watson_machine_learning_client import WatsonMachineLearningAPIClient
from contextlib import suppress
import os
import pickle
wml_credentials={
"url": "xxxxxxxxxxxxxxxxxx",
"apikey": "xxxxxxxxxxxxxxxxxxxxxxx",
"username": "xxxxxxxxxxxxxxxxxxxx",
"password": "xxxxxxxxxxxxxxxxxxxxxxx",
"instance_id": "xxxxxxxxxxxxxxxxxxxxxx"
}
client = WatsonMachineLearningAPIClient(wml_credentials)
#compressing model
filename = 'weights/model.h5'
tar_filename = 'weights/model' + '.tgz'
cmdstring = 'tar -zcvf ' + tar_filename + ' ' + filename
os.system(cmdstring)
# defining model specifications for IBM support
model_props = {
client.repository.ModelMetaNames.NAME: 'Speech - compressed keras model',
client.repository.ModelMetaNames.FRAMEWORK_NAME: 'tensorflow',
client.repository.ModelMetaNames.FRAMEWORK_VERSION: '1.15',
client.repository.ModelMetaNames.RUNTIME_NAME: 'python',
client.repository.ModelMetaNames.RUNTIME_VERSION: '3.6',
client.repository.ModelMetaNames.FRAMEWORK_LIBRARIES: [{'name':'keras', 'version': '2.2.5'}]
}
published_model_details = client.repository.store_model(model='model.tgz', meta_props=model_props)
model_uid = client.repository.get_model_uid(published_model_details)
print(model_uid)
# Main deployment used for prediction
deployment = client.deployments.create(model_uid, 'Keras Speech recognition through compressed file.')
# required variable for prediction
dp = open("variables/deployment.pkl", 'wb')
pickle.dump(dp, deployment)
dp.close()