def __init__(self, network_type, iterations, window, input_size): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() if network_type == 'sd': self.config = self.VARS.get_config(input_size, 2, iterations, 100, network_type) convertion = self.VARS.CONVERTION_STATIC_DYNAMIC print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'original': self.config = self.VARS.get_config(input_size, 17, iterations, 100, network_type) convertion = self.VARS.CONVERTION_ORIGINAL print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'static': self.config = self.VARS.get_config(input_size, 5, iterations, 100, network_type) remove_activities = self.VARS.REMOVE_DYNAMIC_ACTIVITIES keep_activities = self.VARS.CONVERTION_STATIC self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, len(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'dynamic': remove_activities = self.VARS.CONVERTION_STATIC keep_activities = self.VARS.CONVERTION_DYNAMIC self.config = self.VARS.get_config(input_size, len(keep_activities), iterations, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, len(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'walk_stairs': remove_activities = self.VARS.CONVERTION_WALK_STAIRS_REMOVE keep_activities = self.VARS.CONVERTION_WALK_STAIRS self.config = self.VARS.get_config(input_size, len(keep_activities), iterations, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, len(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'shuf_stand': remove_activities = self.VARS.CONVERTION_SHUF_STAND_INVERSE keep_activities = self.VARS.CONVERTION_SHUF_STAND self.config = self.VARS.get_config(input_size, len(keep_activities), iterations, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, len(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'stand_sit': self.config = self.VARS.get_config(input_size, 3, iterations, 100, network_type) convertion = self.VARS.CONVERTION_STAND_SIT print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'lying': self.config = self.VARS.get_config(input_size, 2, iterations, 100, network_type) convertion = self.VARS.CONVERTION_LYING print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) self.cnn = CNN.CNN_TWO_LAYERS(self.config) self.cnn.set_data_set(self.data_set) self.cnn.train_network() self.cnn.save_model('models/' + network_type +'_'+ str(input_size))
def __init__(self, network_type, iterations, window, input_size): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() if network_type == 'sd': self.config = self.VARS.get_config(input_size, 2, iterations, 100, network_type) convertion = self.VARS.CONVERTION_STATIC_DYNAMIC print 'Creating data set' self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'original': self.config = self.VARS.get_config(input_size, 17, iterations, 100, network_type) convertion = self.VARS.CONVERTION_ORIGINAL print 'Creating data set' self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'static': self.config = self.VARS.get_config(input_size, 5, iterations, 100, network_type) remove_activities = self.VARS.REMOVE_DYNAMIC_ACTIVITIES keep_activities = self.VARS.CONVERTION_STATIC self.data_set = input_data_window_large.read_data_sets_without_activity( subject_set, len(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'dynamic': remove_activities = self.VARS.CONVERTION_STATIC keep_activities = self.VARS.CONVERTION_DYNAMIC self.config = self.VARS.get_config(input_size, len(keep_activities), iterations, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity( subject_set, len(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'shuf_stand': remove_activities = self.VARS.CONVERTION_SHUF_STAND_INVERSE keep_activities = self.VARS.CONVERTION_SHUF_STAND self.config = self.VARS.get_config(input_size, len(keep_activities), iterations, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity( subject_set, len(keep_activities), remove_activities, None, keep_activities, window) self.cnn = CNN.CNN_TWO_LAYERS(self.config) self.cnn.set_data_set(self.data_set) self.cnn.train_network() self.cnn.save_model('models/' + network_type + '_' + str(input_size))
def __init__(self, network_type, index, complete_set, window, input_size, conv_f_1, conv_f_2, nn_1, filter_type): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() convertion = self.VARS.CONVERTION_STATIC_DYNAMIC config = self.VARS.get_config(input_size, 2, index, 100, network_type, conv_f_1, conv_f_2, nn_1, filter_type) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type + '_' + str(input_size) + '_' + str(conv_f_1) + '_' + str(conv_f_2) + '_' + str(nn_1) + '_' + filter_type) if complete_set == 1: print self.cnn.test_network() elif complete_set == 2: print self.cnn.test_real_accuracy_on_network( self.data_set.test, window, input_size / 6, convertion) else: data = self.data_set.test.next_data_label(index) print data print np.argmax(data[1]) + 1, self.cnn.run_network(data)
def __init__(self, subject_set, config): self._info = "Convolutional neural network with two convolutional layers and a fully connected network" '''Config''' self._input_size = config['input_size'] self._output_size = config['output_size'] self._iteration_size = config['iteration_size'] self._batch_size = config['batch_size'] self._save_model_name = config['model_name'] self._load_model = config['model_name_load'] self._input_size_sqrt = int(self._input_size**0.5) '''Data set''' self._data_set = input_data_window_large.read_data_sets( subject_set, self._output_size) '''Default values''' # Conv1 self._bias_conv1 = 32 self._weight_conv1 = 32 # Conv2 self._bias_conv2 = 64 self._weight_conv2 = 64 # Neural network self._bias_neural1 = 1024 self._weight_neural1 = 1024 self._downsampled_twice = self._input_size_sqrt / 4 + 1 self._weight_neural_input1 = self._downsampled_twice * self._downsampled_twice * self._weight_conv2 self._weight_neural_input2 = 1024 '''Placeholders for input and output''' self.x = tf.placeholder("float", shape=[None, self._input_size]) self.y_ = tf.placeholder("float", shape=[None, self._output_size]) self.sess = None
def __init__(self, network_type, window, input_size, conv_f_1, conv_f_2, nn_1, filter_type): ''' CNN INIT''' self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() if network_type == 'sd': convertion = self.VARS.CONVERTION_STATIC_DYNAMIC config = self.VARS.get_config(input_size, 2, 1, 100, network_type, conv_f_1, conv_f_2, nn_1, filter_type) self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type+ '_' + str(input_size) + '_' + str(conv_f_1) + '_' + str(conv_f_2) + '_' + str(nn_1) + '_' + filter_type) ''' Segmenting part ''' # Get the predictions and save them window_list = [] data_length = self.data_set.test._num_examples for i in range(0,data_length): data = self.data_set.test.next_data_label(i) prediction = self.cnn.run_network([data[0]]) window_list.append(prediction) print 'Prediction finished' window_size = input_size / 6 # After an activity, add a timestamp segment_list = [0] for i in range(0, len(window_list)-1): if window_list[i] != window_list[i+1]: segment_list.append((i+1)*window_size) segment_list.append(len(window_list)*window_size) print segment_list
def __init__(self, window, input_size): self.input_size = input_size self.window = window self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() print 'Creating ORIGINAL data set' convertion = self.VARS.CONVERTION_ORIGINAL self.data_set_ORIGINAL = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window)
def __init__(self, network_type, index, complete_set, window, input_size): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() if network_type == 'sd': convertion = self.VARS.CONVERTION_STATIC_DYNAMIC config = self.VARS.get_config(input_size, 2, index, 100, network_type) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'original': convertion = self.VARS.CONVERTION_ORIGINAL config = self.VARS.get_config(input_size, 17, index, 100, network_type) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'static': remove_activities = self.VARS.REMOVE_DYNAMIC_ACTIVITIES keep_activities = self.VARS.CONVERTION_STATIC config = self.VARS.get_config(input_size, 5, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, self.VARS.len_convertion_list(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'dynamic': remove_activities = self.VARS.CONVERTION_STATIC keep_activities = self.VARS.CONVERTION_DYNAMIC config = self.VARS.get_config(input_size, 12, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, self.VARS.len_convertion_list(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'shuf_stand': remove_activities = self.VARS.CONVERTION_SHUF_STAND_INVERSE keep_activities = self.VARS.CONVERTION_SHUF_STAND config = self.VARS.get_config(input_size, 3, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, len(keep_activities), remove_activities, None, keep_activities, window) self.cnn = CNN.CNN_TWO_LAYERS(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type + '_' + str(input_size)) if complete_set: print self.cnn.test_network() else: data = self.data_set.test.next_data_label(index) print np.argmax(data[1])+1, self.cnn.run_network(data)
def __init__(self, network_type, index, models): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() convertion = self.VARS.CONVERTION_STATIC_DYNAMIC raw_signal_labels = get_raw_signal_labels(subject_set, convertion) df_results = pd.DataFrame(index=np.arange(len(models)), columns=np.arange(len(raw_signal_labels))) for i in range(0, len(models)): window_size = models[i][1] / 6 config = self.VARS.get_config(models[i][1], 2, index, 100, models[i][0], models[i][2], models[i][3], models[i][4], models[i][5]) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, models[i][6]) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + models[i][0] + '_' + str(models[i][1]) + '_' + str(models[i][2]) + '_' + str(models[i][3]) + '_' + str(models[i][4]) + '_' + models[i][5]) print "hei" print len(self.data_set.test._data) print models[i][1] / 6 for j in range(0, len(self.data_set.test._data)): data = [self.data_set.test._data[j]] prediction = self.cnn.sess.run(self.cnn.y_conv, feed_dict={ self.cnn.x: data, self.cnn.keep_prob: 1.0 }) prediction = np.argmax(prediction[0]) + 1 index = j * window_size df_results.iloc[i][index:index + window_size] = prediction print df_results df_max = df_results.mode() correct_instances = 0.0 for i in range(0, len(df_max.columns)): if df_max[i][0] == int(raw_signal_labels[i]): correct_instances += 1 print correct_instances print correct_instances / len(df_max.columns)
def __init__(self, network_type, iterations, window): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() self.config = self.VARS.get_config(576, 17, iterations, 100, network_type) convertion = self.VARS.CONVERTION_ORIGINAL print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, 17, convertion, None, window) self.cnn = CNN_MOD.CNN_MOD(self.config) self.cnn.set_data_set(self.data_set) self.cnn.train_network() self.cnn.save_model('models/' + network_type)
def __init__(self, network_type, index, complete_set, window, input_size): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() if network_type == 'sd': convertion = self.VARS.CONVERTION_STATIC_DYNAMIC config = self.VARS.get_config(input_size, 2, index, 100, network_type) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'original': convertion = self.VARS.CONVERTION_ORIGINAL config = self.VARS.get_config(input_size, 17, index, 100, network_type) print 'Creating data set' #self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) transition_remove_activties = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 10:10, 11:11, 12:12, 13:13, 14:14, 15:15, 16:16, 17:17} train_remove_activities = {9:9} self.data_set = input_data_window_large.read_EM_data_set(subject_set, 17, train_remove_activities, convertion, transition_remove_activties, window) if network_type == 'static': remove_activities = self.VARS.REMOVE_DYNAMIC_ACTIVITIES keep_activities = self.VARS.CONVERTION_STATIC config = self.VARS.get_config(input_size, 5, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, self.VARS.len_convertion_list(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'dynamic': remove_activities = self.VARS.CONVERTION_STATIC keep_activities = self.VARS.CONVERTION_DYNAMIC config = self.VARS.get_config(input_size, 12, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, self.VARS.len_convertion_list(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'shuf_stand': remove_activities = self.VARS.CONVERTION_SHUF_STAND_INVERSE keep_activities = self.VARS.CONVERTION_SHUF_STAND config = self.VARS.get_config(input_size, 3, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity(subject_set, len(keep_activities), remove_activities, None, keep_activities, window) self.cnn = CNN.CNN_TWO_LAYERS(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type + '_' + str(input_size)) if complete_set: print self.cnn.test_network() else: for i in range(0,100): #print self.data_set.test.next_data_label(i)[1] data = self.data_set.test.next_data_label(i) print np.argmax(data[1])+1, self.cnn.run_network(data)
def __init__(self, network_type, index, models): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() convertion = self.VARS.CONVERTION_ORIGINAL raw_signal_labels = get_raw_signal_labels(subject_set,convertion) df_results = pd.DataFrame(index = np.arange(len(raw_signal_labels)) ,columns=np.arange(len(models)*2+1)) for i in range(0,len(raw_signal_labels)): df_results[10][i] = raw_signal_labels[i]; for i in range(0,len(models)): window_size = models[i][1]/6 config = self.VARS.get_config(models[i][1], self.VARS.len_convertion_list(convertion), index, 100, models[i][0], models[i][2], models[i][3], models[i][4], models[i][5]) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, models[i][6]) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + models[i][0]+ '_' + str(models[i][1]) + '_' + str(models[i][2]) + '_' + str(models[i][3]) + '_' + str(models[i][4]) + '_' + models[i][5]) print "hei" print len(self.data_set.test._data) print models[i][1]/6 for j in range(0,len(self.data_set.test._data)): data = [self.data_set.test._data[j]] prediction = self.cnn.sess.run(self.cnn.y_conv, feed_dict={self.cnn.x: data ,self.cnn.keep_prob:1.0}) prob = np.max(prediction[0]) prediction = np.argmax(prediction[0])+1 index=j*window_size df_results[i*2][index:index+window_size] = prob df_results[i*2+1][index:index+window_size] = prediction print df_results np.savetxt('original_5_classifiers.csv', df_results, fmt='%s',delimiter=",") correct_instances = 0.0; for i in range(0,len(df_results.index)): highestProb=0 for j in range(0,len(df_results.columns)/2): if df_results[j*2][i]>highestProb: highestProb=df_results[j*2][i] prediction = df_results[j*2+1][i] if prediction == int(raw_signal_labels[i]): correct_instances += 1 print correct_instances print correct_instances / len(df_results.index)
def __init__(self, network_type, index, complete_set, window): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() convertion = self.VARS.CONVERTION_ORIGINAL config = self.VARS.get_config(576, 17, index, 100, network_type) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type) if complete_set: print self.cnn.test_network() else: data = self.data_set.test.next_data_label(index) print np.argmax(data[1]) + 1, self.cnn.run_network(data)
def __init__(self, network_type, index, models): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() convertion = self.VARS.CONVERTION_STATIC_DYNAMIC raw_signal_labels = get_raw_signal_labels(subject_set,convertion) df_results = pd.DataFrame(index = np.arange(len(models)),columns=np.arange(len(raw_signal_labels))) for i in range(0,len(models)): window_size = models[i][1]/6 config = self.VARS.get_config(models[i][1], 2, index, 100, models[i][0], models[i][2], models[i][3], models[i][4], models[i][5]) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, models[i][6]) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + models[i][0]+ '_' + str(models[i][1]) + '_' + str(models[i][2]) + '_' + str(models[i][3]) + '_' + str(models[i][4]) + '_' + models[i][5]) print "hei" print len(self.data_set.test._data) print models[i][1]/6 for j in range(0,len(self.data_set.test._data)): data = [self.data_set.test._data[j]] prediction = self.cnn.sess.run(self.cnn.y_conv, feed_dict={self.cnn.x: data ,self.cnn.keep_prob:1.0}) prediction = np.argmax(prediction[0])+1 index=j*window_size df_results.iloc[i][index:index+window_size] = prediction print df_results df_max = df_results.mode(); correct_instances = 0.0; for i in range(0,len(df_max.columns)): if df_max[i][0] == int(raw_signal_labels[i]): correct_instances += 1 print correct_instances print correct_instances / len(df_max.columns)
def __init__(self, network_type, index, complete_set, window, input_size, conv_f_1, conv_f_2, nn_1, filter_type): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() convertion = self.VARS.CONVERTION_STATIC_DYNAMIC config = self.VARS.get_config(input_size, 2, index, 100, network_type, conv_f_1, conv_f_2, nn_1, filter_type) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type+ '_' + str(input_size) + '_' + str(conv_f_1) + '_' + str(conv_f_2) + '_' + str(nn_1) + '_' + filter_type) if complete_set==1: print self.cnn.test_network() elif complete_set==2: print self.cnn.test_real_accuracy_on_network(self.data_set.test,window,input_size/6,convertion) else: data = self.data_set.test.next_data_label(index) print data print np.argmax(data[1])+1, self.cnn.run_network(data)
def __init__(self, network_type, window, input_size, conv_f_1, conv_f_2, nn_1, filter_type): ''' CNN INIT''' self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() if network_type == 'sd': convertion = self.VARS.CONVERTION_STATIC_DYNAMIC config = self.VARS.get_config(input_size, 2, 1, 100, network_type, conv_f_1, conv_f_2, nn_1, filter_type) self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type + '_' + str(input_size) + '_' + str(conv_f_1) + '_' + str(conv_f_2) + '_' + str(nn_1) + '_' + filter_type) ''' Segmenting part ''' # Get the predictions and save them window_list = [] data_length = self.data_set.test._num_examples for i in range(0, data_length): data = self.data_set.test.next_data_label(i) prediction = self.cnn.run_network([data[0]]) window_list.append(prediction) print 'Prediction finished' window_size = input_size / 6 # After an activity, add a timestamp segment_list = [0] for i in range(0, len(window_list) - 1): if window_list[i] != window_list[i + 1]: segment_list.append((i + 1) * window_size) segment_list.append(len(window_list) * window_size) print segment_list
def __init__(self, network_type, index, complete_set, window, input_size): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() if network_type == 'sd': convertion = self.VARS.CONVERTION_STATIC_DYNAMIC config = self.VARS.get_config(input_size, 2, index, 100, network_type) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) if network_type == 'original': convertion = self.VARS.CONVERTION_ORIGINAL config = self.VARS.get_config(input_size, 17, index, 100, network_type) print 'Creating data set' #self.data_set = input_data_window_large.read_data_sets(subject_set, self.VARS.len_convertion_list(convertion), convertion, None, window) transition_remove_activties = { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, 17: 17 } train_remove_activities = {9: 9} self.data_set = input_data_window_large.read_EM_data_set( subject_set, 17, train_remove_activities, convertion, transition_remove_activties, window) if network_type == 'static': remove_activities = self.VARS.REMOVE_DYNAMIC_ACTIVITIES keep_activities = self.VARS.CONVERTION_STATIC config = self.VARS.get_config(input_size, 5, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity( subject_set, self.VARS.len_convertion_list(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'dynamic': remove_activities = self.VARS.CONVERTION_STATIC keep_activities = self.VARS.CONVERTION_DYNAMIC config = self.VARS.get_config(input_size, 12, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity( subject_set, self.VARS.len_convertion_list(keep_activities), remove_activities, None, keep_activities, window) if network_type == 'shuf_stand': remove_activities = self.VARS.CONVERTION_SHUF_STAND_INVERSE keep_activities = self.VARS.CONVERTION_SHUF_STAND config = self.VARS.get_config(input_size, 3, index, 100, network_type) self.data_set = input_data_window_large.read_data_sets_without_activity( subject_set, len(keep_activities), remove_activities, None, keep_activities, window) self.cnn = CNN.CNN_TWO_LAYERS(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + network_type + '_' + str(input_size)) if complete_set: print self.cnn.test_network() else: for i in range(0, 100): #print self.data_set.test.next_data_label(i)[1] data = self.data_set.test.next_data_label(i) print np.argmax(data[1]) + 1, self.cnn.run_network(data)
def __init__(self, network_type, index, models): self.VARS = CNN_STATIC_VARIABLES.CNN_STATIC_VARS() subject_set = self.VARS.get_subject_set() convertion = self.VARS.CONVERTION_ORIGINAL raw_signal_labels = get_raw_signal_labels(subject_set, convertion) df_results = pd.DataFrame(index=np.arange(len(raw_signal_labels)), columns=np.arange(len(models) * 2 + 1)) for i in range(0, len(raw_signal_labels)): df_results[10][i] = raw_signal_labels[i] for i in range(0, len(models)): window_size = models[i][1] / 6 config = self.VARS.get_config( models[i][1], self.VARS.len_convertion_list(convertion), index, 100, models[i][0], models[i][2], models[i][3], models[i][4], models[i][5]) print 'Creating data set' self.data_set = input_data_window_large.read_data_sets( subject_set, self.VARS.len_convertion_list(convertion), convertion, None, models[i][6]) self.cnn = CNN_MOD.CNN_MOD(config) self.cnn.set_data_set(self.data_set) self.cnn.load_model('models/' + models[i][0] + '_' + str(models[i][1]) + '_' + str(models[i][2]) + '_' + str(models[i][3]) + '_' + str(models[i][4]) + '_' + models[i][5]) print "hei" print len(self.data_set.test._data) print models[i][1] / 6 for j in range(0, len(self.data_set.test._data)): data = [self.data_set.test._data[j]] prediction = self.cnn.sess.run(self.cnn.y_conv, feed_dict={ self.cnn.x: data, self.cnn.keep_prob: 1.0 }) prob = np.max(prediction[0]) prediction = np.argmax(prediction[0]) + 1 index = j * window_size df_results[i * 2][index:index + window_size] = prob df_results[i * 2 + 1][index:index + window_size] = prediction print df_results np.savetxt('original_5_classifiers.csv', df_results, fmt='%s', delimiter=",") correct_instances = 0.0 for i in range(0, len(df_results.index)): highestProb = 0 for j in range(0, len(df_results.columns) / 2): if df_results[j * 2][i] > highestProb: highestProb = df_results[j * 2][i] prediction = df_results[j * 2 + 1][i] if prediction == int(raw_signal_labels[i]): correct_instances += 1 print correct_instances print correct_instances / len(df_results.index)
6: 2, 7: 2, 8: 2, 9: 1, 10: 1, 11: 1, 12: 1, 13: 1, 14: 1, 15: 1, 16: 2, 17: 2 } number_of_labels = len(set(convertion.values())) data_set_1 = input_data_window_large.read_data_sets(subject_set, number_of_labels, convertion, None) #data_set_1 = input_data.read_data_sets("MNIST_data/", one_hot=True) nn = Simple_network(data_set_1, 2, 'model_1') #nn.train_network() #nn.test_network() #nn.save_variables("model_1") nn.load_model('model_1') nn.test_network() convertion_2 = { 1: 1, 2: 2, 3: 3,
self.sess.run(self.init) for i in range(1000): batch_xs, batch_ys = self.data_set.train.next_batch(100) self.sess.run(self.train_step, feed_dict={self.x: batch_xs, self.y_: batch_ys}) def test_network(self): correct_prediction = tf.equal(tf.argmax(self.y,1), tf.argmax(self.y_,1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")) print(self.sess.run(accuracy, feed_dict={self.x: self.data_set.test.data, self.y_: self.data_set.test.labels})) train_subjects = ["P03","P04"]#,"P06","P07","P08","P09","P10","P14","P15","P16","P17","P18","P19","P20","P21"] test_subjects = ["P11"]#,"P04","P06","P07","P08","P09","P10","P14","P15","P16","P17","P18","P19","P20","P21"] subject_set = [train_subjects, test_subjects] convertion = {1:1, 2:1, 3:1, 4:1, 5:1, 6:2, 7:2, 8:2, 9:1, 10:1, 11:1, 12:1, 13:1, 14:1, 15:1, 16:2, 17:2} number_of_labels = len(set(convertion.values())) data_set_1 = input_data_window_large.read_data_sets(subject_set, number_of_labels, convertion, None) #data_set_1 = input_data.read_data_sets("MNIST_data/", one_hot=True) nn = Simple_network(data_set_1,2,'model_1') #nn.train_network() #nn.test_network() #nn.save_variables("model_1") nn.load_model('model_1') nn.test_network() convertion_2 = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8, 9:9, 10:10, 11:11, 12:12, 13:13, 14:14, 15:15, 16:16, 17:17} number_label_2 = len(set(convertion_2.values())) data_set_2 = input_data_window_large.read_data_sets(subject_set, number_label_2, convertion_2, None)