work on lab7
Some checks failed
s449288-training/pipeline/head There was a failure building this commit
Some checks failed
s449288-training/pipeline/head There was a failure building this commit
This commit is contained in:
parent
8e23b9517b
commit
3e4bc7479b
@ -4,30 +4,32 @@ from keras.models import save_model
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import sys
|
||||
from sacred import Experiment
|
||||
from sacred.observers import FileStorageObserver
|
||||
from sacred.observers import MongoObserver
|
||||
|
||||
# Stworzenie obiektu klasy Experiment do śledzenia przebiegu regresji narzędziem Sacred
|
||||
ex = Experiment(save_git_info=False)
|
||||
ex = Experiment()
|
||||
|
||||
# Dodanie obserwatora FileObserver
|
||||
ex.observers.append(FileStorageObserver('runs'))
|
||||
|
||||
#Dodanie obserwatora Mongo
|
||||
#ex.observers.append(MongoObserver(url='mongodb://mongo_user:mongo_password_IUM_2021@localhost:27017', db_name='sacred'))
|
||||
ex.observers.append(MongoObserver(url='mongodb://mongo_user:mongo_password_IUM_2021@localhost:27017', db_name='sacred'))
|
||||
|
||||
# Przykładowa modyfikowalna z Sacred konfiguracja wybranych parametrów treningu
|
||||
@ex.config
|
||||
def config():
|
||||
epochs = 100
|
||||
units = 1
|
||||
learning_rate = 0.1
|
||||
|
||||
|
||||
# Reszta kodu wrzucona do udekorowanej funkcji train do wywołania przez Sacred, żeby coś było capture'owane
|
||||
@ex.capture
|
||||
def train(epochs, units, learning_rate, _run):
|
||||
def train(units, learning_rate, _run):
|
||||
# Pobranie przykładowego argumentu trenowania z poziomu Jenkinsa
|
||||
EPOCHS_NUM = int(sys.argv[1])
|
||||
|
||||
# Wczytanie danych
|
||||
data_train = pd.read_csv('lego_sets_clean_train.csv')
|
||||
@ -59,7 +61,7 @@ def train(epochs, units, learning_rate, _run):
|
||||
history = model.fit(
|
||||
train_piece_counts,
|
||||
train_prices,
|
||||
epochs=epochs,
|
||||
epochs=EPOCHS_NUM,
|
||||
verbose=0,
|
||||
validation_split=0.2
|
||||
)
|
||||
@ -74,14 +76,15 @@ def train(epochs, units, learning_rate, _run):
|
||||
|
||||
# Zapis modelu do pliku standardowo poprzez metodę kerasa i poprzez metodę obiektu Experiment z Sacred
|
||||
model.save('lego_reg_model')
|
||||
ex.add_artifact('lego_reg_model/saved_model.pb')
|
||||
ex.add_artifact('lego_reg_model_art')
|
||||
|
||||
# Przykładowo zwracamy coś w charakterze wyników, żeby było widoczne w plikach zapisanych przez obserwator
|
||||
hist = pd.DataFrame(history.history)
|
||||
hist['epoch'] = history.epoch
|
||||
_run.info["train_results"] = str(hist.tail())
|
||||
return hist.tail()
|
||||
_run.log_scalar('final.training.loss', hist['loss'].iloc[-1])
|
||||
print(hist['loss'].iloc[-1])
|
||||
print(type(hist['loss'].iloc[-1]))
|
||||
|
||||
@ex.automain
|
||||
def main(units, learning_rate):
|
||||
print(train())
|
||||
train()
|
Loading…
Reference in New Issue
Block a user