def online_test(path, gesture_id): results_folder_name = os.path.basename(os.path.splitext(path)[0]) full_path = 'online_results/' + results_folder_name if not os.path.exists(full_path): os.makedirs(full_path) data_set = FilesUtil.generate_data_set_from_file(path) start = 0 end = 149 errors = list() values = list() predictions = list() for i in range(len(data_set)): if end < len(data_set): current = data_set[start:end] x_new, y_pre = evaluate_rnn_model( current.values, str(gesture_id), CONFIG.get_neurons_dim(gesture_id)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) errors.append( np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) values.append(x_new) predictions.append(y_pre) current, start, end = FilesUtil.get_next_window(current, dimension=150, start=start, end=end) print( "done " + str(i) + " of " + len(data_set).__str__() + " error " + str(np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) + " gesture " + str(gesture_id)) FilesUtil.save_results_to_file( errors, os.path.basename(os.path.splitext(path)[0]), gesture_id) return errors, values, predictions
def evaluate_model(gesture_id): outer_list = list() for data_set in enumerate(CONFIG.UNI_GE_DATA_SETS): inner_list = list() for i in range(CONFIG.evaluation_runs): train_set, test_set, validation = FilesUtil.split_data_set( CONFIG.get_path(data_set[1]), CONFIG.train_space) x_new, y_pre = evaluate_rnn_model( FilesUtil.get_random_file(test_set), str(gesture_id), CONFIG.get_neurons_dim(gesture_id)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) inner_list.append( np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) # main_index = data_set[1] # result_dictionary[main_index][i] = outer_list.append(inner_list) return DataFrame(outer_list, index=[1, 2, 5, 6, 7, 8])
def test(): for i in range(CONFIG.evaluation_runs): train_set, test_set, valid = FilesUtil.split_data_set( CONFIG.get_path(1), CONFIG.train_space) x_new, y_pre = evaluate_rnn_model( FilesUtil.get_random_file(test_set), str(1), CONFIG.get_neurons_dim(1)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) print(np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) print("----------------------------------------------------") for i in range(CONFIG.evaluation_runs): train_set, test_set, valid = FilesUtil.split_data_set( CONFIG.get_path(2), CONFIG.train_space) x_new, y_pre = evaluate_rnn_model( FilesUtil.get_random_file(test_set), str(1), CONFIG.get_neurons_dim(1)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) print(np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) print("----------------------------------------------------") for i in range(CONFIG.evaluation_runs): train_set, test_set, valid = FilesUtil.split_data_set( CONFIG.get_path(5), CONFIG.train_space) x_new, y_pre = evaluate_rnn_model( FilesUtil.get_random_file(test_set), str(1), CONFIG.get_neurons_dim(1)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) print(np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) print("----------------------------------------------------") for i in range(CONFIG.evaluation_runs): train_set, test_set, valid = FilesUtil.split_data_set( CONFIG.get_path(6), CONFIG.train_space) x_new, y_pre = evaluate_rnn_model( FilesUtil.get_random_file(test_set), str(1), CONFIG.get_neurons_dim(1)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) print(np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) print("----------------------------------------------------") for i in range(CONFIG.evaluation_runs): train_set, test_set, valid = FilesUtil.split_data_set( CONFIG.get_path(7), CONFIG.train_space) x_new, y_pre = evaluate_rnn_model( FilesUtil.get_random_file(test_set), str(1), CONFIG.get_neurons_dim(1)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) print(np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z)) print("----------------------------------------------------") for i in range(CONFIG.evaluation_runs): train_set, test_set, valid = FilesUtil.split_data_set( CONFIG.get_path(8), CONFIG.train_space) x_new, y_pre = evaluate_rnn_model( FilesUtil.get_random_file(test_set), str(1), CONFIG.get_neurons_dim(1)) mse_x = get_mse(x_new[0][1:, 0], y_pre[0][:-1, 0]) mse_y = get_mse(x_new[0][1:, 1], y_pre[0][:-1, 1]) mse_z = get_mse(x_new[0][1:, 2], y_pre[0][:-1, 2]) print(np.sqrt(mse_x * mse_x + mse_y * mse_y + mse_z * mse_z))