def main(): prs = [] rocs = [] times = [] with Parallel(n_jobs=4, verbose=11, backend='multiprocessing') as parallel_pool: for index in range(ITERATIONS): print('ITERATION #%s' % str(index+1)) start_time = time.time() pr, roc = hplsfacev(args, parallel_pool) end_time = time.time() abs_time = (end_time - start_time) / FOLD prs.append(pr) rocs.append(roc) times.append(abs_time) prs_f, rocs_f = iteration_to_fold(prs, rocs) with open('./files/' + OUTPUT_NAME + '.file', 'w') as outfile: pickle.dump([prs_f, rocs_f], outfile) for index in range(len(prs_f)): plot_precision_recall(prs_f[index], OUTPUT_NAME + '_fold_' + str(index + 1)) for index in range(len(rocs_f)): plot_roc_curve(rocs_f[index], OUTPUT_NAME + '_fold_' + str(index + 1)) with open('./times/' + OUTPUT_NAME + '.time', 'a') as outtime: outtime.write(str(abs_time) + '\n') with open('./times/' + OUTPUT_NAME + '.time', 'a') as outtime: outtime.write('------\n') outtime.write(str(np.mean(times)) + '\n') outtime.write(str(np.std(times)) + '\n')
def main(): os_cmcs = [] oaa_cmcs = [] dets = [] prs = [] rocs = [] fscores = [] with Parallel(n_jobs=-2, verbose=11, backend='multiprocessing') as parallel_pool: for index in range(ITERATIONS): print('ITERATION #%s' % str(index + 1)) os_cmc, oaa_cmc, det, pr, roc, fscore = plshface( args, parallel_pool) os_cmcs.append(os_cmc) oaa_cmcs.append(oaa_cmc) dets.append(det) prs.append(pr) rocs.append(roc) fscores.append(fscore) with open('./files/' + OUTPUT_NAME + '.file', 'w') as outfile: pickle.dump([prs, rocs], outfile) plot_cmc_curve(os_cmcs, oaa_cmcs, OUTPUT_NAME) plot_det_curve(dets, OUTPUT_NAME) plot_precision_recall(prs, OUTPUT_NAME) plot_roc_curve(rocs, OUTPUT_NAME) means = mean_results(fscores) with open('./values/' + OUTPUT_NAME + '.txt', 'a') as outvalue: for item in fscores: outvalue.write(str(item) + '\n') for item in means: outvalue.write(str(item) + '\n') print(fscores)
def main(): PATH = str(args.path) DATASET = str(args.file) ITERATIONS = int(args.rept) KNOWN_SET_SIZE = float(args.known_set_size) TRAIN_SET_SIZE = float(args.train_set_size) NUM_HASH = int(args.hash) DATASET = DATASET.replace('-FEATURE-VECTORS.bin', '') OUTPUT_NAME = 'HSVM_' + DATASET + '_' + str(NUM_HASH) + '_' + str( KNOWN_SET_SIZE) + '_' + str(TRAIN_SET_SIZE) + '_' + str(ITERATIONS) prs = [] rocs = [] with Parallel(n_jobs=-2, verbose=11, backend='multiprocessing') as parallel_pool: for index in range(ITERATIONS): print('ITERATION #%s' % str(index + 1)) pr, roc = svmhface(args, parallel_pool) prs.append(pr) rocs.append(roc) with open('./files/' + OUTPUT_NAME + '.file', 'w') as outfile: pickle.dump([prs, rocs], outfile) plot_precision_recall(prs, OUTPUT_NAME) plot_roc_curve(rocs, OUTPUT_NAME)
def main(): fscores = [] prs = [] rocs = [] with Parallel(n_jobs=1, verbose=15, backend='multiprocessing') as parallel_pool: for index in range(ITERATIONS): keras_backend.clear_session() keras_session = tensorflow.Session() keras_backend.set_session(keras_session) print('ITERATION #%s' % str(index + 1)) pr, roc, fscore = fcnhface(args, parallel_pool) fscores.append(fscore) prs.append(pr) rocs.append(roc) with open('./files/plot_' + OUTPUT_NAME + '.file', 'w') as outfile: pickle.dump([prs, rocs], outfile) plot_precision_recall(prs, OUTPUT_NAME) plot_roc_curve(rocs, OUTPUT_NAME) means = mean_results(fscores) with open('./values/' + OUTPUT_NAME + '.txt', 'a') as outvalue: for item in fscores: outvalue.write(str(item) + '\n') for item in means: outvalue.write(str(item) + '\n') print(fscores)
def main(): PATH = str(args.path) DATASET = str(args.file) DESCRIPTOR = str(args.desc) ITERATIONS = int(args.rept) NUM_HASH = int(args.hash) OUTPUT_NAME = 'OC-SVM_' + DATASET.replace( '.txt', '') + '_' + str(NUM_HASH) + '_' + DESCRIPTOR + '_' + str(ITERATIONS) prs = [] rocs = [] for index in range(ITERATIONS): print('ITERATION #%s' % str(index + 1)) pr, roc = svm_oneclass(args) prs.append(pr) rocs.append(roc) with open('./files/' + OUTPUT_NAME + '.file', 'w') as outfile: pickle.dump([prs, rocs], outfile) plot_precision_recall(prs, OUTPUT_NAME) plot_roc_curve(rocs, OUTPUT_NAME)
import os import pickle from auxiliar import generate_precision_recall, plot_precision_recall from auxiliar import generate_roc_curve, plot_roc_curve path_files = os.listdir('./') print path_files for file in path_files: if file.endswith('.file'): file_path = './' + file with open(file_path) as infile: file_prs, file_rocs = pickle.load(infile) plot_precision_recall(file_prs, file_path.replace('.file', '.jpg')) plot_roc_curve(file_rocs, file_path.replace('.file', '.jpg'))