From 39acc4bd2791a351d8fbbe6cc579a3c9c2e5ca08 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Wed, 11 May 2022 18:19:02 +0200 Subject: [PATCH] Add scripts to use someones model --- Jenkinsfile-predict-s444356 | 20 ++++++++++++++++++++ predict_s444356.py | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 Jenkinsfile-predict-s444356 create mode 100644 predict_s444356.py diff --git a/Jenkinsfile-predict-s444356 b/Jenkinsfile-predict-s444356 new file mode 100644 index 0000000..f97dc69 --- /dev/null +++ b/Jenkinsfile-predict-s444356 @@ -0,0 +1,20 @@ +pipeline { + agent { + docker { + image 's444409-create-dataset' + } + } + + stages { + stage('Get dataset from artifact') { + steps { + copyArtifacts projectName: 's444356-training/master', selector: lastSuccessful() + } + } + stage('Predict values using model from artifact') { + steps { + sh "python predict_s444356.py" + } + } + } +} diff --git a/predict_s444356.py b/predict_s444356.py new file mode 100644 index 0000000..6060158 --- /dev/null +++ b/predict_s444356.py @@ -0,0 +1,16 @@ +import json +import mlflow +import numpy as np +import torch +from torch.autograd import Variable + +logged_model = 'mlruns/1/d5b6f9c1784a4d2dbb8592cd4ad364d7/artifacts/model' +loaded_model = mlflow.pyfunc.load_model(logged_model) + + +with open(f'{logged_model}/input_example.json') as f: + data = json.load(f) + input_example = np.array(data['inputs'][0]) + input_example = Variable(torch.from_numpy(input_example)).float() + +loaded_model.predict(input_example)