示例#1
0
service.delete()

# ## DEPLOY FROM MODEL FILE
# First change score.py!

scorepy_content = "import json\nimport numpy as np\nimport os\nimport pickle\nfrom sklearn.externals import joblib\nfrom sklearn.linear_model import LogisticRegression\n\nfrom azureml.core.model import Model\n\ndef init():\n    global model\n    # retreive the path to the model file using the model name\n    model_path = Model.get_model_path('sklearn_mnist_model.pkl')\n    model = joblib.load(model_path)\n\ndef run(raw_data):\n    data = np.array(json.loads(raw_data)['data'])\n    # make prediction\n    y_hat = model.predict(data)\n    return json.dumps(y_hat.tolist())"
with open("score.py", "w") as f:
    f.write(scorepy_content)

# <option1Deploy>
from azureml.core.webservice import Webservice

service_name = 'aci-mnist-1'
service = Webservice.deploy(deployment_config=aciconfig,
                            image_config=image_config,
                            model_paths=['sklearn_mnist_model.pkl'],
                            name=service_name,
                            workspace=ws)

service.wait_for_deployment(show_output=True)
print(service.state)
# </option1Deploy>

# <testService>
# Load Data
import os
import urllib

os.makedirs('./data', exist_ok=True)

urllib.request.urlretrieve(
# Container image configuration
service_name = "summarization1"
runtime = "python"
driver_file = "summarizer_service1.py"
conda_file = "mydeployenv.yml"

from azureml.core.image import ContainerImage

image_config = ContainerImage.image_configuration(execution_script=driver_file,
                                                  runtime=runtime,
                                                  conda_file=conda_file)

# In[3]: Deploy service in container
deployedService = Webservice.deploy(workspace=ws,
                                    name=service_name,
                                    model_paths=[],
                                    image_config=image_config,
                                    deployment_config=aci_config)

deployedService.wait_for_deployment(show_output=True)

# In[4]: Test deployed service
uri = deployedService.scoring_uri

example_document = """On november 9th 1989, as the Berlin Wall tumbled, 
Hans-Joachim Binder was on night shift at the potash mine in Bischofferode, 
a village in the communist-ruled German Democratic Republic. 
Mr Binder, a maintenance worker who had toiled in the mine for 17 years, had no idea of the momentous events unfolding 240km (150 miles) to the east. 
The first sign something was up was when most of his colleagues disappeared to investigate what was happening at the border with West Germany, 
just ten minutes drive away. Only three returned to complete their shift. Less than a year later Germany was reunited, 
capping one of the most extraordinary stories in modern history. 
示例#3
0
root_run.upload_file(name="outputs/mse_over_alpha.png",
                     path_or_stream="mse_over_alpha.png")

aciconfig = AciWebservice.deploy_configuration(cpu_cores=1,
                                               memory_gb=1,
                                               tags=['e2e-01'],
                                               description='e2e test 01')

print('deploying to ACI...')
from azureml.core.webservice import Webservice

service = Webservice.deploy(name=web_service_name,
                            workspace=ws,
                            deployment_config=aciconfig,
                            model_paths=['best_model.pkl'],
                            runtime='python',
                            conda_file='myenv.yml',
                            execution_script='score.py')

service.wait_for_deployment(show_output=True)

test_sample = json.dumps({'data': X_test[0:10, :].tolist()})
test_sample = bytes(test_sample, encoding='utf8')

# test result
print('test the web service.')
print(service.run(input_data=test_sample))

# claan up
print('delete ACI')