update dllib-sacred.py
This commit is contained in:
parent
8e85f90e0a
commit
7a0bf1af21
@ -2,7 +2,6 @@ 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
|
||||||
@ -17,15 +16,13 @@ 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'))
|
||||||
|
|
||||||
mlflow.set_experiment("s444356")
|
@ex.config
|
||||||
|
def my_config():
|
||||||
#@ex.config
|
epochs = 100
|
||||||
#def my_config():
|
|
||||||
# epochs = 100
|
|
||||||
|
|
||||||
class Model(nn.Module):
|
class Model(nn.Module):
|
||||||
def __init__(self, input_dim):
|
def __init__(self, input_dim):
|
||||||
@ -245,11 +242,8 @@ 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()
|
||||||
|
|
||||||
epochs = int(sys.argv[1]) if len(sys.argv) > 20 else 20
|
@ex.automain
|
||||||
|
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()
|
||||||
@ -301,8 +295,7 @@ def my_main(epochs):
|
|||||||
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)
|
||||||
@ -329,15 +322,14 @@ def my_main(epochs):
|
|||||||
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")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user