Commit 9d483a45 authored by Ard Kastrati's avatar Ard Kastrati
Browse files

Fixed some small bugs

parent ab620b37
/.idea/
/venv/
*.pyc
.DS_Store
\ No newline at end of file
.DS_Store
/data/*
all_EEGprocuesan.mat
all_trialinfoprosan.mat
......@@ -6,6 +6,8 @@ import torch.optim as optim
import torch.utils.data
from utils.utils import *
from config import config
class Net(nn.Module):
def __init__(self):
......@@ -45,9 +47,9 @@ def run(trainX, trainY):
# PATH = '../cifar_net.pth'
# torch.save(net.state_dict(), PATH)
# Newly added lines below
save_logs(hist, config['model_dir'], config['model'], pytorch=True)
save_model_param(config['model_dir'], config['model'], 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=[]
......
......@@ -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, config['model_dir'], config['model'], pytorch=False)
save_model_param(config['model_dir'], config['model'], 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,
......
......@@ -10,9 +10,8 @@ def run(trainX, trainY):
hist = classifier.fit(trainX, trainY)
plot_loss(hist, 'Inception', True)
plot_acc(hist, 'Inception', True)
# Newly added lines below
save_logs(hist, config['model_dir'], config['model'], pytorch=False)
save_model_param(config['model_dir'], config['model'], 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,
......@@ -96,5 +95,5 @@ class Classifier_INCEPTION:
return model
def fit(self, inception_x, y):
hist = self.model.fit(inception_x, y, verbose=1, validation_split=0.2, epochs=10)
hist = self.model.fit(inception_x, y, verbose=1, validation_split=0.2, epochs=1)
return hist
\ No newline at end of file
......@@ -15,7 +15,8 @@ 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'] = '/cluster/home/your_username/data/'
# config['data_dir'] = '/cluster/home/your_username/data/'
config['data_dir'] = './'
config['data_dir_server'] = '/cluster/project/infk/zigeng/preprocessed2/'
# Path of root
config['root_dir'] = '.'
......@@ -35,7 +36,7 @@ deepeye: Our method
"""
# Choosing model
config['model'] = 'eegnet'
config['model'] = 'inception'
# CNN - 1
config['cnn'] = {}
......@@ -74,4 +75,6 @@ config['deepeye']['trainY_filename'] = "trialinfocuelocked"
# Create a unique output directory for this experiment.
timestamp = str(int(time.time()))
model_folder_name = timestamp if config['model'] == '' else timestamp + "_" + config['model']
config['model_dir'] = os.path.abspath(os.path.join(config['log_dir'], model_folder_name))
\ No newline at end of file
config['model_dir'] = os.path.abspath(os.path.join(config['log_dir'], model_folder_name))
if not os.path.exists(config['model_dir']):
os.makedirs(config['model_dir'])
\ No newline at end of file
......@@ -10,7 +10,8 @@ import numpy as np
def main():
start_time = time.time()
try:
trainX, trainY = IOHelper.get_data(config['data_dir'], verbose=True)
trainX, trainY = IOHelper.get_mat_data(config['data_dir'], verbose=True)
# trainX, trainY = IOHelper.get_pickle_data(config['data_dir'], verbose=True)
# IOHelper.store(trainX, trainY)
except:
return
......@@ -39,4 +40,4 @@ def main():
print("--- Runtime: %s seconds ---" % (time.time() - start_time))
if __name__=='__main__':
main()
main()
\ No newline at end of file
Accuracy,Loss
0.5900683403015137,0.6709842085838318
loss,accuracy,val_loss,val_accuracy
0.6709842085838318,0.5900683403015137,0.6837942004203796,0.6404416561126709
best_model_train_loss,best_model_val_loss,best_model_train_acc,best_model_val_acc
0.706407904624939,0.6844089031219482,0.5264661908149719,0.5702930688858032
Accuracy,Loss
0.5264661908149719,0.706407904624939
loss,accuracy,val_loss,val_accuracy
0.706407904624939,0.5264661908149719,0.6844089031219482,0.5702930688858032
File deleted
File deleted
......@@ -3,8 +3,30 @@ import numpy as np
import scipy.io as sio
import os
import pickle
import h5py
def get_data(data_dir, verbose=True):
def get_mat_data(data_dir, verbose=True):
with h5py.File(data_dir + 'all_EEGprocuesan.mat', 'r') as f:
X = f['all_EEGprocuesan'][:]
if verbose:
print("X training loaded.")
print(X.shape)
with h5py.File(data_dir + 'all_trialinfoprosan.mat', 'r') as f:
y = f['all_trialinfoprosan'][:]
if verbose:
print("y training loaded.")
print(y.shape)
if verbose: print("Setting the shapes")
X = np.transpose(X, (2, 1, 0))
y = np.transpose(y, (1, 0))
if verbose:
print(X.shape)
print(y.shape)
return X, y
def get_pickle_data(data_dir, verbose=True):
pkl_file_x = open(data_dir + 'x.pkl', 'rb')
x = pickle.load(pkl_file_x)
pkl_file_x.close()
......
......@@ -74,14 +74,14 @@ def save_logs(hist, output_directory, model, pytorch=False):
df_best_model['best_model_train_loss'] = row_best_model['loss']
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['best_model_train_acc'] = row_best_model['accuracy']
df_best_model['best_model_val_acc'] = row_best_model['val_accuracy']
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, model, pytorch=False):
if pytorch:
torch.save(net.state_dict(), output_directory + '/' + model + '_' + 'model.pth')
else:
classifier.save(output_directory + '/' + model + '_' + 'model.h5')
# def save_model_param(output_directory, model, pytorch=False):
# if pytorch:
# torch.save(net.state_dict(), output_directory + '/' + model + '_' + 'model.pth')
# else:
# classifier.save(output_directory + '/' + model + '_' + 'model.h5')
Supports Markdown
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