ium_434804/pred_from_mlflow_model.py

23 lines
638 B
Python
Raw Normal View History

2021-05-23 18:50:55 +02:00
import json
import mlflow as mlf
2021-05-28 21:48:35 +02:00
from mlflow.tracking import MlflowClient
2021-05-23 18:50:55 +02:00
import pandas as pd
2021-05-23 18:58:52 +02:00
model_name = "s430705"
2021-05-28 21:48:35 +02:00
model_version = 30
2021-05-23 19:07:22 +02:00
mlf.set_tracking_uri("http://172.17.0.1:5000")
2021-05-23 19:51:26 +02:00
model = mlf.pyfunc.load_model(
2021-05-23 18:50:55 +02:00
model_uri=f"models:/{model_name}/{model_version}"
)
2021-05-28 21:48:35 +02:00
client = MlflowClient()
models_version = client.search_model_versions("name='s430705'")
input_path = models_version[-1].source
with open(f'{input_path}/input_example.json', 'r') as datafile:
2021-05-23 18:50:55 +02:00
data = json.load(datafile)['inputs']
input_dictionary = {idx:x for idx, x in enumerate(data)}
input_ex = pd.DataFrame([input_dictionary])
print(model.predict(input_ex))