add mlflow

This commit is contained in:
jakubknczny 2021-05-16 23:01:34 +02:00
parent aeaf3178a0
commit a9a40b0424
6 changed files with 50 additions and 26 deletions

View File

@ -12,14 +12,19 @@ and prints a short summary of the dataset as well as its subsets.
### Zadanie 2
add Jenkinsfiles and mock data preprocessing
### Zadanie 5
added lab4 file with new python script and updated Dockerfile.
### Zadanie 4
added lab4 directory with new python script and updated Dockerfile.
The container downloads the dataset and installs software needed,
then trains and evaluates model on the dataset.
Loss and accuracy are saved to test_eval.txt file.
### Zadanie 5
added lab5 directory with scripts
### Zadanie 6
added create, train, eval directories in lab5
### Zadanie 7
updated contents of lab5/train directory
ium01.ipynb is a notebook used to develop previously mentioned scripts.

View File

@ -55,6 +55,7 @@ pipeline {
stage('archive artifact') {
steps {
archiveArtifacts 'eval.csv'
archiveArtifacts 'plot.png'
}
}
}

View File

@ -1,9 +1,6 @@
import csv
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import sys
import tensorflow
from tensorflow.keras import layers
from tensorflow.keras.models import load_model
@ -20,3 +17,11 @@ with open('eval.csv', 'a', newline='') as fp:
wr = csv.writer(fp, dialect='excel')
wr.writerow(results)
metrics = pd.read_csv('eval.csv', header=None, names=['loss', 'accuracy'])
fig = plt.figure()
plt.plot(metrics.accuracy)
plt.ylabel('Accuracy')
plt.xlabel('Build no.')
fig.savefig('plot.png')

8
lab5/train/MLproject Normal file
View File

@ -0,0 +1,8 @@
name: s470607
docker_env:
image: kubakonieczny/ium:train-sacred-mlflow
entry_points:
main:
parameters:
learning_rate: (type: float, default: 0.0003)
comment: "python3 train.py {learning_rate}"

View File

@ -3,3 +3,4 @@ pandas
tensorflow
keras==2.3.1
sacred
mlflow

View File

@ -1,4 +1,5 @@
from datetime import datetime
import mlflow
import pandas as pd
from sacred import Experiment
from sacred.observers import FileStorageObserver, MongoObserver
@ -19,34 +20,37 @@ def my_config():
@ex.capture
def prepare_train_model(learning_rate, _run):
_run.info["prepare_model"] = str(datetime.now())
with mlflow.start_run():
_run.info["prepare_model"] = str(datetime.now())
X_train = pd.read_csv('train.csv')
X_valid = pd.read_csv('valid.csv')
X_train = pd.read_csv('train.csv')
X_valid = pd.read_csv('valid.csv')
Y_train = X_train.pop('stabf')
Y_train = pd.get_dummies(Y_train)
Y_train = X_train.pop('stabf')
Y_train = pd.get_dummies(Y_train)
Y_valid = X_valid.pop('stabf')
Y_valid = pd.get_dummies(Y_valid)
Y_valid = X_valid.pop('stabf')
Y_valid = pd.get_dummies(Y_valid)
model = tensorflow.keras.Sequential([
layers.Input(shape=(12,)),
layers.Dense(32),
layers.Dense(16),
layers.Dense(2, activation='softmax')
])
model = tensorflow.keras.Sequential([
layers.Input(shape=(12,)),
layers.Dense(32),
layers.Dense(16),
layers.Dense(2, activation='softmax')
])
model.compile(
loss=tensorflow.keras.losses.BinaryCrossentropy(),
optimizer=tensorflow.keras.optimizers.Adam(learning_rate=learning_rate),
metrics=[tensorflow.keras.metrics.BinaryAccuracy()])
model.compile(
loss=tensorflow.keras.losses.BinaryCrossentropy(),
optimizer=tensorflow.keras.optimizers.Adam(learning_rate=learning_rate),
metrics=[tensorflow.keras.metrics.BinaryAccuracy()])
history = model.fit(X_train, Y_train, epochs=2, validation_data=(X_valid, Y_valid))
history = model.fit(X_train, Y_train, epochs=2, validation_data=(X_valid, Y_valid))
model.save('grid-stability-dense.h5')
model.save('grid-stability-dense.h5')
_run.info['history'] = str(history.history['loss'][-1])
_run.info['history'] = str(history.history['loss'][-1])
mlflow.log_metric('loss', history.history['loss'][-1])
mlflow.log_param('learning_rate', learning_rate)
@ex.main