add MLProject, update Dockerfile, dllib-sacred.py
Some checks failed
s444356-evaluation/pipeline/head This commit looks good
s444356-training/pipeline/head There was a failure building this commit

This commit is contained in:
Maciej Czajka 2022-05-09 21:07:13 +02:00
parent 6cda242a4c
commit 452e1bedb5
3 changed files with 32 additions and 11 deletions

View File

@ -2,6 +2,7 @@ import numpy as np
import sys import sys
import os import os
import torch import torch
import mlflow
import pandas as pd import pandas as pd
from torch import nn from torch import nn
from torch.autograd import Variable from torch.autograd import Variable
@ -16,13 +17,15 @@ from sacred.observers import MongoObserver
# EPOCHS = int(sys.argv[1]) # EPOCHS = int(sys.argv[1])
ex = Experiment() #ex = Experiment()
ex.observers.append(FileStorageObserver('my_res')) #ex.observers.append(FileStorageObserver('my_res'))
ex.observers.append(MongoObserver(url='mongodb://admin:IUM_2021@172.17.0.1:27017', db_name='sacred')) #ex.observers.append(MongoObserver(url='mongodb://admin:IUM_2021@172.17.0.1:27017', db_name='sacred'))
@ex.config mlflow.set_experiment("s444356")
def my_config():
epochs = 100 #@ex.config
#def my_config():
# epochs = 100
class Model(nn.Module): class Model(nn.Module):
def __init__(self, input_dim): def __init__(self, input_dim):
@ -242,8 +245,11 @@ def remove_list(games):
# features_g = pd.DataFrame(features_g, dtype=np.float64) # features_g = pd.DataFrame(features_g, dtype=np.float64)
# features_g = features_g.to_numpy() # features_g = features_g.to_numpy()
@ex.automain epochs = int(sys.argv[1]) if len(sys.argv) > 20 else 20
def my_main(epochs, _run):
#@ex.automain
#def my_main(epochs, _run):
def my_main(epochs)
platform = pd.read_csv('all_games.train.csv', sep=',', usecols=[1], header=None).values.tolist() platform = pd.read_csv('all_games.train.csv', sep=',', usecols=[1], header=None).values.tolist()
release_date = pd.read_csv('all_games.train.csv', sep=',', usecols=[2], header=None).values.tolist() release_date = pd.read_csv('all_games.train.csv', sep=',', usecols=[2], header=None).values.tolist()
meta_score = pd.read_csv('all_games.train.csv', sep=',', usecols=[4], header=None).values.tolist() meta_score = pd.read_csv('all_games.train.csv', sep=',', usecols=[4], header=None).values.tolist()
@ -295,7 +301,8 @@ def my_main(epochs, _run):
loss_fn = nn.CrossEntropyLoss() loss_fn = nn.CrossEntropyLoss()
# epochs = 1000 # epochs = 1000
# epochs = epochs # epochs = epochs
_run.info['epochs'] = epochs #_run.info['epochs'] = epochs
mlflow.log_param("epochs", epochs)
def print_(loss): def print_(loss):
print ("The loss calculated: ", loss) print ("The loss calculated: ", loss)
@ -322,14 +329,15 @@ def my_main(epochs, _run):
pred = pred.detach().numpy() pred = pred.detach().numpy()
print("The accuracy is", accuracy_score(labels_test_g, np.argmax(pred, axis=1))) print("The accuracy is", accuracy_score(labels_test_g, np.argmax(pred, axis=1)))
_run.info['accuracy'] = accuracy_score(labels_test_g, np.argmax(pred, axis=1)) #_run.info['accuracy'] = accuracy_score(labels_test_g, np.argmax(pred, axis=1))
_run.log_scalar("measure.accuracy", accuracy_score(labels_test_g, np.argmax(pred, axis=1))) _run.log_scalar("measure.accuracy", accuracy_score(labels_test_g, np.argmax(pred, axis=1)))
mlflow.log_metric("measure.accuracy", accuracy_score(labels_test_g, np.argmax(pred, axis=1)))
pred = pd.DataFrame(pred) pred = pd.DataFrame(pred)
pred.to_csv('result.csv') pred.to_csv('result.csv')
# save model # save model
torch.save(model, "games_model.pkl") torch.save(model, "games_model.pkl")
ex.add_artifact("games_model.pkl") #ex.add_artifact("games_model.pkl")

View File

@ -15,6 +15,7 @@ RUN pip3 install torch
RUN pip3 install sacred RUN pip3 install sacred
RUN pip3 install GitPython RUN pip3 install GitPython
RUN pip3 install pymongo RUN pip3 install pymongo
RUN pip3 install mlflow
#RUN pip3 install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/#tensorflow-0.12.0-py3-none-any.whl #RUN pip3 install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/#tensorflow-0.12.0-py3-none-any.whl
#RUN pip3 install keras #RUN pip3 install keras
RUN apt-get install unzip RUN apt-get install unzip

12
MLProject Executable file
View File

@ -0,0 +1,12 @@
name: ium_s444356
docker_env:
image: maciejczajka
entry_points:
main:
parameters:
epochs: {type: float, default: 100}
command: "python Biblioteka_DL/dllib-sacred.py -e {epochs}"
eval:
command: "python Biblioteka_DL/evaluate.py"