<jupyter_start><jupyter_text>ANN to Predict a QuadrantUsing modal representation, can we imrprove on Santamaria-Granados, Luz, et al. "Using deep convolutional neural network for emotion detection on a physiological signals dataset (AMIGOS)." IEEE Access 7 (2018): 57-67.Another step forward from fingerprints, single subject??All, w\ augmentation, discrete Setup: Javascript and ipynb stuff<jupyter_code>%reload_ext autoreload
%autoreload 2
%matplotlib inline
%%javascript
utils.load_extension('collapsible_headings/main')
utils.load_extension('hide_input/main')
utils.load_extension('autosavetime/main')
utils.load_extension('execute_time/ExecuteTime')
utils.load_extension('code_prettify/code_prettify')
utils.load_extension('scroll_down/main')
utils.load_extension('jupyter-js-widgets/extension')<jupyter_output><empty_output><jupyter_text>Load Functions<jupyter_code>from fastai.vision import *
import os
import numpy as np
import pandas as pd
import pickle
import warnings; warnings.simplefilter('ignore')
path=pathlib.Path('/home/tris/Documents/EEG_data/DMD_DEAP')
path<jupyter_output><empty_output><jupyter_text>Load Original Data Labels<jupyter_code>path = '/media/tris/tris_files/EEG_datasets/DEAP_data_preprocessed_python/s01.dat'
df_read = pickle.load(open(path, 'rb'), encoding='latin1')
labels=df_read['labels']
df_tmp = pd.DataFrame(labels, columns=['valence','arousal','dominance','liking'])
df=df_tmp
for n in range (2,10):
    path = '/media/tris/tris_files/EEG_datasets/DEAP_data_preprocessed_python/s0'+str(n)+'.dat'
    df_read = pickle.load(open(path, 'rb'), encoding='latin1')
    labels=df_read['labels']
    df_tmp = pd.DataFrame(labels, columns=['valence','arousal','dominance','liking'])
    df=df.append(df_tmp, ignore_index=True)
for n in range (10,33):
    path = '/media/tris/tris_files/EEG_datasets/DEAP_data_preprocessed_python/s'+str(n)+'.dat'
    df_read = pickle.load(open(path, 'rb'), encoding='latin1')
    labels=df_read['labels']
    df_tmp = pd.DataFrame(labels, columns=['valence','arousal','dominance','liking'])
    df=df.append(df_tmp, ignore_index=True) 
df=df.div(9) #normalize
df.head()
df=df.loc[df.index.repeat(4)].reset_index(drop=True)
df.tail()<jupyter_output><empty_output><jupyter_text>Set filenames and labels<jupyter_code>filenames=[]
subject_labels=[]
for n in range (0,9):
    for i in range (0,9):
        filename='S'+str(n+1)+'T'+str(i+1)
        filenames.append(filename)
        subject_label=n+1
        subject_labels.append(subject_label)
    for i in range (9,160):
        filename='S'+str(n+1)+'T'+str(i+1)
        filenames.append(filename)
        subject_label=n+1
        subject_labels.append(subject_label)
for n in range (9,32):
    for i in range (0,9):
        filename='S'+str(n+1)+'T'+str(i+1)
        filenames.append(filename)
        subject_label=n+1
        subject_labels.append(subject_label)
    for i in range (9,160):
        filename='S'+str(n+1)+'T'+str(i+1)
        filenames.append(filename)
        subject_label=n+1
        subject_labels.append(subject_label)

df['file_name']=filenames
df['subject_label']=subject_labels
df=df[['file_name','subject_label','valence','arousal']]
df.tail()
# for i in range(1,33):
#     for ii in range(1,41):
#         os.rename(r'/media/tris/tris_files/github/OoMA-omniscient/data/processed/heatmaps_ind/heatmaps/T'+str(ii)+'S'+str(i)+".png",r'/media/tris/tris_files/github/OoMA-omniscient/data/processed/heatmaps_ind/heatmaps/S'+str(i)+'T'+str(ii)+".png")
# from PIL import Image

# for i in range (0,1280):
    
