Predict registry own model.

This commit is contained in:
Jan Nowak 2021-05-23 19:01:11 +02:00
parent 8934d2a07e
commit 5f572f039b
4 changed files with 52 additions and 5 deletions

3
.gitignore vendored
View File

@ -7,4 +7,5 @@ plot.png
my_runs
mlruns
my_model
1/
1/
mydb.sqlite

View File

@ -1,9 +1,5 @@
pipeline {
agent any
// triggers {
// upstream(upstreamProjects: "s426206-train/master",
// threshold: hudson.model.Result.SUCCESS)
// }
parameters {
buildSelector(
defaultSelector: lastSuccessful(),

View File

@ -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'
}
}
}
}
}
}

View File

@ -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()))