def get_precision_recall(results_path, output_file):

    results_path = os.path.normpath(results_path)
    results_name = os.path.split(results_path)[-1]
    outfile = open(output_file, "w")
    all_detections = []

    data_sequence_path = os.path.join(results_path, "detections.data_sequence")
    v000_path = os.path.join(results_path, "preRec")

    if os.path.exists(v000_path):
        print(v000_path, "already exists, skipping the generation step")
    else:
        # convert data sequence to caltech data format
        detections_to_caltech(data_sequence_path, v000_path)
        for f in glob.glob(os.path.join(v000_path, "*.txt")):
            all_detections.append(readDetection(f))
            all_detections = sorted(all_detections,
                                    key=lambda det: det[1],
                                    reverse=True)
            print(all_detections)

        tp = 0
        tn = 0
        fp = 0
        fn = 0
        for det in all_detections:
            if det[0] == "pos":
                if det[2]:
                    tp += 1
                else:
                    fn += 1

            if det[0] == "neg":
                if not det[2]:
                    tn += 1
                else:
                    fp += 1
            correct = tp + tn
            incorrect = fp + fn
            allDet = tp + fn
            pr = 5  #float(correct)/float(correct+incorrect)
            recall = 3  #float(correct)/allDet
            outfile.writelines(str(pr) + " " + str(recall) + "\n")
def get_precision_recall(results_path, output_file):

    results_path = os.path.normpath(results_path)
    results_name = os.path.split(results_path)[-1]
    outfile = open(output_file, "w")
    all_detections = []

    data_sequence_path = os.path.join(results_path, "detections.data_sequence")
    v000_path  = os.path.join(results_path, "preRec")

    if os.path.exists(v000_path):
        print(v000_path, "already exists, skipping the generation step")
    else:
        # convert data sequence to caltech data format
        detections_to_caltech(data_sequence_path, v000_path)
	for f in glob.glob(os.path.join(v000_path, "*.txt")):
		all_detections.append(readDetection(f))
		all_detections = sorted(all_detections, key=lambda det: det[1], reverse=True)
		print (all_detections)

	tp = 0
	tn = 0
	fp = 0
	fn = 0
	for det in all_detections:
		if det[0] =="pos":
			if det[2]:
				tp +=1
			else:
				fn +=1

		if det[0] =="neg":
			if not det[2]:
				tn +=1
			else:
				fp +=1
		correct = tp + tn
		incorrect = fp+fn
		allDet = tp + fn
		pr = 5#float(correct)/float(correct+incorrect)
		recall = 3#float(correct)/allDet
		outfile.writelines(str(pr) + " " + str(recall) + "\n")
def plot_caltech_evaluation(results_path, disable_show, exp_idx):

    results_path = os.path.normpath(results_path)
    results_name = os.path.split(results_path)[-1]

    data_sequence_path = os.path.join(results_path, "detections.data_sequence")
    v000_path = os.path.join(results_path, "V000")

    if os.path.exists(v000_path):
        print(v000_path, "already exists, skipping the generation step")
    else:
        # convert data sequence to caltech data format
        detections_to_caltech(data_sequence_path, v000_path)

    caltech_results_dir = os.path.join(caltech_data_dir,
                                       "data-INRIA/res/Ours-wip")

    set01_path = os.path.join(caltech_results_dir, "set01_" + results_name)
    set01_v000_path = os.path.join(set01_path, "V000")
    if os.path.exists(set01_v000_path):
        print(set01_v000_path, "already exists, skipping the copy step")
    else:
        os.mkdir(set01_path)
        shutil.copytree(v000_path, set01_v000_path)

    # update the set01 symbolic link
    set01_ln_path = os.path.join(caltech_results_dir, "set01")
    if os.path.exists(set01_ln_path):
        os.remove(set01_ln_path)
    os.symlink(set01_path, set01_ln_path)

    # clear previous evaluations
    caltech_eval_dir = os.path.join(caltech_evaluation_dir, "eval/InriaTest")
    caltech_result_dir = os.path.join(caltech_evaluation_dir, "results")
    paths_to_remove = glob.glob(os.path.join(caltech_eval_dir, "*"))
    for path in paths_to_remove:
        os.remove(path)

    # run the matlab code
    current_dir = os.getcwd()
    os.chdir(caltech_evaluation_dir)

    if False and (machine in visics_machines):
        global matlab_command
        matlab_command = matlab_command % exp_idx
    else:
        print("(options exp_idx was ignored)")

    print("Running:", matlab_command)
    subprocess.call(matlab_command, shell=True)
    os.chdir(current_dir)

    if False and ((machine in visics_machines) or (machine in d2_machines)):
        # copy and rename the the curve of our detector
        result_mat_path = os.path.join(set01_path,
                                       results_name + "Ours-wip.mat")
        shutil.copy(os.path.join(caltech_result_dir, "Ours-wip.mat"),
                    result_mat_path)

    # copy and rename the resulting pdf
    result_pdf_path = os.path.join(set01_path, results_name + "_roc.pdf")
    pdfname = "InriaTest roc exp=" + getExperimentName(exp_idx) + ".pdf"
    shutil.copy(os.path.join(caltech_result_dir, pdfname), result_pdf_path)

    # done
    print("Done creating the evaluation. Check out %s." % result_pdf_path)
    if not disable_show:
        subprocess.call("gnome-open %s" % result_pdf_path, shell=True)
    return
