def convert_file(): # for i in range(len(files)): for i in range(1): file_x = open((FOLDER + files[i]), 'r') if not exists(SAVE_FOLDER): mkdir(SAVE_FOLDER) training_file = open((SAVE_FOLDER + "TR - " + files[i]), 'w') test_file = open((SAVE_FOLDER + "TE - " + files[i]), 'w') count_file = open((SAVE_FOLDER + "N - " + files[i]), 'w') lines_x = file_x.readlines() d, p, s, h, r = 0, 0, 0, 0, 0 test = lines_x[0].split(",") w_line = [] w_line.append(str(range(0, len(test) - 1)).replace("[", "").replace("]", "") + ", Phase\n") for index in range(len(lines_x)): # print(lines_x[index], " " + str(len(lines_x[index])), " ", lines_x[index][len(lines_x[index]) - 2:len(lines_x[index]) - 1]) char = lines_x[index][len(lines_x[index]) - 2:len(lines_x[index]) - 1] if char == "D": d += 1 if char == "P": p += 1 if char == "S": s += 1 if char == "H": h += 1 if char == "R": r += 1 w_line.append(lines_x[index].replace(char, Pds.convert_target_name(char))) count_line = ("D = " + str(d) + "\n" + "P = " + str(p) + "\n" + "S = " + str(s) + "\n" + "H = " + str(h) + "\n" + "R = " + str(r)) count_file.write(count_line) count_file.close() for index in range(0, (int(len(w_line) * 0.7))): training_file.write(w_line[index]) training_file.close() for index in range(int(len(w_line) * 0.7), len(w_line)): test_file.write(w_line[index]) test_file.close()
hoopPos = np.zeros((2, 2), np.int) # hoopPos = LabelFunc.getHoopPosition(label_vFn) # hoopPos = np.array([[865, 79], [965, 179]]) # ball1 # hoopPos = np.array([[505, 272], [555, 322]]) # ball3 if task == 'label': LabelFunc.labelGoalFrames(label_vFn, hoopPos, label_vAnnFile) elif task == 'crop': LabelFunc.cropHoop(crop_vFn, hoopPos, crop_vAnnFile, outDIRPos, outDIRNeg) elif task == 'compose': PictureCombine.image_compose(outDIRPos, int(crop_size), int(crop_row), int(crop_column), crop_pos_save) PictureCombine.image_compose(outDIRNeg, int(crop_size), int(crop_row), int(crop_column), crop_neg_save) PrepareDataSet.select_test_img(crop_pos_save, crop_neg_save, test_path, train_pkl, test_pkl) elif task == 'training': hog_center = np.mean(HogFeature.compute_hog(train_path), 0) HogFeature.test_distance(hog_center, center_pos_path, pos_distance_path) HogFeature.test_distance(hog_center, center_neg_path, neg_distance_path) HogFeature.test_distance(hog_center, test_path, test_distance_path) elif task == 'ROC': pos_distance = ReadFile.load_distance(pos_distance_path) neg_distance = ReadFile.load_distance(neg_distance_path) threshold_values = ReadFile.get_threshold(pos_distance, neg_distance) test_data = ReadFile.load_distance(test_distance_path) test_img, test_label = ReadFile.load_pkl(test_pkl) test_label = np.array(test_label, dtype=int) ROC.plotROC(test_data, test_label, threshold_values)
y = var_exp x = [i for i in range(len(eigen_values))] soma = 0 for index in range(15): soma += var_exp[index] print soma plt.plot(x, y, linestyle='--', marker='o', color='b') plt.ylabel("Porcentagem de Representacao") plt.xlabel("Indice dos Autovalores") plt.show() dataset = pds.get_dataset(pds.FILE) reduced_matrix = execute(dataset) print ("final", reduced_matrix) # with open(pds.PATH+"/a1_va3_reducedR.csv", 'w') as csvw: # csvw = csv.writer(csvw, delimiter=',') # csvw.writerows(reduced_matrix) np.savetxt(pds.FILE_REDUCED, reduced_matrix, delimiter=',', fmt='%.8f') print('y', dataset['y']) outf = open(pds.FILE_REDUCED_PRED, 'w') for index in range(len(dataset['y'])):