From 0e7a4840c95fcc6d0f0e113f78f71369b8711aaa Mon Sep 17 00:00:00 2001 From: Adrian Charkiewicz Date: Sat, 7 May 2022 21:07:01 +0200 Subject: [PATCH] sacred --- Dockerfile | 4 ++++ pytorch/pytorch.py | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index e1d4373..c8cb532 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,10 @@ RUN pip3 install torch RUN pip3 install seaborn RUN pip3 install torchvision RUN pip3 install sklearn +RUN pip3 install sacred +RUN pip3 install pymongo +RUN pip3 install GitPython + # RUN python3 -m pip install kaggle RUN python3 -m pip install pandas RUN pip3 install matplotlib diff --git a/pytorch/pytorch.py b/pytorch/pytorch.py index 4d89412..6a65f14 100644 --- a/pytorch/pytorch.py +++ b/pytorch/pytorch.py @@ -18,10 +18,21 @@ from torch.utils.data import DataLoader, TensorDataset, random_split import random import os import sys +from sacred import Experiment +from sacred.observers import FileStorageObserver +from sacred.observers import MongoObserver # In[2]: +ex = Experiment(save_git_info=False) +ex.observers.append(FileStorageObserver('runs')) +@ex.config +def config(): + epochs = 1500 + + + dataframe_raw = pd.read_csv("winequality-red.csv") dataframe_raw.head() @@ -131,7 +142,8 @@ def evaluate(model, val_loader): outputs = [model.validation_step(batch) for batch in val_loader] return model.validation_epoch_end(outputs) -def fit(epochs, lr, model, train_loader, val_loader, opt_func=torch.optim.SGD): +@ex.capture +def fit(epochs, lr, model, train_loader, val_loader, opt_func=torch.optim.SGD, _run): history = [] optimizer = opt_func(model.parameters(), lr) for epoch in range(epochs): @@ -149,9 +161,9 @@ def fit(epochs, lr, model, train_loader, val_loader, opt_func=torch.optim.SGD): # In[12]: -epochs = int(sys.argv[1]) -lr = 1e-6 -history5 = fit(epochs, lr, model, train_loader, val_loader) +#epochs = int(sys.argv[1]) + + # In[27]: @@ -183,5 +195,10 @@ with open("result.txt", "w+") as file: input_, target = val_ds[i] file.write(str(predict_single(input_, target, model))) +@ex.main +def main(): + lr = 1e-6 + history5 = fit(epochs, lr, model, train_loader, val_loader) +ex.run()