<jupyter_start><jupyter_text><jupyter_code>#@title # Clone the repository and upgrade Keras {display-mode: "form"}

!git clone https://github.com/iamsoroush/DeepEEG.git
!pip install --upgrade keras
!rm -r DeepEEG
#@title # Imports {display-mode: "form"}

import os
import pickle
import sys
sys.path.append('DeepEEG')

PACKAGE_PARENT = '..'
SCRIPT_DIR = os.path.dirname(os.path.realpath(os.getcwd()))
sys.path.append(os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)))

import numpy as np

from deepeeg.helpers import CrossValidator
from deepeeg.models import DilatedDeepEEG
from deepeeg.dataset import DataLoader, Splitter, FixedLenGenerator

from google.colab import drive
drive.mount('/content/gdrive')
#@title # Set data path {display-mode: "form"}

#@markdown ---
#@markdown Type in the folder in your google drive that contains numpy _data_ folder:

parent_dir = 'soroush_deep_eeg'#@param {type:"string"}
gdrive_path =  os.path.abspath(os.path.join('gdrive/My Drive', parent_dir))
data_dir = os.path.join(gdrive_path, 'data')
cv_results_dir = os.path.join(gdrive_path, 'cross_validation')
if not os.path.exists(cv_results_dir):
    os.mkdir(cv_results_dir)

print('Data directory: ', data_dir)
print('Cross validation results dir: ', cv_results_dir)
#@title # Set Parameters

batch_size = 80
epochs = 50
k = 10
t = 10
instance_duration = 4 
instance_overlap = 1 
sampling_rate = 256 
n_channels = 19 
# task = 'rnr'
data_mode = 'cross_subject'<jupyter_output><empty_output><jupyter_text>RnR<jupyter_code>#@title ## DilatedDeepEEG-AttV2

task = 'rnr'
model_name = 'DilatedDeepEEG-AttV2'

train_generator = FixedLenGenerator(batch_size=batch_size,
                                    duration=instance_duration,
                                    overlap=instance_overlap,
                                    sampling_rate=sampling_rate,
                                    is_train=True)

test_generator = FixedLenGenerator(batch_size=8,
                                   duration=instance_duration,
                                   overlap=instance_overlap,
                                   sampling_rate=sampling_rate,
                                   is_train=False)

params = {'task': task,
          'data_mode': data_mode,
          'main_res_dir': cv_results_dir,
          'model_name': model_name,
          'epochs': epochs,
          'train_generator': train_generator,
          'test_generator': test_generator,
          't': t,
          'k': k,
          'channel_drop': True}

validator = CrossValidator(**params)

dataloader = DataLoader(data_dir,
                        task,
                        data_mode,
                        sampling_rate,
                        instance_duration,
                        instance_overlap)
data, labels = dataloader.load_data()

input_shape = (sampling_rate * instance_duration,
               n_channels)

model_obj = DilatedDeepEEG(input_shape,
                           model_name=model_name,
                           attention='v2')
model = model_obj.create_model()
model.summary()

scores = validator.do_cv(model_obj,
                         data,
                         labels)<jupyter_output><empty_output><jupyter_text>H-MDD<jupyter_code>#@title ## DilatedDeepEEG-AttV2

task = 'hmdd'
model_name = 'DilatedDeepEEG-AttV2'

train_generator = FixedLenGenerator(batch_size=batch_size,
                                    duration=instance_duration,
                                    overlap=instance_overlap,
                                    sampling_rate=sampling_rate,
                                    is_train=True)

test_generator = FixedLenGenerator(batch_size=8,
                                   duration=instance_duration,
                                   overlap=instance_overlap,
                                   sampling_rate=sampling_rate,
                                   is_train=False)

params = {'task': task,
          'data_mode': data_mode,
          'main_res_dir': cv_results_dir,
          'model_name': model_name,
          'epochs': epochs,
          'train_generator': train_generator,
          'test_generator': test_generator,
          't': t,
          'k': k,
          'channel_drop': True}

validator = CrossValidator(**params)

dataloader = DataLoader(data_dir,
                        task,
                        data_mode,
                        sampling_rate,
                        instance_duration,
                        instance_overlap)
data, labels = dataloader.load_data()

input_shape = (sampling_rate * instance_duration,
               n_channels)

model_obj = DilatedDeepEEG(input_shape,
                           model_name=model_name,
                           attention='v2')
model = model_obj.create_model()
model.summary()

scores = validator.do_cv(model_obj,
                         data,
                         labels)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09076142131979695, 'fraction_numerical': 0.0046700507614213195, 'mean_word_length': 2.0128440366972478, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '48858', 'license': 'MIT', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1417, 'n_words': 257, 'path': 'arch_attv2_tests_4s.ipynb', 'repo_name': 'iamsoroush/DeepEEG', 'size': '4925'}