Exemplo n.º 1
0
def process_event(event):
    if 'runId' not in event:
        raise ValueError('Malformed Event. Run Id does not exits. Event: %s',
                         event)

    logger.info(f'Event Details: {event}')

    exp = Experiment(workspace=get_workspace(), name=event['experimentName'])
    run = Run(exp, event['runId'])
    run_details = run.get_details()
    app_insight_connection = os.environ.get('APPINSIGHTS_CONNECTION_STRING')

    if 'endTimeUtc' in run_details:
        logger.info(f'Run details: {run_details}')
        """
        Just for sample here we are saving metrics to Application Insight after collecting details from 'run_details'
        & 'event'. You can store it to any other storage/database as well.
        """
        save_to_app_insight(to_run_metrics(run_details, event),
                            app_insight_connection)
    else:
        logging.info(
            'Ignoring event. As step/pipeline is still running. Event: %s',
            event)
Exemplo n.º 2
0
deploy_model = PythonScriptStep(script_name="src/deploy_model.py",
                                compute_target=compute_target,
                                runconfig=aml_run_config)

steps = [train_model, deploy_model]
step_seq = StepSequence(steps=steps)
pipeline = Pipeline(workspace=ws, steps=step_seq)

pp = pipeline.publish(
    name="TitanicDeploymentPipeline",
    description="Training and deployment pipeline for our titanic API.",
    version="1.0")

# We can also set up a trigger based schedule using the Datastore class - https://docs.microsoft.com/en-us/azure/machine-learning/how-to-schedule-pipelines#create-a-time-based-schedule
recurrence = ScheduleRecurrence(frequency="Month",
                                interval=1,
                                start_time='2020-11-01T00:00:00')
recurring_schedule = Schedule.create(ws,
                                     name="TitanicRetrainingSchedule",
                                     description="Once a month training",
                                     pipeline_id=pp.id,
                                     experiment_name=exp_name,
                                     recurrence=recurrence)

run = pp.submit(ws, experiment_name=exp_name)

run_id = run.id
exp = Experiment(ws, exp_name)
r = Run(exp, run_id)
r.get_details()
Exemplo n.º 3
0
    model_name = "model_n_estimators_" + str(n) + ".pkl"
    filename = "outputs/" + model_name

    joblib.dump(value=model, filename=filename)
    run.upload_file(name=model_name, path_or_stream=filename)
    run.complete()

    ###############

maximum_acc_runid = None
maximum_acc = None

for run in experiment.get_runs():
    run_metrics = run.get_metrics()
    run_details = run.get_details()
    # each logged metric becomes a key in this returned dict
    run_acc = run_metrics["acc"]
    run_id = run_details["runId"]

    if maximum_acc is None:
        maximum_acc = run_acc
        maximum_acc_runid = run_id
    else:
        if run_acc > maximum_acc:
            maximum_acc = run_acc
            maximum_acc_runid = run_id

print("Best run_id: " + maximum_acc_runid)
print("Best run_id acc: " + str(maximum_acc))
"""
Helper to get run details for debugging
"""
import os
from azureml.core import Workspace, Experiment, Run
from azureml.core.authentication import AzureCliAuthentication


# load workspace
ws = Workspace.from_config(
    auth=AzureCliAuthentication(),
    path=os.path.join(
        os.path.dirname(os.path.realpath(__file__)),
        'config.json'
    )
)
experiment = Experiment(
    workspace=ws,
    name="multitask_ssd"
)

run = Run(
    experiment,
    run_id="a9858223-b3b7-4272-98a4-33bfee9f67e9"
)

print(run.get_details())

# print(run.get_metrics())