added sacred

This commit is contained in:
Dawid 2021-05-15 18:47:47 +02:00
parent 4aae76c38b
commit 71864a36b3
3 changed files with 115 additions and 0 deletions

View File

@ -31,12 +31,15 @@ pipeline {
sh 'chmod +x ./tensor-eval.py'
sh 'python3 ./tensor-eval.py $BUILD_NUMBER >> evaluation.txt'
sh 'python3 ./tensor-plot.py'
sh 'python3 ./sacred1.py'
sh 'python3 ./sacred2.py'
}
}
stage('archiveArtifacts') {
steps{
archiveArtifacts 'evaluation.txt'
archiveArtifacts 'evaluation_plot.png'
archiveArtifacts 'sacred/**'
}
}
}

56
sacred1.py Normal file
View File

@ -0,0 +1,56 @@
import pandas as pd
from tensorflow import keras
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as rmse
from sacred import Experiment
from datetime import datetime
from sacred.observers import FileStorageObserver
ex = Experiment("file_observer", interactive=False, save_git_info=False)
ex.observers.append(FileStorageObserver('sacred/my_runs'))
@ex.config
def my_config():
test_size = 0.2
epochs = 100
batch_size = 32
@ex.capture
def create_model(test_size, epochs, batch_size, _run):
_run.info["prepare_model_ts"] = str(datetime.now())
df = pd.read_csv('country_vaccinations.csv').dropna()
dataset = df.iloc[:, 3:-3]
dataset = df.groupby(by=["country"], dropna=True).sum()
X = dataset.loc[:,dataset.columns != "daily_vaccinations"]
y = dataset.loc[:,dataset.columns == "daily_vaccinations"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = test_size, random_state = 6)
model = keras.Sequential([
keras.layers.Dense(512,input_dim = X_train.shape[1],kernel_initializer='normal', activation='relu'),
keras.layers.Dense(512,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(256,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(256,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(128,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(1,kernel_initializer='normal', activation='linear'),
])
model.compile(loss='mean_absolute_error', optimizer='adam', metrics=['mean_absolute_error'])
model.fit(X_train, y_train, epochs = epochs, validation_split = 0.3, batch_size = batch_size)
prediction = model.predict(X_test)
rmse_result = rmse(y_test, prediction, squared = False)
print(prediction)
_run.info["Results: "] = rmse_result
model.save('vaccines_model')
return rmse_result
@ex.automain
def my_main(test_size, epochs, batch_size):
print(create_model())
r = ex.run()
ex.add_artifact("vaccines_model/saved_model.pb")

56
sacred2.py Normal file
View File

@ -0,0 +1,56 @@
import pandas as pd
from tensorflow import keras
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error as rmse
from sacred import Experiment
from datetime import datetime
from sacred.observers import MongoObserver
ex = Experiment("file_observer", interactive=False, save_git_info=False)
ex.observers.append(MongoObserver(url='mongodb://mongo_user:mongo_password_IUM_2021@172.17.0.1:27017', db_name='sacred'))
@ex.config
def my_config():
test_size = 0.2
epochs = 100
batch_size = 32
@ex.capture
def create_model(test_size, epochs, batch_size, _run):
_run.info["prepare_model_ts"] = str(datetime.now())
df = pd.read_csv('country_vaccinations.csv').dropna()
dataset = df.iloc[:, 3:-3]
dataset = df.groupby(by=["country"], dropna=True).sum()
X = dataset.loc[:,dataset.columns != "daily_vaccinations"]
y = dataset.loc[:,dataset.columns == "daily_vaccinations"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = test_size, random_state = 6)
model = keras.Sequential([
keras.layers.Dense(512,input_dim = X_train.shape[1],kernel_initializer='normal', activation='relu'),
keras.layers.Dense(512,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(256,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(256,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(128,kernel_initializer='normal', activation='relu'),
keras.layers.Dense(1,kernel_initializer='normal', activation='linear'),
])
model.compile(loss='mean_absolute_error', optimizer='adam', metrics=['mean_absolute_error'])
model.fit(X_train, y_train, epochs = epochs, validation_split = 0.3, batch_size = batch_size)
prediction = model.predict(X_test)
rmse_result = rmse(y_test, prediction, squared = False)
print(prediction)
_run.info["Results: "] = rmse_result
model.save('vaccines_model')
return rmse_result
@ex.automain
def my_main(test_size, epochs, batch_size):
print(create_model())
r = ex.run()
ex.add_artifact("vaccines_model/saved_model.pb")