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/'
|
sh 'tar -czf lego_reg_model.tar.gz lego_reg_model/'
|
||||||
archiveArtifacts 'lego_reg_model.tar.gz'
|
archiveArtifacts 'lego_reg_model.tar.gz'
|
||||||
echo 'Model archived'
|
echo 'Model archived'
|
||||||
echo 'Archiving Sacreds output repo...'
|
echo 'Archiving the MLflow repo...'
|
||||||
sh 'ls -lh runs/*/'
|
archiveArtifacts 'mlruns'
|
||||||
sh 'tar -czf sacred_runs.tar.gz runs/'
|
echo 'MLflow repo archived'
|
||||||
archiveArtifacts 'sacred_runs.tar.gz'
|
|
||||||
echo 'Sacreds repo archived'
|
|
||||||
echo 'Launching the s449288-evaluation job...'
|
echo 'Launching the s449288-evaluation job...'
|
||||||
build job: 's449288-evaluation/master/'
|
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,37 +4,22 @@ from keras.models import save_model
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from sacred import Experiment
|
|
||||||
from sacred.observers import FileStorageObserver
|
|
||||||
from sacred.observers import MongoObserver
|
|
||||||
import mlflow
|
import mlflow
|
||||||
import mlflow.keras
|
import mlflow.keras
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
import sys
|
||||||
# Konfiguracja serwera i nazwy eksperymentu MLflow
|
|
||||||
#mlflow.set_tracking_uri('http://tzietkiewicz.vm.wmi.amu.edu.pl: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
|
def train():
|
||||||
@ex.capture
|
|
||||||
def train(epochs, units, learning_rate, _run):
|
# 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')
|
||||||
|
|
||||||
# Podpięcie treningu do MLflow
|
# Podpięcie treningu do MLflow
|
||||||
with mlflow.start_run() as run:
|
with mlflow.start_run() as run:
|
||||||
@ -81,17 +66,12 @@ def train(epochs, units, learning_rate, _run):
|
|||||||
|
|
||||||
# Zapis predykcji do pliku
|
# Zapis predykcji do pliku
|
||||||
results = pd.DataFrame(
|
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)
|
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')
|
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)
|
# Ewaluacja MAE na potrzeby MLflow (kopia z evaluate.py)
|
||||||
mae = model.evaluate(
|
mae = model.evaluate(
|
||||||
@ -109,11 +89,10 @@ def train(epochs, units, learning_rate, _run):
|
|||||||
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
|
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
|
||||||
if tracking_url_type_store != 'file':
|
if tracking_url_type_store != 'file':
|
||||||
mlflow.keras.log_model(model, 'lego-model', registered_model_name='TFLegoModel',
|
mlflow.keras.log_model(model, 'lego-model', registered_model_name='TFLegoModel',
|
||||||
signature=signature)
|
signature=signature)
|
||||||
else:
|
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
|
if __name__ == '__main__':
|
||||||
def main(epochs, units, learning_rate):
|
|
||||||
train()
|
train()
|
||||||
|
@ -4,37 +4,22 @@ from keras.models import save_model
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from sacred import Experiment
|
|
||||||
from sacred.observers import FileStorageObserver
|
|
||||||
from sacred.observers import MongoObserver
|
|
||||||
import mlflow
|
import mlflow
|
||||||
import mlflow.keras
|
import mlflow.keras
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
import sys
|
||||||
# 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
|
def train():
|
||||||
@ex.capture
|
|
||||||
def train(epochs, units, learning_rate, _run):
|
# 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')
|
||||||
|
|
||||||
# Podpięcie treningu do MLflow
|
# Podpięcie treningu do MLflow
|
||||||
with mlflow.start_run() as run:
|
with mlflow.start_run() as run:
|
||||||
@ -81,17 +66,12 @@ def train(epochs, units, learning_rate, _run):
|
|||||||
|
|
||||||
# Zapis predykcji do pliku
|
# Zapis predykcji do pliku
|
||||||
results = pd.DataFrame(
|
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)
|
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')
|
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)
|
# Ewaluacja MAE na potrzeby MLflow (kopia z evaluate.py)
|
||||||
mae = model.evaluate(
|
mae = model.evaluate(
|
||||||
@ -109,11 +89,10 @@ def train(epochs, units, learning_rate, _run):
|
|||||||
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
|
tracking_url_type_store = urlparse(mlflow.get_tracking_uri()).scheme
|
||||||
if tracking_url_type_store != 'file':
|
if tracking_url_type_store != 'file':
|
||||||
mlflow.keras.log_model(model, 'lego-model', registered_model_name='TFLegoModel',
|
mlflow.keras.log_model(model, 'lego-model', registered_model_name='TFLegoModel',
|
||||||
signature=signature)
|
signature=signature)
|
||||||
else:
|
else:
|
||||||
mlflow.keras.log_model(model, 'model', signature=signature, input_example=np.array(500))
|
mlflow.keras.log_model(model, 'model', signature=signature, input_example=np.array(500))
|
||||||
|
|
||||||
|
|
||||||
@ex.automain
|
if __name__ == '__main__':
|
||||||
def main(epochs, units, learning_rate):
|
|
||||||
train()
|
train()
|
||||||
|
Loading…
Reference in New Issue
Block a user