From 0fce6cd355c38fa279b30e8dedc51f341fa129c9 Mon Sep 17 00:00:00 2001 From: Wojciech Jarmosz Date: Thu, 13 May 2021 22:20:25 +0200 Subject: [PATCH] LAB 6 - 1, Add pipeline for training --- Jenkinsfile_train | 29 +++++++++++++++++++++++++++++ training.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 Jenkinsfile_train create mode 100644 training.py diff --git a/Jenkinsfile_train b/Jenkinsfile_train new file mode 100644 index 0000000..6952ed2 --- /dev/null +++ b/Jenkinsfile_train @@ -0,0 +1,29 @@ +pipeline { + agent { + docker { image 'jarmosz/ium:1.1' } + } + parameters { + string(name: 'optioms', description: 'Trainig script options') + buildSelector(defaultSelector: lastSuccessful(), description: 'Use latest build', name: 'BUILD_SELECTOR') + } + stages { + stage("Copy artifacts"){ + steps { + copyArtifacts fingerprintArtifacts: true, projectName: 's434704-create-dataset', selector: buildParameter('BUILD_SELECTOR') + } + } + stage("Run training"){ + sh "python3 training.py ${params.options}" + } + stage('Save trained model files') { + steps{ + archiveArtifacts 'linear_regression/**' + } + } + } + post { + always { + mail body: ${currentBuild.currentResult}, subject: 's434704', to: '26ab8f35.uam.onmicrosoft.com@emea.teams.ms' + } + } +} \ No newline at end of file diff --git a/training.py b/training.py new file mode 100644 index 0000000..cddf32b --- /dev/null +++ b/training.py @@ -0,0 +1,43 @@ +import pandas as pd +import numpy as np +import tensorflow as tf +import os.path + +from tensorflow import keras +from tensorflow.keras import layers +from tensorflow.keras.layers.experimental import preprocessing + +pd.set_option("display.max_columns", None) + +# Wczytanie danych +train_data = pd.read_csv("./train.csv") +test_data = pd.read_csv("./test.csv") + +# Stworzenie modelu +columns_to_use = ['Year', 'Runtime', 'Netflix'] +train_X = tf.convert_to_tensor(train_data[columns_to_use]) +train_Y = tf.convert_to_tensor(train_data[["IMDb"]]) +test_X = tf.convert_to_tensor(test_data[columns_to_use]) +test_Y = tf.convert_to_tensor(test_data[["IMDb"]]) + +normalizer = preprocessing.Normalization(input_shape=[3,]) +normalizer.adapt(train_X) + +if os.path.isdir('linear_regression'): + model = keras.models.load_model('linear_regression') +else: + model = keras.Sequential([ + keras.Input(shape=(len(columns_to_use),)), + normalizer, + layers.Dense(30, activation='relu'), + layers.Dense(10, activation='relu'), + layers.Dense(25, activation='relu'), + layers.Dense(1) + ]) + + model.compile(loss='mean_absolute_error', + optimizer=tf.keras.optimizers.Adam(0.001)) + + model.fit(train_X, train_Y, verbose=0, epochs=100) + + model.save('linear_regression') \ No newline at end of file