Add mlflow prediction
Some checks failed
s434704-predict-s426206/pipeline/head There was a failure building this commit

This commit is contained in:
Wojciech Jarmosz 2021-05-23 16:21:50 +02:00
parent c96da734b1
commit d701d365ec
2 changed files with 32 additions and 2 deletions

View File

@ -6,12 +6,24 @@ pipeline {
description: 'Last successfull artifact',
name: 'BUILD_SELECTOR'
)
string(
defaultValue: 'input_example.json',
description: 'Input name',
name: 'INPUT_NAME',
trim: false
)
}
stages {
stage('copyArtifacts') {
stage('Copy model artifacts from s426206') {
steps {
copyArtifacts fingerprintArtifacts: true, projectName: 's434705-training/master', selector: buildParameter('BUILD_SELECTOR')
copyArtifacts fingerprintArtifacts: true, projectName: 's426206-training/master', selector: buildParameter('BUILD_SELECTOR')
}
}
stage('Run prediction') {
steps {
sh 'python3 mlflow_prediction.py $INPUT_NAME'
}
}
}
}

18
mlflow_prediction.py Normal file
View File

@ -0,0 +1,18 @@
import json
import mlflow
import pandas as pd
import sys
arguments = sys.argv[1:]
input = str(arguments[0])
model = mlflow.keras.load_model("my_model")
with open('my_model/{input}', 'r') as file:
json_data = json.load(file)['inputs']
data_into_dict = {idx:x for idx, x in enumerate(json_data)}
print(model.predict(pd.DataFrame([data_into_dict])))