From 7905591af2b9fde0f25f4263de0035f5e309b866 Mon Sep 17 00:00:00 2001 From: jakubknczny Date: Sun, 16 May 2021 14:30:55 +0200 Subject: [PATCH] add sacred --- lab5/eval/Dockerfile | 1 + lab5/train/Dockerfile | 1 - lab5/train/requirements.txt | 1 + lab5/train/train.py | 62 ++++++++++++++++++++++++++----------- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/lab5/eval/Dockerfile b/lab5/eval/Dockerfile index e16c895..69bef2b 100644 --- a/lab5/eval/Dockerfile +++ b/lab5/eval/Dockerfile @@ -11,6 +11,7 @@ WORKDIR /app COPY ./eval.py ./ COPY ./script.sh ./ +COPY ./test.csv ./ RUN chmod +x script.sh COPY ./requirements.txt ./ diff --git a/lab5/train/Dockerfile b/lab5/train/Dockerfile index 5e579a5..fa359be 100644 --- a/lab5/train/Dockerfile +++ b/lab5/train/Dockerfile @@ -8,7 +8,6 @@ RUN apt install -y unzip >>/dev/null WORKDIR /app -COPY ./train.py ./ COPY ./script.sh ./ RUN chmod +x script.sh diff --git a/lab5/train/requirements.txt b/lab5/train/requirements.txt index b35a172..bfe51aa 100644 --- a/lab5/train/requirements.txt +++ b/lab5/train/requirements.txt @@ -2,3 +2,4 @@ numpy~=1.19.2 pandas tensorflow keras==2.3.1 +sacred diff --git a/lab5/train/train.py b/lab5/train/train.py index 952c297..21289d2 100644 --- a/lab5/train/train.py +++ b/lab5/train/train.py @@ -1,29 +1,55 @@ +from datetime import datetime import pandas as pd +from sacred import Experiment +from sacred.observers import MongoObserver import sys import tensorflow from tensorflow.keras import layers -X_train = pd.read_csv('train.csv') -X_valid = pd.read_csv('valid.csv') +ex = Experiment("470607", interactive=False, save_git_info=False) +ex.observers.append(MongoObserver(url='mongodb://mongo_user:mongo_password_IUM_2021@172.17.0.1:27017', db_name='sacred')) +ex.observers.append(FileStorageObserver('my_runs')) -Y_train = X_train.pop('stabf') -Y_train = pd.get_dummies(Y_train) +@ex.config +def my_config(): + learning_rate = float(sys.argv[1]) -Y_valid = X_valid.pop('stabf') -Y_valid = pd.get_dummies(Y_valid) +@ex.capture +def prepare_train_model(learning_rate, _run): + _run.info["prepare_model"] = str(datetime.now()) -model = tensorflow.keras.Sequential([ - layers.Input(shape=(12,)), - layers.Dense(32), - layers.Dense(16), - layers.Dense(2, activation='softmax') -]) + X_train = pd.read_csv('train.csv') + X_valid = pd.read_csv('valid.csv') -model.compile( - loss=tensorflow.keras.losses.BinaryCrossentropy(), - optimizer=tensorflow.keras.optimizers.Adam(lr=float(sys.argv[1])), - metrics=[tensorflow.keras.metrics.BinaryAccuracy()]) + Y_train = X_train.pop('stabf') + Y_train = pd.get_dummies(Y_train) -history = model.fit(X_train, Y_train, epochs=2, validation_data=(X_valid, 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.compile( + loss=tensorflow.keras.losses.BinaryCrossentropy(), + optimizer=tensorflow.keras.optimizers.Adam(lr=learning_rate), + metrics=[tensorflow.keras.metrics.BinaryAccuracy()]) + + history = model.fit(X_train, Y_train, epochs=2, validation_data=(X_valid, Y_valid)) + + model.save('grid-stability-dense.h5') + + _run['history'] = history + +@ex.main +def my_main(learning_rate): + print(prepare_train_model()) + + +r = ex.run() +ex.add_artifact('grid-stability-dense.h5') -model.save('grid-stability-dense.h5')