working on lab8
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
d1e9d6235f
commit
97f05db3b9
Binary file not shown.
@ -21,11 +21,9 @@ pipeline {
|
||||
sh 'tar -czf lego_reg_model.tar.gz lego_reg_model/'
|
||||
archiveArtifacts 'lego_reg_model.tar.gz'
|
||||
echo 'Model archived'
|
||||
echo 'Archiving Sacreds output repo...'
|
||||
sh 'ls -lh runs/*/'
|
||||
sh 'tar -czf sacred_runs.tar.gz runs/'
|
||||
archiveArtifacts 'sacred_runs.tar.gz'
|
||||
echo 'Sacreds repo archived'
|
||||
echo 'Archiving the MLflow repo...'
|
||||
archiveArtifacts 'mlruns'
|
||||
echo 'MLflow repo archived'
|
||||
echo 'Launching the s449288-evaluation job...'
|
||||
build job: 's449288-evaluation/master/'
|
||||
}
|
||||
|
@ -1 +1,14 @@
|
||||
name lego_sets
|
||||
|
||||
docker_env:
|
||||
image: s449288/ium:lab8
|
||||
|
||||
entry_points:
|
||||
main:
|
||||
parameters:
|
||||
epochs: {type: float, default: 100}
|
||||
units: {type: float, default: 1}
|
||||
learning_rate: {type: float, default: 0.1}
|
||||
command: python3 simple_regression_lab8.py {epochs} {units} {learning_rate}
|
||||
test:
|
||||
command: python3 evaluate.py
|
||||
|
@ -4,38 +4,23 @@ from keras.models import save_model
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from sacred import Experiment
|
||||
from sacred.observers import FileStorageObserver
|
||||
from sacred.observers import MongoObserver
|
||||
import mlflow
|
||||
import mlflow.keras
|
||||
from urllib.parse import urlparse
|
||||
import sys
|
||||
|
||||
|
||||
def train():
|
||||
|
||||
# Definicja wartości parametrów treningu
|
||||
epochs = int(sys.argv[1]) if len(sys.argv) > 1 else 100
|
||||
units = int(sys.argv[2]) if len(sys.argv) > 2 else 1
|
||||
learning_rate = float(sys.argv[3]) if len(sys.argv) > 3 else 0.1
|
||||
|
||||
# Konfiguracja serwera i nazwy eksperymentu MLflow
|
||||
#mlflow.set_tracking_uri('http://tzietkiewicz.vm.wmi.amu.edu.pl:5000')
|
||||
# mlflow.set_tracking_uri("http://172.17.0.1:5000")
|
||||
mlflow.set_experiment('s449288')
|
||||
|
||||
# Stworzenie obiektu klasy Experiment do śledzenia przebiegu regresji narzędziem Sacred
|
||||
ex = Experiment(save_git_info=False)
|
||||
|
||||
# Dodanie obserwatora FileObserver
|
||||
ex.observers.append(FileStorageObserver('runs'))
|
||||
|
||||
#Dodanie obserwatora Mongo
|
||||
ex.observers.append(MongoObserver(url='mongodb://admin:IUM_2021@172.17.0.1: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):
|
||||
|
||||
# Podpięcie treningu do MLflow
|
||||
with mlflow.start_run() as run:
|
||||
print('MLflow run experiment_id: {0}'.format(run.info.experiment_id))
|
||||
@ -81,17 +66,12 @@ def train(epochs, units, learning_rate, _run):
|
||||
|
||||
# Zapis predykcji do pliku
|
||||
results = pd.DataFrame(
|
||||
{'test_set_piece_count': test_piece_counts.tolist(), 'predicted_price': [round(a[0], 2) for a in y_pred.tolist()]})
|
||||
{'test_set_piece_count': test_piece_counts.tolist(),
|
||||
'predicted_price': [round(a[0], 2) for a in y_pred.tolist()]})
|
||||
results.to_csv('lego_reg_results.csv', index=False, header=True)
|
||||
|
||||
# Zapis modelu do pliku standardowo poprzez metodę kerasa i poprzez metodę obiektu Experiment z Sacred
|
||||
# Zapis modelu do pliku
|
||||
model.save('lego_reg_model')
|
||||
ex.add_artifact('lego_reg_model/saved_model.pb')
|
||||
|
||||
# Przykładowo zwracamy loss ostatniej epoki w charakterze wyników, żeby było widoczne w plikach zapisanych przez obserwator
|
||||
hist = pd.DataFrame(history.history)
|
||||
hist['epoch'] = history.epoch
|
||||
_run.log_scalar('final.training.loss', hist['loss'].iloc[-1])
|
||||
|
||||
# Ewaluacja MAE na potrzeby MLflow (kopia z evaluate.py)
|
||||
mae = model.evaluate(
|
||||
@ -111,9 +91,8 @@ def train(epochs, units, learning_rate, _run):
|
||||
mlflow.keras.log_model(model, 'lego-model', registered_model_name='TFLegoModel',
|
||||
signature=signature)
|
||||
else:
|
||||
mlflow.keras.log_model(model, 'model', signature=signature, input_example=500)
|
||||
mlflow.keras.log_model(model, 'model', signature=signature, input_example=np.array(500))
|
||||
|
||||
|
||||
@ex.automain
|
||||
def main(epochs, units, learning_rate):
|
||||
if __name__ == '__main__':
|
||||
train()
|
||||
|
@ -4,38 +4,23 @@ from keras.models import save_model
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from sacred import Experiment
|
||||
from sacred.observers import FileStorageObserver
|
||||
from sacred.observers import MongoObserver
|
||||
import mlflow
|
||||
import mlflow.keras
|
||||
from urllib.parse import urlparse
|
||||
import sys
|
||||
|
||||
|
||||
def train():
|
||||
|
||||
# Definicja wartości parametrów treningu
|
||||
epochs = int(sys.argv[1]) if len(sys.argv) > 1 else 100
|
||||
units = int(sys.argv[2]) if len(sys.argv) > 2 else 1
|
||||
learning_rate = float(sys.argv[3]) if len(sys.argv) > 3 else 0.1
|
||||
|
||||
# Konfiguracja serwera i nazwy eksperymentu MLflow
|
||||
# mlflow.set_tracking_uri("http://172.17.0.1:5000")
|
||||
mlflow.set_experiment('s449288')
|
||||
|
||||
# Stworzenie obiektu klasy Experiment do śledzenia przebiegu regresji narzędziem Sacred
|
||||
ex = Experiment(save_git_info=False)
|
||||
|
||||
# Dodanie obserwatora FileObserver
|
||||
ex.observers.append(FileStorageObserver('runs'))
|
||||
|
||||
#Dodanie obserwatora Mongo
|
||||
ex.observers.append(MongoObserver(url='mongodb://admin:IUM_2021@172.17.0.1: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):
|
||||
|
||||
# Podpięcie treningu do MLflow
|
||||
with mlflow.start_run() as run:
|
||||
print('MLflow run experiment_id: {0}'.format(run.info.experiment_id))
|
||||
@ -81,17 +66,12 @@ def train(epochs, units, learning_rate, _run):
|
||||
|
||||
# Zapis predykcji do pliku
|
||||
results = pd.DataFrame(
|
||||
{'test_set_piece_count': test_piece_counts.tolist(), 'predicted_price': [round(a[0], 2) for a in y_pred.tolist()]})
|
||||
{'test_set_piece_count': test_piece_counts.tolist(),
|
||||
'predicted_price': [round(a[0], 2) for a in y_pred.tolist()]})
|
||||
results.to_csv('lego_reg_results.csv', index=False, header=True)
|
||||
|
||||
# Zapis modelu do pliku standardowo poprzez metodę kerasa i poprzez metodę obiektu Experiment z Sacred
|
||||
# Zapis modelu do pliku
|
||||
model.save('lego_reg_model')
|
||||
ex.add_artifact('lego_reg_model/saved_model.pb')
|
||||
|
||||
# Przykładowo zwracamy loss ostatniej epoki w charakterze wyników, żeby było widoczne w plikach zapisanych przez obserwator
|
||||
hist = pd.DataFrame(history.history)
|
||||
hist['epoch'] = history.epoch
|
||||
_run.log_scalar('final.training.loss', hist['loss'].iloc[-1])
|
||||
|
||||
# Ewaluacja MAE na potrzeby MLflow (kopia z evaluate.py)
|
||||
mae = model.evaluate(
|
||||
@ -114,6 +94,5 @@ def train(epochs, units, learning_rate, _run):
|
||||
mlflow.keras.log_model(model, 'model', signature=signature, input_example=np.array(500))
|
||||
|
||||
|
||||
@ex.automain
|
||||
def main(epochs, units, learning_rate):
|
||||
if __name__ == '__main__':
|
||||
train()
|
||||
|
Loading…
Reference in New Issue
Block a user