run prediction
This commit is contained in:
parent
1c2aea10ca
commit
458ef1af1f
38
Jenkinsfile_predict
Normal file
38
Jenkinsfile_predict
Normal file
@ -0,0 +1,38 @@
|
||||
pipeline {
|
||||
agent {
|
||||
docker { image 's444507_create_dataset_image:latest' }
|
||||
}
|
||||
parameters {
|
||||
buildSelector(
|
||||
defaultSelector: lastSuccessful(),
|
||||
description: 'Which build to use for copying artifacts for predict',
|
||||
name: 'BUILD_SELECTOR')
|
||||
string(
|
||||
defaultValue: '{\\"inputs\\": [[0.51, 0.86], [0.79, 0.79], [0.74, 0.77], [0.66, 0.73]]}',
|
||||
description: 'Input file',
|
||||
name: 'INPUT',
|
||||
trim: true
|
||||
)
|
||||
}
|
||||
stages {
|
||||
stage('Copy arifacts') {
|
||||
steps {
|
||||
copyArtifacts projectName: 's444356-training/master', selector: buildParameter('BUILD_SELECTOR')
|
||||
sh "echo ${params.INPUT} > input_example.json"
|
||||
}
|
||||
}
|
||||
stage('Run prediction on model') {
|
||||
steps {
|
||||
sh "python3 lab08_predict.py $epoch"
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success {
|
||||
archiveArtifacts artifacts: 'CarPrices_pytorch_model.pkl, mlruns/**, my_model/**', followSymlinks: false
|
||||
}
|
||||
always {
|
||||
emailext body: "${currentBuild.currentResult}", subject: 's444507-training', to: 'e19191c5.uam.onmicrosoft.com@emea.teams.ms'
|
||||
}
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ from sklearn import preprocessing
|
||||
import sys
|
||||
import logging
|
||||
import mlflow
|
||||
import mlflow.sklearn
|
||||
import mlflow.pytorch
|
||||
|
||||
logging.basicConfig(level=logging.WARN)
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -32,9 +32,9 @@ class Model(nn.Module):
|
||||
self.layer3 = nn.Linear(60, 5)
|
||||
|
||||
def forward(self, x):
|
||||
x = F.relu(self.layer1(x))
|
||||
x = F.relu(self.layer2(x))
|
||||
x = F.softmax(self.layer3(x)) # To check with the loss function
|
||||
x = F.relu(self.layer1(x.float()))
|
||||
x = F.relu(self.layer2(x.float()))
|
||||
x = F.softmax(self.layer3(x.float())) # To check with the loss function
|
||||
return x
|
||||
|
||||
|
||||
|
15
lab08_predict.py
Normal file
15
lab08_predict.py
Normal file
@ -0,0 +1,15 @@
|
||||
import mlflow
|
||||
import mlflow.sklearn
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import json
|
||||
|
||||
logged_model = 'mlruns/1/4b83e774512444188fb587288818c298/artifacts/model'
|
||||
model = mlflow.pyfunc.load_model(logged_model)
|
||||
|
||||
with open('my_model/input_example.json') as f:
|
||||
data = json.load(f)
|
||||
input_example = np.array([data['inputs'][0]]).reshape(-1,4)
|
||||
|
||||
print(f'Prediction: {model.predict(input_example)}')
|
||||
|
Loading…
Reference in New Issue
Block a user