From 329240227d1de92d6a7c46b6bb1bae92ad76482c Mon Sep 17 00:00:00 2001 From: s444417 Date: Sun, 15 May 2022 10:55:01 +0200 Subject: [PATCH] predict registry --- lab8/predictMlflow.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lab8/predictMlflow.py b/lab8/predictMlflow.py index fe17266..89dc687 100644 --- a/lab8/predictMlflow.py +++ b/lab8/predictMlflow.py @@ -1,15 +1,30 @@ +# import mlflow +# import numpy as np +# import json +# +# logged_model = '/mlruns/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model' +# +# # Load model as a PyFuncModel. +# loaded_model = mlflow.pyfunc.load_model(logged_model) +# +# with open(f'{loaded_model}/input_example.json') as f: +# input_example_data = json.load(f) +# +# # Predictions +# print(f'input: {input_example_data}') +# print(f'predictions: {loaded_model.predict(input_example_data)}') + import mlflow import numpy as np import json -logged_model = '/mlruns/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model' +registry_path = '/mlruns/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model' +model = mlflow.pyfunc.load_model(registry_path) -# Load model as a PyFuncModel. -loaded_model = mlflow.pyfunc.load_model(logged_model) - -with open(f'{loaded_model}/input_example.json') as f: +with open(f'{registry_path}/input_example.json') as f: input_example_data = json.load(f) - # Predictions - print(f'input: {input_example_data}') - print(f'predictions: {loaded_model.predict(input_example_data)}') \ No newline at end of file +input_example = np.array(input_example_data['inputs']).reshape(-1, 8) + +print(f'Input: {input_example}') +print(f'Prediction: {model.predict(input_example)}') \ No newline at end of file