5_jenkins_predict
This commit is contained in:
parent
0735fbc4ef
commit
ee9dacba25
@ -14,6 +14,7 @@ RUN pip3 install keras
|
|||||||
RUN pip3 install tensorflow
|
RUN pip3 install tensorflow
|
||||||
RUN pip3 install scikit-learn
|
RUN pip3 install scikit-learn
|
||||||
RUN pip3 install argparse
|
RUN pip3 install argparse
|
||||||
|
RUN pip3 install matplotlib
|
||||||
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
36
Jenkinsfile_evaluation
Normal file
36
Jenkinsfile_evaluation
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
node {
|
||||||
|
stage('Preparation') {
|
||||||
|
properties([
|
||||||
|
parameters([
|
||||||
|
string(
|
||||||
|
defaultValue: '1',
|
||||||
|
description: 'Build number',
|
||||||
|
name: 'build'),
|
||||||
|
gitParameter(
|
||||||
|
branchFilter: 'origin/(.*)',
|
||||||
|
defaultValue: 'master',
|
||||||
|
name: 'BRANCH',
|
||||||
|
type: 'PT_BRANCH'
|
||||||
|
),
|
||||||
|
])
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('checkout: Check out from version control') {
|
||||||
|
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 's487197', url: 'https://git.wmi.amu.edu.pl/s487197/ium_487197']]])
|
||||||
|
}
|
||||||
|
stage('Dockerfile'){
|
||||||
|
def testImage = docker.image('s487197/ium:37')
|
||||||
|
testImage.inside{
|
||||||
|
copyArtifacts filter: 'baltimore_train.csv', projectName: 's487197-create-dataset'
|
||||||
|
copyArtifacts filter: 'baltimore_test.csv', projectName: 's487197-create-dataset'
|
||||||
|
copyArtifacts filter: 'baltimore_model.h5', fingerprintArtifacts: true, projectName: "s487197-training/$BRANCH", selector: buildParameter(lastSuccessful())
|
||||||
|
copyArtifacts filter: 'metrics.csv', projectName: "s487197-evaluation.eg/$BRANCH", optional: true
|
||||||
|
sh "python3 ium_predict.py -build $BUILD"
|
||||||
|
archiveArtifacts artifacts: 'metrics.csv, listfile.txt, metrics_img.png', onlyIfSuccessful: true
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -25,12 +25,14 @@ node {
|
|||||||
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 's487197', url: 'https://git.wmi.amu.edu.pl/s487197/ium_487197']]])
|
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 's487197', url: 'https://git.wmi.amu.edu.pl/s487197/ium_487197']]])
|
||||||
}
|
}
|
||||||
stage('Dockerfile'){
|
stage('Dockerfile'){
|
||||||
def testImage = docker.image('s487197/ium:36')
|
def testImage = docker.image('s487197/ium:37')
|
||||||
testImage.inside{
|
testImage.inside{
|
||||||
copyArtifacts filter: 'baltimore_train.csv', projectName: 's487197-create-dataset'
|
copyArtifacts filter: 'baltimore_train.csv', projectName: 's487197-create-dataset'
|
||||||
sh "python3 ium_train.py -epochs $EPOCHS -lr $LR -validation_split $VALIDATION_SPLIT"
|
sh "python3 ium_train.py -epochs $EPOCHS -lr $LR -validation_split $VALIDATION_SPLIT"
|
||||||
archiveArtifacts artifacts: 'baltimore_model.h5'
|
archiveArtifacts artifacts: 'baltimore.zip'
|
||||||
|
stage('Buil'){
|
||||||
|
build job: 's449312-evaluation.eg/master', parameters: [string(name: 'build', value: "${currentBuild.number}")], wait:false
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
from keras.models import Sequential
|
from keras.models import load_model
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sklearn.preprocessing import LabelEncoder
|
from sklearn.preprocessing import LabelEncoder
|
||||||
from sklearn import metrics
|
from sklearn import metrics
|
||||||
import math
|
import math
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
import os.path
|
||||||
|
import argparse
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import shutil
|
||||||
|
|
||||||
def write_list(names):
|
def write_list(names):
|
||||||
with open('listfile.txt', 'w') as fp:
|
with open('listfile.txt', 'w') as fp:
|
||||||
@ -26,7 +29,11 @@ def get_x_y(data):
|
|||||||
|
|
||||||
|
|
||||||
def predict():
|
def predict():
|
||||||
model = load_model('baltimore_model.h5')
|
parser = argparse.ArgumentParser(description='Pred')
|
||||||
|
parser.add_argument('-build', type=int, default=1)
|
||||||
|
args = parser.parse_args()
|
||||||
|
shutil.unpack_archive('baltimore.zip', 'baltimore_model', 'zip')
|
||||||
|
model = load_model('baltimore_model')
|
||||||
|
|
||||||
train = pd.read_csv('baltimore_train.csv')
|
train = pd.read_csv('baltimore_train.csv')
|
||||||
baltimore_data_test = pd.read_csv('baltimore_test.csv')
|
baltimore_data_test = pd.read_csv('baltimore_test.csv')
|
||||||
@ -36,11 +43,46 @@ def predict():
|
|||||||
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100))
|
print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100))
|
||||||
|
|
||||||
y_predicted = model.predict(x_test)
|
y_predicted = model.predict(x_test)
|
||||||
y_predicted = np.argmax(y_predicted,axis=1)
|
y_predicted = np.argmax(y_predicted, axis=1)
|
||||||
test_results = {}
|
test_results = {}
|
||||||
test_results['Weapon'] = model.evaluate(
|
test_results['Weapon'] = model.evaluate(
|
||||||
x_test,
|
x_test,
|
||||||
y_test, verbose=0)
|
y_test, verbose=0)
|
||||||
write_list(y_predicted)
|
write_list(y_predicted)
|
||||||
|
print('Accuracy : ', scores[1] * 100)
|
||||||
|
print('Mean Absolute Error : ', metrics.mean_absolute_error(y_test, y_predicted))
|
||||||
|
print('Root Mean Squared Error : ', math.sqrt(metrics.mean_squared_error(y_test, y_predicted)))
|
||||||
|
if os.path.exists("metrics.csv"):
|
||||||
|
df = pd.read_csv('metrics.csv')
|
||||||
|
data = {
|
||||||
|
'build': [args.build],
|
||||||
|
'mse': metrics.mean_squared_error(y_test, y_predicted),
|
||||||
|
'rmse': math.sqrt(metrics.mean_squared_error(y_test, y_predicted)),
|
||||||
|
'accuracy': scores[1] * 100
|
||||||
|
}
|
||||||
|
row = pd.DataFrame([data])
|
||||||
|
if df['build'].isin([int(args.build)]).any():
|
||||||
|
df[df['build'] == args.build] = row.iloc[0]
|
||||||
|
else:
|
||||||
|
df = pd.concat([df, row])
|
||||||
|
df['build'] = df['build'].astype('int')
|
||||||
|
df.to_csv('metrics.csv', index=False)
|
||||||
|
else:
|
||||||
|
data = {
|
||||||
|
'build': [args.build],
|
||||||
|
'mse': metrics.mean_squared_error(y_test, y_predicted),
|
||||||
|
'rmse': math.sqrt(metrics.mean_squared_error(y_test, y_predicted)),
|
||||||
|
'accuracy': scores[1] * 100
|
||||||
|
}
|
||||||
|
df = pd.DataFrame(data)
|
||||||
|
df['build'] = df['build'].astype('int')
|
||||||
|
df.to_csv('metrics.csv', index=False)
|
||||||
|
plt.plot(df['build'], df['mse'], label="mse")
|
||||||
|
plt.plot(df['build'], df['rmse'], label="rmse")
|
||||||
|
plt.plot(df['build'], df['accuracy'], label="accuracy")
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
||||||
|
plt.savefig('metrics_img.png')
|
||||||
|
|
||||||
|
|
||||||
predict()
|
predict()
|
@ -10,6 +10,7 @@ import tensorflow as tf
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from sklearn.preprocessing import LabelEncoder
|
from sklearn.preprocessing import LabelEncoder
|
||||||
import argparse
|
import argparse
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
def get_x_y(data):
|
def get_x_y(data):
|
||||||
@ -57,7 +58,8 @@ def train_model():
|
|||||||
validation_split=args.validation_split)
|
validation_split=args.validation_split)
|
||||||
hist = pd.DataFrame(history.history)
|
hist = pd.DataFrame(history.history)
|
||||||
hist['epoch'] = history.epoch
|
hist['epoch'] = history.epoch
|
||||||
model.save('baltimore_model.h5')
|
model.save('baltimore_model')
|
||||||
|
shutil.make_archive('baltimore', 'zip', 'baltimore_model')
|
||||||
|
|
||||||
|
|
||||||
train_model()
|
train_model()
|
||||||
|
Loading…
Reference in New Issue
Block a user