MLFlow other models inference init

This commit is contained in:
MatOgr 2022-05-15 12:33:21 +02:00
parent 8ca9b73537
commit b608875348
4 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,34 @@
pipeline {
agent {
docker {
image 's478841-image:latest'
}
}
parameters {
string(
defaultValue: '{\\"inputs\\": [[0.76, 0.71], [0.6, 0.73], [0.75, 0.75], [0.91, 0.85]]}',
description: 'Input data',
name: 'INPUT',
trim: true
)
buildSelector(
defaultSelector: lastSuccessful(),
description: 'Build used for artifacts copying',
name: 'BUILD_SELECTOR'
)
}
stages {
stage('Load artifacts') {
steps {
copyArtifacts projectName: 's444356-training/master', selector: buildParameter('BUILD_SELECTOR')
}
}
stage('Predict using artifact') {
steps {
sh "echo ${params.INPUT} > scripts/input_example.json"
sh 'python3 scripts/predict_s444356.py'
}
}
}
}

View File

@ -0,0 +1,16 @@
pipeline {
agent {
docker {
image 's478841-image:latest'
args '-v /mlruns:/mlruns'
}
}
stages {
stage('Predict using artifacts') {
steps {
sh 'python3 scripts/predict_s444356_registry.py'
}
}
}
}

View File

@ -0,0 +1,10 @@
import mlflow
import numpy as np
import json
model = mlflow.pyfunc.load_model(
'mlruns/13/da5c6167bb45403fa35569849a1fbc13/artifacts/model')
with open('input_example.json') as f:
data = np.array([json.load(f)['inputs'][0]], dtype=np.float32)
print(f"Predicted values: {model.predict(data.reshape(-1, 2))}")

View File

@ -0,0 +1,10 @@
import mlflow
import numpy as np
import json
model = mlflow.pyfunc.load_model(
'mlruns/13/da5c6167bb45403fa35569849a1fbc13/artifacts/model')
with open('mlruns/13/da5c6167bb45403fa35569849a1fbc13/artifacts/model/input_example.json') as f:
data = np.array([json.load(f)['inputs'][0]], dtype=np.float32)
print(f"Predicted values: {model.predict(data.reshape(-1, 2))}")