To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit b84d859b authored by zpgeng's avatar zpgeng
Browse files

Updated the saving log and model functions, added the experiment of deepEye,...

Updated the saving log and model functions, added the experiment of deepEye, and make get_data function in IOHelper more generalised
parent 660610bf
......@@ -45,9 +45,9 @@ def run(trainX, trainY):
# PATH = '../cifar_net.pth'
# torch.save(net.state_dict(), PATH)
# Newly added lines below
save_logs(hist, pytorch=True)
save_model_param(pytorch=True)
plot_loss_torch(loss)
save_logs(hist, config['model_dir'], config['model'], pytorch=True)
save_model_param(config['model_dir'], config['model'], pytorch=True)
plot_loss_torch(loss)
def train(trainloader, net, optimizer, criterion, epoch=50):
loss=[]
......
......@@ -12,14 +12,14 @@ import seaborn as sns
sns.set_style('darkgrid')
def run(trainX,trainY):
def run(trainX, trainY):
classifier = Classifier_DEEPEYE(output_directory=config['root_dir'], input_shape=(129, 500))
hist = classifier.fit(deepeye_x=trainX, y=trainY)
plot_loss(hist, 'DeepEye', True)
plot_acc(hist, 'DeepEye', True)
# Newly added lines below
save_logs(hist, pytorch=False)
save_model_param(pytorch=False)
save_logs(hist, config['model_dir'], config['model'], pytorch=False)
save_model_param(config['model_dir'], config['model'], pytorch=False)
class Classifier_DEEPEYE:
"""
......@@ -40,7 +40,7 @@ class Classifier_DEEPEYE:
y_pred : class (left/right for nb_class=2) of the given input_tensor
"""
def __init__(self, output_directory, input_shape, nb_classes, verbose=False, build=True,
def __init__(self, output_directory, input_shape, verbose=False, build=True,
batch_size=64, nb_filters=32, use_residual=True, use_bottleneck=True, depth=6,
kernel_size=41, nb_epochs=1500):
......
......@@ -18,8 +18,8 @@ def run(trainX, trainY):
plot_loss(hist, 'EEGNet', True)
plot_acc(hist, 'EEGNet', True)
# Newly added lines below
save_logs(hist, pytorch=False)
save_model_param(pytorch=False)
save_logs(hist, config['model_dir'], config['model'], pytorch=False)
save_model_param(config['model_dir'], config['model'], pytorch=False)
class Classifier_EEGNet:
def __init__(self, output_directory, nb_classes=1, chans = 129, samples = 500, dropoutRate = 0.5, kernLength = 64, F1 = 8,
......
......@@ -11,8 +11,8 @@ def run(trainX, trainY):
plot_loss(hist, 'Inception', True)
plot_acc(hist, 'Inception', True)
# Newly added lines below
save_logs(hist, pytorch=False)
save_model_param(pytorch=False)
save_logs(hist, config['model_dir'], config['model'], pytorch=False)
save_model_param(config['model_dir'], config['model'], pytorch=False)
class Classifier_INCEPTION:
def __init__(self, output_directory, input_shape, verbose=False, build=True, batch_size=64, nb_filters=32,
......
# DL-Project
Predicting eye gaze with DL
Projects that we try: CNN, InceptionTime, EEGNet, DeepEye
\ No newline at end of file
Projects that we try: CNN, InceptionTime, EEGNet, DeepEye
## Leonhard Settings
Please use the command
`module load gcc/6.3.0 python_gpu/3.8.5`
before training the model. Please make sure that the Tensorflow version should be 2.x.
\ No newline at end of file
......@@ -15,7 +15,7 @@ config['log_dir'] = './runs/'
config['tmp_dir'] = './tmp/'
# Path to training, validation and test data folders.
# PS: Note that we have to upload the data to the server!!!
config['data_dir'] = '/Volumes/methlab/ETH_AS/preprocessed2/'
config['data_dir'] = '/cluster/home/your_username/data/'
config['data_dir_server'] = '/cluster/project/infk/zigeng/preprocessed2/'
# Path of root
config['root_dir'] = '.'
......
......@@ -10,7 +10,7 @@ import numpy as np
def main():
start_time = time.time()
try:
trainX, trainY = IOHelper.get_data(verbose=True)
trainX, trainY = IOHelper.get_data(config['data_dir'], verbose=True)
# IOHelper.store(trainX, trainY)
except:
return
......
......@@ -4,15 +4,15 @@ import scipy.io as sio
import os
import pickle
def get_data(verbose=True):
pkl_file_x = open('x.pkl', 'rb')
def get_data(data_dir, verbose=True):
pkl_file_x = open(data_dir + 'x.pkl', 'rb')
x = pickle.load(pkl_file_x)
pkl_file_x.close()
if verbose:
print("X training loaded.")
print(x.shape)
pkl_file_y = open('y.pkl', 'rb')
pkl_file_y = open(data_dir + 'y.pkl', 'rb')
y = pickle.load(pkl_file_y)
pkl_file_y.close()
if verbose:
......
from config import config
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import torch
import pandas as pd
import os
sns.set_style('darkgrid')
def plot_acc(hist,name,val=False):
......@@ -50,22 +50,21 @@ def plot_loss_torch(loss,name='CNN'):
plt.show()
# Save the logs (newly added without debugging)
# haven't write about the pytorch=True part
def save_logs(hist, output_directory=config['model_dir'], pytorch=False):
# Save the logs
def save_logs(hist, output_directory, model, pytorch=False):
if pytorch:
df_metrics={'Loss':hist}
df_metrics=pd.DataFrame(df_metrics)
df_metrics.to_csv(output_directory + config['model'] + '_df_metrics.csv', index=False)
df_metrics = {'Loss':hist}
df_metrics = pd.DataFrame(df_metrics)
df_metrics.to_csv(output_directory + '/' + model + '_' + 'df_metrics.csv', index=False)
else:
hist_df = pd.DataFrame(hist.history)
hist_df.to_csv(output_directory + config['model'] + '_history.csv', index=False)
hist_df.to_csv(output_directory + '/' + model + '_' + 'history.csv', index=False)
df_metrics = {'Accuracy': hist_df['accuracy'], 'Loss': hist_df['loss']}
df_metrics = pd.DataFrame(df_metrics)
df_metrics.to_csv(output_directory + config['model'] + '_df_metrics.csv', index=False)
df_metrics.to_csv(output_directory + '/' + model + '_' + 'df_metrics.csv', index=False)
index_best_model = hist_df['loss'].idxmin()
row_best_model = hist_df.loc[index_best_model]
......@@ -77,13 +76,12 @@ def save_logs(hist, output_directory=config['model_dir'], pytorch=False):
df_best_model['best_model_val_loss'] = row_best_model['val_loss']
df_best_model['best_model_train_acc'] = row_best_model['acc']
df_best_model['best_model_val_acc'] = row_best_model['val_acc']
df_best_model.to_csv(output_directory + config['model'] + '_df_best_model.csv', index=False)
df_best_model.to_csv(output_directory + '/' + model + '_' + 'df_best_model.csv', index=False)
# Save the model parameters (newly added without debugging)
def save_model_param(output_directory=config['model_dir'], pytorch=False):
def save_model_param(output_directory, model, pytorch=False):
if pytorch:
torch.save(net.state_dict(), output_directory + config['model'] + '_model.pth')
torch.save(net.state_dict(), output_directory + '/' + model + '_' + 'model.pth')
else:
classifier.save(output_directory + config['model'] + '_model.h5')
classifier.save(output_directory + '/' + model + '_' + 'model.h5')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment