From 0559fd603882e80ea73764d532e1805c6f01ed0f Mon Sep 17 00:00:00 2001 From: Kacper Date: Sat, 14 May 2022 13:03:16 +0200 Subject: [PATCH] working on lab8 --- lab8/Jenkinsfile_predict_artifact | 32 +++++++++++++++++++++++++++++++ lab8/Jenkinsfile_predict_registry | 17 ++++++++++++++++ lab8/predict_artifact.py | 17 ++++++++++++++++ lab8/predict_registry.py | 14 ++++++++++++++ predict_artifact.py | 17 ++++++++++++++++ predict_registry.py | 14 ++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 lab8/Jenkinsfile_predict_artifact create mode 100644 lab8/Jenkinsfile_predict_registry create mode 100644 lab8/predict_artifact.py create mode 100644 lab8/predict_registry.py create mode 100644 predict_artifact.py create mode 100644 predict_registry.py diff --git a/lab8/Jenkinsfile_predict_artifact b/lab8/Jenkinsfile_predict_artifact new file mode 100644 index 0000000..52d9e0c --- /dev/null +++ b/lab8/Jenkinsfile_predict_artifact @@ -0,0 +1,32 @@ +pipeline { + agent { + docker { + image 's449288/ium:lab8.1' + } + } + parameters { + string( + defaultValue: '{\\"inputs\\": [[]]}', + description: 'Input example in json format', + name: 'INPUT' + ) + buildSelector( + defaultSelector: lastSuccessful(), + description: 'Which build to use for copying artifacts', + name: 'BUILD_SELECTOR' + ) + } + stages { + stage('Stage 1') { + steps { + echo 'Copying model from s444417-training...' + copyArtifacts projectName: 's444417-training/master', selector: buildParameter('BUILD_SELECTOR') + echo 'Model copied' + echo 'Making a prediction...' + sh 'echo ${params.INPUT} > input_example.json' + sh 'python3 predict_s444356.py' + echo 'Prediction made' + } + } + } +} diff --git a/lab8/Jenkinsfile_predict_registry b/lab8/Jenkinsfile_predict_registry new file mode 100644 index 0000000..4746ce5 --- /dev/null +++ b/lab8/Jenkinsfile_predict_registry @@ -0,0 +1,17 @@ +pipeline { + agent { + docker { + image 's449288/ium:lab8.1' + args '-v /mlruns:/mlruns' + } + } + stages { + stage('Stage 1') { + steps { + echo 'Making a prediction with a model from experiment s444417...' + sh "python3 predict_registry.py" + echo 'Prediction made' + } + } + } +} diff --git a/lab8/predict_artifact.py b/lab8/predict_artifact.py new file mode 100644 index 0000000..d33f133 --- /dev/null +++ b/lab8/predict_artifact.py @@ -0,0 +1,17 @@ +import mlflow +import numpy as np +import json + +artifact_path = 'mlruns/1//artifacts/model' # +model = mlflow.pyfunc.load_model(artifact_path) # + +with open(f'{model}/input_example.json') as f: + input_example_data = json.load(f) + +input_example = np.array() # + +print(f'Input example: {input_example}') +print(f'Model prediction: {model.predict(input_example)}') + + + diff --git a/lab8/predict_registry.py b/lab8/predict_registry.py new file mode 100644 index 0000000..28561df --- /dev/null +++ b/lab8/predict_registry.py @@ -0,0 +1,14 @@ +import mlflow +import numpy as np +import json + +regsistry_path = '/mlruns/17/ /artifacts/model' # +model = mlflow.pyfunc.load_model(registry_path) # + +with open(f'{model}/input_example.json') as f: + input_example_data = json.load(f) + +input_example = np.array() # + +print(f'Input example: {input_example}') +print(f'Model prediction: {model.predict(input_example)}') diff --git a/predict_artifact.py b/predict_artifact.py new file mode 100644 index 0000000..d33f133 --- /dev/null +++ b/predict_artifact.py @@ -0,0 +1,17 @@ +import mlflow +import numpy as np +import json + +artifact_path = 'mlruns/1//artifacts/model' # +model = mlflow.pyfunc.load_model(artifact_path) # + +with open(f'{model}/input_example.json') as f: + input_example_data = json.load(f) + +input_example = np.array() # + +print(f'Input example: {input_example}') +print(f'Model prediction: {model.predict(input_example)}') + + + diff --git a/predict_registry.py b/predict_registry.py new file mode 100644 index 0000000..28561df --- /dev/null +++ b/predict_registry.py @@ -0,0 +1,14 @@ +import mlflow +import numpy as np +import json + +regsistry_path = '/mlruns/17/ /artifacts/model' # +model = mlflow.pyfunc.load_model(registry_path) # + +with open(f'{model}/input_example.json') as f: + input_example_data = json.load(f) + +input_example = np.array() # + +print(f'Input example: {input_example}') +print(f'Model prediction: {model.predict(input_example)}')