Exemplo n.º 4
0
def plot_caltech_evaluation(results_path, disable_show, exp_idx):

    results_path = os.path.normpath(results_path)
    results_name = os.path.split(results_path)[-1]

    data_sequence_path = os.path.join(results_path, "detections.data_sequence")
    vxxx_path = os.path.join(results_path, "Vxxx")
    print(results_name)

    if os.path.exists(vxxx_path):
        print(vxxx_path, "already exists, skipping the generation step")
    else:
        # convert data sequence to caltech data format
        detections_to_caltech(data_sequence_path, vxxx_path)

    caltech_evaluation_dir = "/esat/kochab/mmathias/caltech_pedestrian/evaluation/code3.0.0/"
    caltech_results_dir = os.path.join(caltech_evaluation_dir,
                                       "data-ETH/res/Ours-wip_" + results_name)
    print("caltech result directory:", caltech_results_dir)

    set01_path = os.path.join(caltech_results_dir, "setxxx_" + results_name)
    print("set01_path ", set01_path)
    for f in glob.glob(os.path.join(vxxx_path, "*.txt")):
        [p, txtname] = os.path.split(f)
        try:
            [a, b, c] = txtname.split('_')
        except:
            print('could not process the file: ', txtname)
            continue
        resfolder = os.path.join(caltech_results_dir, a, b)
        if not os.path.exists(resfolder):
            print(resfolder)
            os.makedirs(resfolder)
        shutil.copy(f, os.path.join(resfolder, c))

    # update the set01 symbolic link
    ln_path = os.path.join(caltech_evaluation_dir, "data-ETH/res/Ours-wip")
    os.remove(ln_path)
    os.symlink(caltech_results_dir, ln_path)
    print(caltech_results_dir)
    print(ln_path)

    #return

    # clear previous evaluations
    caltech_eval_dir = os.path.join(caltech_evaluation_dir, "data-ETH/eval")
    paths_to_remove = glob.glob(os.path.join(caltech_eval_dir, "*Ours-wip*"))
    for path in paths_to_remove:
        os.remove(path)

    # run the matlab code
    current_dir = os.getcwd()
    os.chdir(caltech_evaluation_dir)
    if at_visics:

        #matlab_command = 'matlab -nodisplay -r "dbEval ('+str(exp_idx)+'); quit"'
        matlab_command = 'matlab -nodisplay -r "dbEval ; quit"'
    else:
        matlab_command = 'octave --eval "dbEvalOctave; quit"'

    print("Running:", matlab_command)
    subprocess.call(matlab_command, shell=True)
    os.chdir(current_dir)

    # copy and rename the the curve of our detector
    #result_mat_path = os.path.join(set01_path, results_name + "Ours-wip.mat")
    #shutil.copy(os.path.join(caltech_eval_dir, "Ours-wip.mat"), result_mat_path)

    # copy and rename the resulting pdf
    result_pdf_path = os.path.join(caltech_results_dir, "output_roc.pdf")
    print("result pdf path", result_pdf_path)
    pdfname = "ETH roc exp=reasonable.pdf"
    print("pdfName: ", pdfname)
    print("from: ", os.path.join(caltech_evaluation_dir, "results", pdfname))
    shutil.copy(os.path.join(caltech_evaluation_dir, "results", pdfname),
                result_pdf_path)

    if at_visics:
        # copy and rename the the curve of our detector
        result_mat_path = os.path.join(caltech_results_dir, "Ours-wip.mat")
        shutil.copy(
            os.path.join(caltech_evaluation_dir, "results", "Ours-wip.mat"),
            result_mat_path)

    # done
    print("Done creating the evaluation. Check out %s." % result_pdf_path)
    if not disable_show:
        subprocess.call("gnome-open %s" % result_pdf_path, shell=True)
    return
