mlflow predict own model.

This commit is contained in:
Jan Nowak 2021-05-23 17:33:43 +02:00
parent f30073b2ec
commit 8934d2a07e
3 changed files with 61 additions and 0 deletions

View File

@ -37,3 +37,5 @@ COPY ./train_mlflow.py ./
RUN chmod +x train_mlflow.py RUN chmod +x train_mlflow.py
COPY ./generate_MLmodel.py ./ COPY ./generate_MLmodel.py ./
RUN chmod +x generate_MLmodel.py RUN chmod +x generate_MLmodel.py
COPY ./mlflow_predict.py ./
RUN chmod +x mlflow_predict.py

42
Jenkinsfile_predict Normal file
View File

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

17
mlflow_predict.py Normal file
View File

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