From 5f572f039b3d8080771dfd174c2ba85866155a99 Mon Sep 17 00:00:00 2001 From: Jan Nowak Date: Sun, 23 May 2021 19:01:11 +0200 Subject: [PATCH] Predict registry own model. --- .gitignore | 3 ++- Jenkinsfile_predict | 4 ---- Jenkinsfile_predict_registry | 26 ++++++++++++++++++++++++++ mlflow_predict_registry.py | 24 ++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 Jenkinsfile_predict_registry create mode 100644 mlflow_predict_registry.py diff --git a/.gitignore b/.gitignore index b7733bd..1d21078 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ plot.png my_runs mlruns my_model -1/ \ No newline at end of file +1/ +mydb.sqlite \ No newline at end of file diff --git a/Jenkinsfile_predict b/Jenkinsfile_predict index 66bcb77..8618163 100644 --- a/Jenkinsfile_predict +++ b/Jenkinsfile_predict @@ -1,9 +1,5 @@ pipeline { agent any -// triggers { -// upstream(upstreamProjects: "s426206-train/master", -// threshold: hudson.model.Result.SUCCESS) -// } parameters { buildSelector( defaultSelector: lastSuccessful(), diff --git a/Jenkinsfile_predict_registry b/Jenkinsfile_predict_registry new file mode 100644 index 0000000..d81bb91 --- /dev/null +++ b/Jenkinsfile_predict_registry @@ -0,0 +1,26 @@ +pipeline { + agent any + 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/input_example.json', 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_registry.py' + sh 'python3 ./mlflow_predict_registry.py' + } + } + } + } + } +} diff --git a/mlflow_predict_registry.py b/mlflow_predict_registry.py new file mode 100644 index 0000000..47339a5 --- /dev/null +++ b/mlflow_predict_registry.py @@ -0,0 +1,24 @@ +import mlflow +import mlflow.pytorch +from mlflow.tracking import MlflowClient +import numpy as np +import torch +import json + +#mlflow.set_tracking_uri("http://127.0.0.1:5000") +mlflow.set_tracking_uri("http://172.17.0.1:5000") +client = MlflowClient() +version = 0 +model_name = "s426206" +for mv in client.search_model_versions("name='s426206'"): + if int(mv.version) > version: + version = int(mv.version) + +model = mlflow.pytorch.load_model( + model_uri=f"models:/{model_name}/{version}" +) + +with open('my_model/input_example.json') 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