ium_430705/lab_09_predict_coop.py

33 lines
910 B
Python
Raw Normal View History

import json
import mlflow
import pandas as pd
2021-05-27 14:50:41 +02:00
from pprint import pprint
from mlflow.tracking import MlflowClient
2021-05-29 12:20:21 +02:00
model_name = "s434804"
2021-05-29 12:20:52 +02:00
model_version = 12
2021-05-27 13:54:34 +02:00
mlflow.set_tracking_uri("http://172.17.0.1:5000")
2021-05-29 12:27:44 +02:00
model = mlflow.keras.pyfunc.load_model(
2021-05-29 12:25:57 +02:00
model_uri=f"models:/{model_name}/{model_version}",
)
2021-05-27 14:57:25 +02:00
"""
Honestly I have no clue how to get model's json input example
any other way, so just intialize MLFlow client, get latest
version of choosen model, and then get path to model's files
"""
2021-05-27 14:50:41 +02:00
client = MlflowClient()
2021-05-29 12:20:21 +02:00
models_version = client.search_model_versions("name='s434804'")
2021-05-27 14:59:20 +02:00
path_to_input = models_version[-1].source
2021-05-27 14:57:25 +02:00
with open(f'{path_to_input}/input_example.json', 'r') as datafile:
2021-05-27 14:38:58 +02:00
data = json.load(datafile)
example_input = data["inputs"]
2021-05-27 14:38:58 +02:00
input_dictionary = {i: x for i, x in enumerate(example_input)}
input_ex = pd.DataFrame(input_dictionary, index=[0])
print(model.predict(input_ex))