From fb163e56532699146faf2eb4d8021134321cadc7 Mon Sep 17 00:00:00 2001 From: Anna Nowak Date: Sun, 16 May 2021 23:41:55 +0200 Subject: [PATCH] MLflow --- .gitignore | 3 ++- MLProject | 11 +++++++++++ evaluate.py | 4 +++- requirements.txt | 3 ++- train.py | 10 ++++++++-- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 MLProject diff --git a/.gitignore b/.gitignore index 629d54a..0a78817 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,5 @@ dev.csv *.txt .venv/ model.h5 -evaluation.png \ No newline at end of file +evaluation.png +mlruns/* \ No newline at end of file diff --git a/MLProject b/MLProject new file mode 100644 index 0000000..94bf167 --- /dev/null +++ b/MLProject @@ -0,0 +1,11 @@ +name: Fifa Players +docker_env: + image: docker.io/adnovac/ium_s434760:2.0 +entry_points: + train: + parameters: + batch_size: {type: int, default: 15} + epochs: {type: int, default: 16} + command: "python train.py {batch_size} {epochs}" + evaluate: + command: "python evaluate.py" \ No newline at end of file diff --git a/evaluate.py b/evaluate.py index ba37e89..2cf6247 100644 --- a/evaluate.py +++ b/evaluate.py @@ -2,8 +2,8 @@ import pandas as pd import numpy as np from os import path from tensorflow import keras -import sys import matplotlib.pyplot as plt +import mlflow model_name = "model.h5" @@ -16,6 +16,8 @@ Y_test=test_data[["Overall"]].to_numpy() #MeanSquaredError results_test = model.evaluate(X_test, Y_test, batch_size=128) +mlflow.log_metric("rmse", results_test) + with open('results.txt', 'a+', encoding="UTF-8") as f: f.write(str(results_test) +"\n") diff --git a/requirements.txt b/requirements.txt index 454e683..0e6102a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ numpy==1.19.2 sklearn tensorflow==2.4.1 jinja2==2.11.3 -matplotlib \ No newline at end of file +matplotlib +mlflow==1.17.0 \ No newline at end of file diff --git a/train.py b/train.py index 261fd61..4498904 100644 --- a/train.py +++ b/train.py @@ -2,6 +2,7 @@ import pandas as pd from os import path from tensorflow import keras from tensorflow.keras import layers +import mlflow import sys model_name = "model.h5" @@ -25,11 +26,16 @@ model.compile( loss=keras.losses.MeanSquaredError(), ) +batch_size = int(sys.argv[1]) +epochs = int(sys.argv[2]) +mlflow.log_param("batch_size", batch_size) +mlflow.log_param("epochs", epochs) + history = model.fit( X, Y, - batch_size=int(sys.argv[1]), - epochs=int(sys.argv[2]), + batch_size=batch_size, + epochs=epochs, ) model.save(model_name) \ No newline at end of file