From 8934d2a07e51c5d3217c6e2ac994ec1d88dce746 Mon Sep 17 00:00:00 2001 From: Jan Nowak Date: Sun, 23 May 2021 17:33:43 +0200 Subject: [PATCH] mlflow predict own model. --- Dockerfile | 2 ++ Jenkinsfile_predict | 42 ++++++++++++++++++++++++++++++++++++++++++ mlflow_predict.py | 17 +++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 Jenkinsfile_predict create mode 100644 mlflow_predict.py diff --git a/Dockerfile b/Dockerfile index e153154..0433de2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,3 +37,5 @@ COPY ./train_mlflow.py ./ RUN chmod +x train_mlflow.py COPY ./generate_MLmodel.py ./ RUN chmod +x generate_MLmodel.py +COPY ./mlflow_predict.py ./ +RUN chmod +x mlflow_predict.py diff --git a/Jenkinsfile_predict b/Jenkinsfile_predict new file mode 100644 index 0000000..66bcb77 --- /dev/null +++ b/Jenkinsfile_predict @@ -0,0 +1,42 @@ +pipeline { + agent any +// triggers { +// upstream(upstreamProjects: "s426206-train/master", +// threshold: hudson.model.Result.SUCCESS) +// } + parameters { + buildSelector( + defaultSelector: lastSuccessful(), + description: 'Which build to use for copying artifacts for predict', + name: 'BUILD_SELECTOR_PREDICT') + string( + defaultValue: 'input_example.json', + description: 'Input name', + name: 'INPUT', + trim: false + ) + } + stages { + stage('checkout') { + steps { + checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://git.wmi.amu.edu.pl/s426206/ium_426206.git']]]) + } + } + stage('Copy artifact') { + steps { + copyArtifacts filter: 'my_model/**/*', fingerprintArtifacts: false, projectName: 's426206-training/master', selector: buildParameter('BUILD_SELECTOR_PREDICT') + } + } + stage('docker') { + steps { + script { + def img = docker.build('rokoch/ium:01') + img.inside { + sh 'chmod +x mlflow_predict.py' + sh 'python3 ./mlflow_predict.py $INPUT' + } + } + } + } + } +} diff --git a/mlflow_predict.py b/mlflow_predict.py new file mode 100644 index 0000000..3f290b4 --- /dev/null +++ b/mlflow_predict.py @@ -0,0 +1,17 @@ +import mlflow +import mlflow.pytorch +import sys +import json +import numpy as np +import torch + +input = sys.argv[1] + +model = mlflow.pytorch.load_model("my_model") + +with open('my_model/'+input) as json_file: + data = json.load(json_file) +#print(np.array(data['inputs'])) +print(model(torch.tensor(np.array(data['inputs'])).float())) + + \ No newline at end of file