def plot_caltech_evaluation(results_path, disable_show, exp_idx ):

    results_path = os.path.normpath(results_path)
    results_name = os.path.split(results_path)[-1]

    data_sequence_path = os.path.join(results_path, "detections.data_sequence")
    vxxx_path  = os.path.join(results_path, "Vxxx")
    print (results_name)

    if os.path.exists(vxxx_path):
        print(vxxx_path, "already exists, skipping the generation step")
    else:
        # convert data sequence to caltech data format
        detections_to_caltech(data_sequence_path, vxxx_path)

    caltech_evaluation_dir = "/esat/kochab/mmathias/caltech_pedestrian/evaluation/code3.0.0/"
    caltech_results_dir = os.path.join(caltech_evaluation_dir, "data-USA/res/Ours-wip_"+results_name)
    print(caltech_results_dir)
   
    
    set01_path = os.path.join(caltech_results_dir, "setxxx_" + results_name)
    for f in glob.glob(os.path.join(vxxx_path,"*.txt")):
        [p,txtname] = os.path.split(f)
        [a, b, c] = txtname.split('_')
        resfolder = os.path.join(caltech_results_dir, a, b)
        if not os.path.exists(resfolder):
            print(resfolder)
            os.makedirs(resfolder)
        shutil.copy(f, os.path.join(resfolder,c))




    # update the set01 symbolic link    
    ln_path = os.path.join(caltech_evaluation_dir, "data-USA/res/Ours-wip")
    os.remove(ln_path)
    os.symlink(caltech_results_dir, ln_path)

    # clear previous evaluations    
    caltech_eval_dir = os.path.join(caltech_evaluation_dir, "data-USA/eval")    
    paths_to_remove = glob.glob(os.path.join(caltech_eval_dir, "*Ours-wip*"))
    for path in paths_to_remove:
        os.remove(path)
    

    # run the matlab code
    current_dir = os.getcwd()
    os.chdir(caltech_evaluation_dir)
    if at_visics:
        #matlab_command = 'matlab -nodisplay -r "dbEval ('+str(exp_idx)+'); quit"'
        matlab_command = 'matlab -nodisplay -r "dbEval ; quit"'
    else:
        matlab_command = 'octave --eval "dbEvalOctave; quit"'
        
    print("Running:", matlab_command)
    subprocess.call(matlab_command, shell=True)
    os.chdir(current_dir)
    
	# copy and rename the the curve of our detector    
    #result_mat_path = os.path.join(set01_path, results_name + "Ours-wip.mat")    
    #shutil.copy(os.path.join(caltech_eval_dir, "Ours-wip.mat"), result_mat_path)

    # copy and rename the resulting pdf    
    result_pdf_path = os.path.join(caltech_results_dir, "output_roc.pdf")    
    print("result pdf path", result_pdf_path)
    pdfname = "UsaTest roc exp=reasonable.pdf"
    print ("pdfName: ", pdfname)
    print ("from: " , os.path.join(caltech_evaluation_dir, "results", pdfname))
    shutil.copy(os.path.join(caltech_evaluation_dir, "results", pdfname), result_pdf_path)

    
    # done
    print("Done creating the evaluation. Check out %s." % result_pdf_path)
    if not disable_show:
		subprocess.call("gnome-open %s" % result_pdf_path, shell=True)    
    return
