From d794e390aa4caa412683e97ee10e4287fffd71b9 Mon Sep 17 00:00:00 2001 From: Marcin Kostrzewski Date: Fri, 6 May 2022 21:37:04 +0200 Subject: [PATCH] Add Sacred FileStorageObserver --- .gitignore | 1 + Jenkinsfile-train | 1 + train_model.py | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 680c817..a483171 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ __pycache__ evaluation_results.txt model_out trend.png +sacred_runs diff --git a/Jenkinsfile-train b/Jenkinsfile-train index e75d67c..122b928 100644 --- a/Jenkinsfile-train +++ b/Jenkinsfile-train @@ -35,6 +35,7 @@ pipeline { stage('Archive model and evaluate it') { steps { archiveArtifacts artifacts: 'model_out', onlyIfSuccessful: true + archiveArtifacts artifacts: 'sacred_runs', onlyIfSuccessful: true build job: "s444409-evaluation/${params.BRANCH}/" } } diff --git a/train_model.py b/train_model.py index 8695f6d..18b290b 100644 --- a/train_model.py +++ b/train_model.py @@ -3,6 +3,7 @@ import argparse import numpy as np import pandas as pd import torch +from sacred.observers import FileStorageObserver from torch import nn from torch.utils.data import DataLoader, Dataset from sacred import Experiment @@ -120,7 +121,13 @@ def main(batch_size, epochs): print("Model saved in ./model_out file.") -ex = Experiment('Predict power output for a given time') +def setup_experiment(): + ex = Experiment('Predict power output for a given time') + ex.observers.append(FileStorageObserver('sacred_runs')) + return ex + + +ex = setup_experiment() @ex.config @@ -132,3 +139,6 @@ def experiment_config(): @ex.automain def run(batch_size, epochs): main(batch_size, epochs) + + +ex.add_artifact('model_out')