output_dir = "3d_conv_3l_" + str(begin_subject) + "_" + str( end_subject) + "_fc_" + str( fc_size) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d')) output_file = "3d_conv_3l_" + str(begin_subject) + "_" + str( end_subject) + "_fc_" + str( fc_size) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d')) os.system("mkdir " + result_dir + "/" + output_dir + " -p") ########################################################################### # build network ########################################################################### # instance cnn class cnn_3d = cnn() # input placeholder X = tf.placeholder( tf.float32, shape=[None, input_depth, input_height, input_width, input_channel_num], name='X') Y = tf.placeholder(tf.float32, shape=[None, num_labels], name='Y') keep_prob = tf.placeholder(tf.float32, name='keep_prob') # first CNN layer conv_1 = cnn_3d.apply_conv3d(X, kernel_depth_1st, kernel_height_1st, kernel_width_1st, input_channel_num, conv_channel_num, kernel_stride) # pool_1 = cnn_3d.apply_max_pooling3d(conv_1, pooling_depth, pooling_height, pooling_width, pooling_stride)
) + "_fc_" + str(n_fc_in) + "_RNN" + str(n_lstm_layers) + "_fc_" + str( n_fc_out) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d') + "_hs_" + str(n_hidden_state)) output_file = "win_" + str(window_size) + "_" + str(begin_subjec) + "_" + str( end_subject ) + "_fc_" + str(n_fc_in) + "_RNN" + str(n_lstm_layers) + "_fc_" + str( n_fc_out) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d') + "_hs_" + str(n_hidden_state)) os.system("mkdir " + result_dir + "/" + output_dir + " -p") ########################################################################### # build network ########################################################################### # instance cnn class rnn = cnn() # input placeholder X = tf.placeholder(tf.float32, shape=[None, n_time_step, n_input_ele], name='X') Y = tf.placeholder(tf.float32, shape=[None, num_labels], name='Y') keep_prob = tf.placeholder(tf.float32, name='keep_prob') ####################### input fully connected layer ########################## # X ==> [batch_size, n_time_step, n_input_ele] shape = X.get_shape().as_list() # X_flat ==> [batch_size*n_time_step, n_input_ele] X_flat = tf.reshape(X, [-1, shape[2]])
begin_subject) + "_" + str(end_subject) + "_fc_" + str( fc_size) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d')) output_file = str(cnn_dimension) + "d_conv_3l_" + str( begin_subject) + "_" + str(end_subject) + "_fc_" + str( fc_size) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d')) os.system("mkdir " + result_dir + "/" + output_dir + " -p") ########################################################################### # build network ########################################################################### # instance cnn class if (cnn_dimension == 1): cnn_1d = cnn() elif (cnn_dimension == 2): cnn_2d = cnn() elif (cnn_dimension == 3): cnn_3d = cnn() else: print( "******************* FATAL unknown dimension ! ! ! ********************" ) sys.exit() # input placeholder if (cnn_dimension == 1): X = tf.placeholder(tf.float32, shape=[None, input_width, input_channel_num], name='X')
learning_rate = 1e-5 # set maximum traing epochs training_epochs = 110 # set batch size batch_size = 10 # set dropout probability dropout_prob = 0.5 # set train batch number per epoch batch_num_per_epoch = features_train.shape[0]//batch_size # instance cnn class cnn_2d = cnn(padding='VALID') # input placeholder X = tf.placeholder(tf.float32, shape=[None, input_height, input_width, input_channel_num], name = 'X') Y = tf.placeholder(tf.float32, shape=[None, num_labels], name = 'Y') train_phase = tf.placeholder(tf.bool, name = 'train_phase') keep_prob = tf.placeholder(tf.float32, name='keep_prob') # first CNN layer conv_1 = cnn_2d.apply_conv2d(X, kernel_height_1st, kernel_width_1st, input_channel_num, conv_channel_num, kernel_stride, train_phase) pool_1 = cnn_2d.apply_max_pooling(conv_1, pooling_height_1st, pooling_width_1st, pooling_stride_1st) pool1_shape = pool_1.get_shape().as_list() pool1_flat = tf.reshape(pool_1, [-1, pool1_shape[1]*pool1_shape[2]*pool1_shape[3]]) fc_drop = tf.nn.dropout(pool1_flat, keep_prob)
# set maximum traing epochs training_epochs = 200 # set batch size batch_size = 10 # set dropout probability dropout_prob = 0.5 # set train batch number per epoch batch_num_per_epoch = train_x.shape[0] // batch_size # instance cnn class padding = 'VALID' cnn_2d = cnn(padding=padding) # input placeholder X = tf.placeholder(tf.float32, shape=[None, input_height, input_width, input_channel_num], name='X') Y = tf.placeholder(tf.float32, shape=[None, num_labels], name='Y') train_phase = tf.placeholder(tf.bool, name='train_phase') keep_prob = tf.placeholder(tf.float32, name='keep_prob') # first CNN layer conv_1 = cnn_2d.apply_conv2d(X, kernel_height_1st, kernel_width_1st, input_channel_num, conv_channel_num, kernel_stride, train_phase) print("conv 1 shape: ", conv_1.get_shape().as_list()) pool_1 = cnn_2d.apply_max_pooling(conv_1, pooling_height_1st,
regularization_method = 'dropout+l2' else: regularization_method = 'dropout' # result output result_dir = "/home/dadafly/experiment_result/eeg_physiobank_cnn_result" output_dir = "1d_conv_3l_"+str(begin_subjec)+"_"+str(end_subject)+"_fc_"+str(fc_size)+"_"+regularization_method+"_"+str(format(train_test_split*100, '03d')) output_file = "1d_conv_3l_"+str(begin_subjec)+"_"+str(end_subject)+"_fc_"+str(fc_size)+"_"+regularization_method+"_"+str(format(train_test_split*100, '03d')) os.system("mkdir "+result_dir+"/"+output_dir+" -p") ########################################################################### # build network ########################################################################### # instance cnn class cnn_1d = cnn() # input placeholder X = tf.placeholder(tf.float32, shape=[None, input_width, input_channel_num], name = 'X') Y = tf.placeholder(tf.float32, shape=[None, num_labels], name = 'Y') keep_prob = tf.placeholder(tf.float32, name='keep_prob') # first CNN layer conv_1 = cnn_1d.apply_conv1d(X, kernel_width_1st, input_channel_num, conv_channel_num, kernel_stride) # pool_1 = cnn_1d.apply_max_pooling(conv_1, pooling_height, pooling_width_1st, pooling_stride) # second CNN layer conv_2 = cnn_1d.apply_conv1d(conv_1, kernel_width_2nd, conv_channel_num, conv_channel_num*2, kernel_stride) # pool_2 = apply_max_pooling(conv_2, pooling_height, pooling_width_2nd, pooling_stride) # third CNN layer
output_dir = "2d_conv_3l_" + str(begin_subject) + "_" + str( end_subject) + "_fc_" + str( fc_size) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d')) output_file = "2d_conv_3l_" + str(begin_subject) + "_" + str( end_subject) + "_fc_" + str( fc_size) + "_" + regularization_method + "_" + str( format(train_test_split * 100, '03d')) os.system("mkdir " + result_dir + "/" + output_dir + " -p") ########################################################################### # build network ########################################################################### # instance cnn class cnn_2d = cnn() # input placeholder X = tf.placeholder(tf.float32, shape=[None, input_height, input_width, input_channel_num], name='X') Y = tf.placeholder(tf.float32, shape=[None, num_labels], name='Y') keep_prob = tf.placeholder(tf.float32, name='keep_prob') # first CNN layer conv_1 = cnn_2d.apply_conv2d(X, kernel_height_1st, kernel_width_1st, input_channel_num, conv_channel_num, kernel_stride) # pool_1 = cnn_1d.apply_max_pooling(conv_1, pooling_height, pooling_width_1st, pooling_stride) # second CNN layer