def plot_caltech_evaluation(results_path, disable_show, exp_idx):

    results_path = os.path.normpath(results_path)
    results_name = os.path.split(results_path)[-1]

    data_sequence_path = os.path.join(results_path,
                                      "detections.data_sequence")
    v000_path = os.path.join(results_path, "V000")

    if os.path.exists(v000_path):
        print(v000_path, "already exists, skipping the generation step")
    else:
        # convert data sequence to caltech data format
        detections_to_caltech(data_sequence_path, v000_path)

    caltech_results_dir = os.path.join(caltech_data_dir,
                                       "data-INRIA/res/Ours-wip")

    set01_path = os.path.join(caltech_results_dir, "set01_" + results_name)
    set01_v000_path = os.path.join(set01_path, "V000")
    if os.path.exists(set01_v000_path):
        print(set01_v000_path, "already exists, skipping the copy step")
    else:
        os.mkdir(set01_path)
        shutil.copytree(v000_path, set01_v000_path)

    # update the set01 symbolic link
    set01_ln_path = os.path.join(caltech_results_dir, "set01")
    if os.path.exists(set01_ln_path):
        os.remove(set01_ln_path)
    os.symlink(set01_path, set01_ln_path)

    # clear previous evaluations
    caltech_eval_dir = os.path.join(caltech_evaluation_dir, "eval/InriaTest")
    caltech_result_dir = os.path.join(caltech_evaluation_dir, "results")
    paths_to_remove = glob.glob(os.path.join(caltech_eval_dir, "*"))
    for path in paths_to_remove:
        os.remove(path)

    # run the matlab code
    current_dir = os.getcwd()
    os.chdir(caltech_evaluation_dir)

    if False and (machine in visics_machines):
        global matlab_command
        matlab_command = matlab_command % exp_idx
    else:
        print("(options exp_idx was ignored)")

    print("Running:", matlab_command)
    subprocess.call(matlab_command, shell=True)
    os.chdir(current_dir)

    if False and ((machine in visics_machines) or (machine in d2_machines)):
        # copy and rename the the curve of our detector
        result_mat_path = os.path.join(set01_path,
                                       results_name + "Ours-wip.mat")
        shutil.copy(os.path.join(caltech_result_dir, "Ours-wip.mat"),
                    result_mat_path)

    # copy and rename the resulting pdf
    result_pdf_path = os.path.join(set01_path, results_name + "_roc.pdf")
    pdfname = "InriaTest roc exp=" + getExperimentName(exp_idx) + ".pdf"
    shutil.copy(os.path.join(caltech_result_dir, pdfname), result_pdf_path)

    # done
    print("Done creating the evaluation. Check out %s." % result_pdf_path)
    if not disable_show:
        subprocess.call("gnome-open %s" % result_pdf_path, shell=True)
    return
Exemplo n.º 7
0
def plot_caltech_evaluation(results_path, disable_show, exp_idx ):

    results_path = os.path.normpath(results_path)
    results_name = os.path.split(results_path)[-1]

    data_sequence_path = os.path.join(results_path, "detections.data_sequence")
    v000_path  = os.path.join(results_path, "V000")

    if os.path.exists(v000_path):
        print(v000_path, "already exists, skipping the generation step")
    else:
        # convert data sequence to caltech data format
        detections_to_caltech(data_sequence_path, v000_path)

    if at_visics:
        caltech_evaluation_dir = "/esat/enif/bgunyel/DataSets/CalTechEvaluation"
    else:            
         caltech_evaluation_dir = "/home/rodrigob/data/CalTechEvaluation_data"
    caltech_results_dir = os.path.join(caltech_evaluation_dir, "data-INRIA/res/Ours-wip")
    
    set01_path = os.path.join(caltech_results_dir, "set01_" + results_name)
    set01_v000_path = os.path.join(set01_path, "V000")
    if os.path.exists(set01_v000_path):
        print(set01_v000_path, "already exists, skipping the copy step")
    else:
        os.mkdir(set01_path)    
        shutil.copytree(v000_path, set01_v000_path)    

    # update the set01 symbolic link    
    set01_ln_path = os.path.join(caltech_results_dir, "set01")
    os.remove(set01_ln_path)
    os.symlink(set01_path, set01_ln_path)

    # clear previous evaluations    
    caltech_eval_dir = os.path.join(caltech_evaluation_dir, "data-INRIA/eval")    
    paths_to_remove = glob.glob(os.path.join(caltech_eval_dir, "*"))
    for path in paths_to_remove:
        os.remove(path)

    # run the matlab code
    current_dir = os.getcwd()
    os.chdir(caltech_evaluation_dir)
    if at_visics:
        matlab_command = 'matlab -nodisplay -r "dbEval ('+str(exp_idx)+'); quit"'
    else:
        #matlab_command = 'octave --eval "dbEvalOctave; quit"'
        matlab_command = '/home/rodrigob/Downloads/matlab_install/bin/matlab -nodisplay -r "dbEval; quit"'


    print("Running:", matlab_command)
    subprocess.call(matlab_command, shell=True)
    os.chdir(current_dir)
    
    if at_visics:
        # copy and rename the the curve of our detector    
        result_mat_path = os.path.join(set01_path, results_name + "Ours-wip.mat")    
        shutil.copy(os.path.join(caltech_eval_dir, "Ours-wip.mat"), result_mat_path)

    # copy and rename the resulting pdf    
    result_pdf_path = os.path.join(set01_path, results_name + "_roc.pdf")    
    pdfname = "INRIA roc exp=" + getExperimentName(exp_idx) +".pdf"
    shutil.copy(os.path.join(caltech_eval_dir, pdfname), result_pdf_path)

    
    # done
    print("Done creating the evaluation. Check out %s." % result_pdf_path)
    if not disable_show:
		subprocess.call("gnome-open %s" % result_pdf_path, shell=True)    
    return