This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyxdf | |
| import sys | |
| import numpy as np | |
| import os | |
| import matplotlib.pyplot as plt | |
| from scipy.io.wavfile import write | |
| # Quick script to check streams in XDF file | |
| def plot_channel(position, channel, eeg): | |
| plt.subplot(position) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pyxdf | |
| import numpy as np | |
| import os | |
| import argparse | |
| import csv | |
| import pandas as pd | |
| import shutil | |
| # Script that takes a XDF file and converts all the data to CSV files. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def box(image, boxes, class_names=None): | |
| colors = torch.FloatTensor([[1, 0, 1], [0, 0, 1], [0, 1, 1], [0, 1, 0], [1, 1, 0], [1, 0, 0]]); | |
| img = image.copy() | |
| width = img.shape[0] | |
| height = img.shape[1] | |
| for i in range(len(boxes)): | |
| box = boxes[i] | |
| x1,y1 = (box[0] - box[2] / 2.0) * width, (box[1] - box[3] / 2.0) * height |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Neek(nn.Module): | |
| def __init__(self): | |
| super().__init__() | |
| self.conv1 = Conv_Bn_Activation(1024, 512, 1, 1, 'leaky') | |
| self.conv2 = Conv_Bn_Activation(512, 1024, 3, 1, 'leaky') | |
| self.conv3 = Conv_Bn_Activation(1024, 512, 1, 1, 'leaky') | |
| # SPP | |
| self.maxpool1 = MaxPoolStride1(5) | |
| self.maxpool2 = MaxPoolStride1(9) | |
| self.maxpool3 = MaxPoolStride1(13) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Yolov4Head(nn.Module): | |
| def __init__(self): | |
| super().__init__() | |
| self.conv1 = Conv_Bn_Activation(128, 256, 3, 1, 'leaky') | |
| self.conv2 = Conv_Bn_Activation(256, 255, 1, 1, 'linear', bn=False) | |
| self.yolo1 = YoloLayer(anchor_mask=[0, 1, 2], num_classes=80, | |
| anchors=[12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401], | |
| num_anchors=9, stride=8) | |
| # R -4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Yolov4(nn.Module): | |
| def __init__(self): | |
| super().__init__() | |
| # backbone | |
| self.down1 = DownSample1() | |
| self.down2 = DownSample2() | |
| self.down3 = DownSample3() | |
| self.down4 = DownSample4() | |
| self.down5 = DownSample5() | |
| # neek |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #We load the image we want to create adversarial | |
| nb_image = 0 | |
| img = X_test[nb_image] | |
| #Get the correct label | |
| label = np.zeros(len(AGE_CLASS)) ; label[int(y_test[nb_image])] = 1. | |
| img = img.reshape(1,img.shape[0],img.shape[1],img.shape[2]) | |
| img = img.astype(np.float32) | |
| #Convert it into tensor | |
| tens = tf.convert_to_tensor(img) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| num_classes = len(AGE_CLASS) | |
| input_shape = (227,227,3) | |
| model = Sequential() | |
| model.add(Conv2D(32, kernel_size=(3, 3), activation='relu',input_shape=input_shape)) | |
| model.add(MaxPooling2D(pool_size=(3,3),strides=2)) | |
| model.add(BatchNormalization()) | |
| model.add(Conv2D(64, (3, 3), activation='relu')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AGE_CLASS = {'(0,2)':0,'(4,6)':1 | |
| ,'(8,13)':2,'(15,20)':3 | |
| ,'(25,32)':4,'(38,43)':5 | |
| ,'(48,53)':6,'(60,100)':7} | |
| #load images | |
| X_train, y_train = [], [] | |
| X_test, y_test = [], [] | |
| for image in os.listdir('train'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with h5py.File("./full_dataset_vectors.h5", "r") as hf: | |
| # Split the data into training/test features/targets | |
| X_train = hf["X_train"][:] | |
| targets_train = hf["y_train"][:] | |
| X_test = hf["X_test"][:] | |
| targets_test = hf["y_test"][:] | |
| # Determine sample shape | |
| sample_shape = (16, 16, 16, 3) |
NewerOlder