Пример #1
0
# Training Parameters
learning_rate = 0.001
training_steps = 100
batch_size = 10
display_step = 1

# Network Parameters
num_input = 20  # data input (# signals)
# ~ timesteps = 1155 # timesteps
timesteps = 815  # timesteps
num_hidden = 128  # hidden layer num of features
num_classes = 2  # Two classes: Inter and pre

data_division = {}
patient_data = EEG.Patient_data(data_division, FLAGS.data_path)

# tf Graph input
X = tf.placeholder("float", [None, timesteps, num_input])
Y = tf.placeholder("float", [None, num_classes])


def RNN(x):
    # GPU version
    # ~ lstm_cuda = tf.contrib.cudnn_rnn.CudnnLSTM(1,num_hidden)
    # ~ outputs, _ = lstm_cuda(x)
    lstm_cell = tf.contrib.rnn.LSTMBlockCell(num_hidden, forget_bias=1.0)
    # ~ lstm_cell = tf.contrib.rnn.LSTMCell(num_hidden, forget_bias=1.0)
    outputs, _ = tf.nn.dynamic_rnn(cell=lstm_cell, inputs=x, dtype=tf.float32)
    # we take only the output at the last time
    # ~ fc_layer = tf.layers.dense(outputs[:,-1,:], 30, activation=tf.nn.relu)
Пример #2
0
import config
import FC
import TCN
import RNN
import CNN

flags = tf.flags
flags.DEFINE_string("data_path", None,
                    "Where the training/test data is stored.")
flags.DEFINE_string("NN", None, "Type of neural network.")
flags.DEFINE_string("patient", None, "Patient number")
FLAGS = flags.FLAGS
cfg = config.Config(data_path=FLAGS.data_path,
                    NN=FLAGS.NN,
                    patient=int(FLAGS.patient))
patient_data = EEG.Patient_data(cfg)
cfg.N_features = np.shape(patient_data.segments)[1]
tf.random.set_random_seed(1)

# tf Graph input
X = tf.placeholder("float", [None, 1, cfg.N_features, cfg.num_inputs])
Y = tf.placeholder("float", [None, cfg.num_classes])

if (cfg.NN == "TCN"):
    logits = TCN.TCN(X, cfg)
elif (cfg.NN == "FC"):
    logits = FC.FC(X, cfg)
elif (cfg.NN == "RNN"):
    logits = RNN.RNN(X, cfg)
elif (cfg.NN == "CNN"):
    logits = CNN.CNN(X, cfg)