diff --git a/Jenkinsfile b/Jenkinsfile index 93e7612..83d1bdb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -34,6 +34,7 @@ pipeline { sh "./download_data.sh" sh "python3 clean_and_split_data.py" archiveArtifacts artifacts: "crime_test.csv, crime_dev.csv, crime_train.csv", onlyIfSuccessful: true + build job: "s444380-training/master" } } } diff --git a/Jenkinsfile.train b/Jenkinsfile.train new file mode 100644 index 0000000..d113aea --- /dev/null +++ b/Jenkinsfile.train @@ -0,0 +1,44 @@ +pipeline { + agent { + docker { image 'kamilguttmann/ium:latest' } + } + parameters { + string ( + defaultValue: '100', + description: 'Epochs', + name: 'EPOCHS' + ) + buildSelector( + defaultSelector: lastSuccessful(), + description: 'Which build to use for copying artifacts', + name: 'BUILD_SELECTOR' + ) + } + stages { + stage('Copy artifacts') { + steps { + copyArtifacts fingerprintArtifacts: true, projectName: 's444380-create-dataset', selector: buildParameter('BUILD_SELECTOR') + } + } + stage("Checkout git") { + steps { + checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 's444380', url: 'https://git.wmi.amu.edu.pl/s444380/ium_444380.git']]]) + } + } + stage("Train model") { + steps { + sh "./train_model.py $EPOCHS" + archiveArtifacts artifacts: "./model/*", onlyIfSuccessful: true + } + } + } + post { + success { + emailtext body: "SUCCESS", subject: "s444380-training", to: "e19191c5.uam.onmicrosoft.com@emea.teams.ms" + } + + failure { + emailtext body: "FAILURE", subject: "s444380-training", to: "e19191c5.uam.onmicrosoft.com@emea.teams.ms" + } + } +} diff --git a/train_model.py b/train_model.py index 9b30e2a..7235637 100644 --- a/train_model.py +++ b/train_model.py @@ -1,3 +1,5 @@ +import sys + import pandas as pd from sklearn.preprocessing import LabelEncoder from keras.models import Sequential @@ -63,8 +65,13 @@ model.add(Dense(128, activation='relu')) model.add(Dense(num_categories, activation='softmax')) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy', 'sparse_categorical_accuracy']) +if len(sys.argv) > 1: + epochs = sys.argv[1] +else: + epochs = 10 + # Train model -model.fit(x_train, y_train, epochs=100, validation_data=(x_val, y_val)) +model.fit(x_train, y_train, epochs=epochs, validation_data=(x_val, y_val)) # Make predictions y_pred = model.predict(x_test)