From 64e1ead5c5b717aec57e52112ec9622eef2ef4a5 Mon Sep 17 00:00:00 2001 From: s430705 Date: Thu, 13 May 2021 10:48:52 +0200 Subject: [PATCH] Add plot for evaluation, add parameters to jenkins and fix mail sending --- Jenkinsfile_evaluation | 45 +++++++++++++++++++++++++++++------------- Jenkinsfile_training | 4 +++- lab06-eval.py | 26 ++++++++++++------------ lab06-plot.py | 6 ++++++ lab08_mfl.py | 2 +- requirements.txt | 3 ++- 6 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 lab06-plot.py diff --git a/Jenkinsfile_evaluation b/Jenkinsfile_evaluation index 95ae4ad..fb7ccf9 100644 --- a/Jenkinsfile_evaluation +++ b/Jenkinsfile_evaluation @@ -7,23 +7,32 @@ pipeline { defaultSelector: lastSuccessful(), description: 'Which build to use for copying artifacts', name: 'WHICH_BUILD_DATA' - ) - buildSelector( + ) + buildSelector( defaultSelector: lastSuccessful(), description: 'Which build to use for copying artifacts', name: 'WHICH_BUILD_TRAIN' - ) - } + ) + buildSelector( + defaultSelector: lastSuccessful(), + description: 'Which build to use for copying artifacts', + name: 'WHICH_BUILD_EVAL' + ) + gitParameter branchFilter: 'origin/(.*)', defaultValue: 'master', name: 'BRANCH', type: 'PT_BRANCH' + } + stages { - stage('checkout') { + stage('copyArtifacts') { steps { copyArtifacts fingerprintArtifacts: true, projectName: 's430705-create-dataset', selector: buildParameter('WHICH_BUILD_DATA') + copyArtifacts fingerprintArtifacts: true, projectName: 's430705-training/master', selector: buildParameter('WHICH_BUILD_TRAIN') + copyArtifacts optional: true, fingerprintArtifacts: true, projectName: 's430705-evaluation/master', selector: buildParameter('WHICH_BUILD_EVAL') } } - stage('Docker'){ + stage('Evaluation){ steps{ - copyArtifacts fingerprintArtifacts: true, projectName: 's430705-training/master', selector: buildParameter('WHICH_BUILD_TRAIN') - sh 'python3 "./lab06-eval.py" >> eval.txt' + sh 'python3 "./lab06-eval.py ${WHICH_BUILD_TRAIN}"' + sh 'python3 "./lab06-plot.py"' sh 'python3 "./lab07_sacred01.py"' sh 'python3 "./lab07_sacred02.py"' } @@ -32,14 +41,22 @@ pipeline { steps { archiveArtifacts 'eval.txt' archiveArtifacts 'lab07/**' + archiveArtifacts 'evaluation_plot.png' } } - stage('sendMail') { - steps{ - emailext body: currentBuild.result ?: 'SUCCESS EVALUATION', - subject: 's430705 evaluation', - to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms' - } + } + post { + success { + mail body: 'SUCCESS', subject: 's430705', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms' + } + unstable { + mail body: 'UNSTABLE', subject: 's430705', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms' + } + failure { + mail body: 'FAILURE', subject: 's430705', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms' + } + changed { + mail body: 'CHANGED', subject: 's430705', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms' } } } \ No newline at end of file diff --git a/Jenkinsfile_training b/Jenkinsfile_training index 38e69c0..6c396c5 100644 --- a/Jenkinsfile_training +++ b/Jenkinsfile_training @@ -16,7 +16,7 @@ pipeline { stage('copyArtifacts') { steps { copyArtifacts fingerprintArtifacts: true, projectName: 's430705-create-dataset', selector: buildParameter('BUILD_SELECTOR') - sh 'python3 lab06_training.py $epochs' + sh 'python3 lab06_training.py ${epochs}' } } @@ -29,6 +29,8 @@ pipeline { post { success { + + build job: 's430705-training/evaluation', parameters: ] mail body: 'SUCCESS', subject: 's430705', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms' diff --git a/lab06-eval.py b/lab06-eval.py index 5931f2f..08ad69a 100644 --- a/lab06-eval.py +++ b/lab06-eval.py @@ -1,22 +1,22 @@ -from tensorflow.keras.models import Sequential -from tensorflow.keras.layers import Dense -from tensorflow.keras.optimizers import Adam -from tensorflow.keras.layers import Dropout -from tensorflow.keras.callbacks import EarlyStopping -from sklearn.metrics import mean_squared_error, mean_absolute_error, accuracy_score -from tensorflow.keras.models import load_model -import pandas as pd +import sys -test_df = pd.read_csv('test.csv') +import pandas as pd +from sklearn.metrics import mean_squared_error +from tensorflow.keras.models import load_model + +test_df = pd.read_csv("test.csv") test_df.drop(test_df.columns[0], axis=1, inplace=True) x_test = test_df.drop("rating", axis=1) y_test = test_df["rating"] -model = Sequential() -model = load_model('model_movies') - +model = load_model("model_movies") y_pred = model.predict(x_test.values) rmse = mean_squared_error(y_test, y_pred) +build_number = sys.argv[1] if len(sys.argv) > 1 else 0 -print(f"RMSE: {rmse}") +d = {"rmse": [rmse], "build": [build_number]} +df = pd.DataFrame(data=d) + +with open("evaluation.csv", "a") as f: + df.to_csv(f, header=f.tell() == 0, index=False) diff --git a/lab06-plot.py b/lab06-plot.py new file mode 100644 index 0000000..8562c80 --- /dev/null +++ b/lab06-plot.py @@ -0,0 +1,6 @@ +import pandas as pd +import matplotlib.pyplot as plt + +df = pd.read_csv("evaluation.csv") +df.plot(x="build", y="rmse") +plt.savefig("evaluation_plot.png") \ No newline at end of file diff --git a/lab08_mfl.py b/lab08_mfl.py index 72ab479..790b8f1 100644 --- a/lab08_mfl.py +++ b/lab08_mfl.py @@ -1,7 +1,7 @@ import sys + import mlflow import pandas as pd - from sklearn.metrics import mean_squared_error from sklearn.model_selection import train_test_split from tensorflow.keras.callbacks import EarlyStopping diff --git a/requirements.txt b/requirements.txt index 2a481a5..ac67c8a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,5 @@ tensorflow==2.0.0b1 wget==3.2 gast==0.3.3 sacred==0.8.2 -GitPython==3.1.14 \ No newline at end of file +GitPython==3.1.14 +matplotlib==3.4.2 \ No newline at end of file