#     im = Image.open(r"/media/tris/tris_files/github/OoMA-omniscient/data/processed/heatmaps_ind/heatmaps/"+str(df.file_name[i])+".png")
#     im1=im.crop((0,0,1450,1030))
#     im1.save("/media/tris/tris_files/github/OoMA-omniscient/data/processed/heatmaps_ind/heatmaps_re/"+str(df.file_name[i])+".png")
df.loc[(df['valence'] >= 0.5) & (df['arousal'] >= 0.5), 'emotion_quad'] = 0  #HVHA
df.loc[(df['valence'] <= 0.5) & (df['arousal'] >= 0.5), 'emotion_quad'] = 1  #LVHA
df.loc[(df['valence'] <= 0.5) & (df['arousal'] <= 0.5), 'emotion_quad'] = 2 #LVLA  
df.loc[(df['valence'] >= 0.5) & (df['arousal'] <= 0.5), 'emotion_quad'] = 3  #HVLA
df.head()
# df.loc[(df['valence'] >= 0.5) & (df['arousal'] >= 0.5), 'emotion_quad'] = 'HVHA'  #HVHA
# df.loc[(df['valence'] <= 0.5) & (df['arousal'] >= 0.5), 'emotion_quad'] = 'LVHA'  #LVHA
# df.loc[(df['valence'] <= 0.5) & (df['arousal'] <= 0.5), 'emotion_quad'] = 'LVLA' #LVLA  
# df.loc[(df['valence'] >= 0.5) & (df['arousal'] <= 0.5), 'emotion_quad'] = 'HVLA'  #HVLA
# df.head()
# df=df.head(n=160)
df=df.reset_index(drop=True); df<jupyter_output><empty_output><jupyter_text>![GitHub Logo](https://www.researchgate.net/profile/Fadi_Al_Machot/publication/307587787/figure/fig3/AS:572907778318337@1513603266552/Arousal-valence-based-emotional-states.png)<jupyter_code>path=pathlib.Path('/media/tris/tris_files/EEG_datasets/DMD')
path
df.to_csv(path/'labels_proc_window4.csv', index=False)
df = pd.read_csv(path/'labels_proc_window4.csv') #load labels
df.tail()
df.hist()<jupyter_output><empty_output><jupyter_text>Data loader<jupyter_code>path=pathlib.Path('/media/tris/tris_files/EEG_datasets/DMD')
df = pd.read_csv(path/'labels_proc_window4.csv') #load labels
df.tail()
src = (ImageList.from_csv(path, 'labels_proc_window4.csv', folder='window_4times', suffix='.png')
       .split_by_rand_pct(0.2)
       .label_from_df(cols=['arousal']))
tfms=get_transforms(do_flip=False, flip_vert=False, max_rotate=0,max_zoom=1.1,max_lighting=0.3,p_affine=0)
data = (src.transform(tfms, size=250)
        .databunch(bs=4).normalize())
data.show_batch(rows=4, figsize=(12,9))<jupyter_output><empty_output><jupyter_text>Setup Network<jupyter_code>learn = cnn_learner(data, models.resnet50, metrics=root_mean_squared_error)
learn.summary()
learn.lr_find()
learn.recorder.plot()<jupyter_output><empty_output><jupyter_text>Train last layers<jupyter_code>lr = 3e-3
learn.fit_one_cycle(5, slice(lr))
learn.recorder.plot_metrics()
learn.recorder.plot_losses()<jupyter_output><empty_output><jupyter_text>Train the whole network<jupyter_code>learn.unfreeze()
learn.lr_find()
learn.recorder.plot()
lr = 5e-4
learn.fit_one_cycle(10, slice(lr))<jupyter_output><empty_output><jupyter_text>Interpret and Results<jupyter_code>learn.show_results()<jupyter_output><empty_output><jupyter_text>Ok, fully in the grind it out stage. Sit in this for a while, back to the drawing board.<jupyter_code>?? learn.show_results<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1727901614142967, 'fraction_numerical': 0.028285933897002305, 'mean_word_length': 6.318335208098987, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '337531', 'license': 'MIT', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2525, 'n_words': 346, 'path': 'src/models/2020-08-25_DEAP-DMD-quadrants-window_03.ipynb', 'repo_name': 'tdgriffith/OoMA-omniscient', 'size': '6505'}