predict artifact
All checks were successful
s444417-training/pipeline/head This commit looks good
s444417-evaluation/pipeline/head This commit looks good

This commit is contained in:
s444417 2022-05-15 12:45:33 +02:00
parent f5175a9517
commit a08f50d333
5 changed files with 55 additions and 20 deletions

View File

@ -22,3 +22,15 @@ Zadanie 2
6. copyArtifacts z s444417-create-dataset
7. parametr BRANCH do wyboru konkretnej gałęzi, buildselector do wybrania builda w Jenkins.eval
8. powiadomenie mail wraz z metryką loss wysyłane w pliku Jenkinsfile.eval post emailext
IUM_8 opis sposobu rozwiązania zadań i podpunktów
---
Zadanie 1
1. lab8/trainScript.py log_param: epoch i learning_rate i log_metric final_loss
2. lab8/MLproject
Zadanie 2
1. na końcu pliku lab8/trainScript.py, zawiera input_example, MLproject docker_env
2.
3. zarejestronwany model np. http://tzietkiewicz.vm.wmi.amu.edu.pl/#/experiments/17/runs/811420769d2642b8be694693c75b3587/artifactPath/linear-model, model rejestruje w pliku lab8/trainScript.py
4. [projekt](https://tzietkiewicz.vm.wmi.amu.edu.pl:8080/job/s444417-predict-s449288-from-registry/) realizuje predykcje skryptem lab8/predictMlflow.py i printuje ją w consoli builda,

23
lab8/Jenkinsfile.artifact Normal file
View File

@ -0,0 +1,23 @@
pipeline {
agent {
dockerfile {
args '-v /mlruns:/mlruns'
}
}
parameters {
buildSelector(
defaultSelector: lastSuccessful(),
description: 'Which build to use for copying artifacts',
name: 'BUILD_SELECTOR'
)
}
stages {
stage('Stage') {
steps {
copyArtifacts filter: 'mlruns.tar.gz', projectName: 's449288-training/master', selector: buildParameter('BUILD_SELECTOR')
sh 'mkdir -p mlrunsArtifact && tar xzf mlruns.tar.gz -C mlrunsArtifact --strip-components 1'
sh "python lab8/predictArtifact.py"
}
}
}
}

View File

@ -11,3 +11,5 @@ entry_points:
epochs: {type: float, default: 3}
learning_rate: {type: float, default: 0.1}
command: "python ./lab8/trainScript.py {epochs} {learning_rate}"
test:
command: "python ./src/evalScript.py"

14
lab8/predictArtifact.py Normal file
View File

@ -0,0 +1,14 @@
import mlflow
import numpy as np
import json
logged_model = 'mlrunsArtifact/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model'
loaded_model = mlflow.pyfunc.load_model(logged_model)
with open(f'{logged_model}/input_example.json') as f:
input_example_data = json.load(f)
input_example = np.array(input_example_data['inputs']).reshape(-1,)
print(f'Input: {input_example}')
print(f'Prediction: {loaded_model.predict(input_example)}')

View File

@ -1,30 +1,14 @@
# import mlflow
# import numpy as np
# import json
#
# logged_model = '/mlruns/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model'
#
# # Load model as a PyFuncModel.
# loaded_model = mlflow.pyfunc.load_model(logged_model)
#
# with open(f'{loaded_model}/input_example.json') as f:
# input_example_data = json.load(f)
#
# # Predictions
# print(f'input: {input_example_data}')
# print(f'predictions: {loaded_model.predict(input_example_data)}')
import mlflow
import numpy as np
import json
registry_path = '/mlruns/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model'
model = mlflow.pyfunc.load_model(registry_path)
logged_model = '/mlruns/14/80fe21a0804844088147d15a3cebb3e5/artifacts/lego-model'
loaded_model = mlflow.pyfunc.load_model(logged_model)
with open(f'{registry_path}/input_example.json') as f:
with open(f'{logged_model}/input_example.json') as f:
input_example_data = json.load(f)
input_example = np.array(input_example_data['inputs']).reshape(-1,)
print(f'Input: {input_example}')
print(f'Prediction: {model.predict(input_example)}')
print(f'Prediction: {loaded_model.predict(input_example)}')