在windows平台上测试自己的人脸检测算法在FDDB数据集

弄了好几天终于能在FDDB数据集上测试自己用wider face数据集训练的的faster rcnn的检测器的性能了。


1、首先在官网http://vis-www.cs.umass.edu/fddb/index.html下载图片和标注文件,FDDB的标注文件,分为图片名称文件FDDB-fold-01.txt、对应的标注文件:FDDB-fold-01-ellispe.txt,各有10个,把10个文件按顺序合并,分别命名为Fold_all.txt和Elsp.txt.


2、读Fold.txt文件,依照顺序做人脸检测,将检测结果输出出来(我是将faster rcnn中test.py文件修改得到的检测结果)。


3、我的mxnet的faster rcnn生成的检测结果格式为<image name i> score x1 y1 x2 y2,与FDDB要求的格式http://vis-www.cs.umass.edu/fddb/README.txt不一致,所以写了个C++程序将我的输出格式转化为FDDB要求的格式

// ToFDDBResults.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<vector>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	ifstream InputFile("comp4_det_Foldall_face.txt");
	ofstream OutputFile("comp4_det_Foldall_face_results.txt");
	string line, ImageNameTemp;
	stringstream ss;
	int count = 1;
	vector<double> vec_score;
	vector<double> vec_x1;
	vector<double> vec_y1;
	vector<double> vec_x2;
	vector<double> vec_y2;
	
	double score, x1, y1, x2, y2;
	string ImageName;
	getline(InputFile, line);
	ss << line;
	ss >> ImageName >> score >> x1 >> y1 >> x2 >> y2;
	vec_score.push_back(score);
	vec_x1.push_back(x1);
	vec_y1.push_back(y1);
	vec_x2.push_back(x2);
	vec_y2.push_back(y2);
	ImageNameTemp = ImageName;


	while (getline(InputFile, line))
	{
		ss.str("");
		ss.clear();
		ss << line;
		ss >> ImageName >> score >> x1 >> y1 >> x2 >> y2;
		if (ImageName == ImageNameTemp)
		{
			count++;
			vec_score.push_back(score);
			vec_x1.push_back(x1);
			vec_y1.push_back(y1);
			vec_x2.push_back(x2);
			vec_y2.push_back(y2);
		}
		else
		{
			OutputFile << ImageNameTemp << endl;
			OutputFile << count << endl;
			count = 1;
			for (int i = 0; i < vec_score.size(); i++)
			{
				OutputFile << vec_x1[i] << " " << vec_y1[i] << " " << (vec_x2[i] - vec_x1[i]) << " "
					<< (vec_y2[i] - vec_y1[i]) << " " << vec_score[i] << endl;

			}
			vec_score.clear();
			vector<double>(vec_score).swap(vec_score);
			vec_x1.clear();
			vector<double>(vec_x1).swap(vec_x1);
			vec_y1.clear();
			vector<double>(vec_y1).swap(vec_y1);
			vec_x2.clear();
			vector<double>(vec_x2).swap(vec_x2);
			vec_y2.clear();
			vector<double>(vec_y2).swap(vec_y2);
			vec_score.push_back(score);
			vec_x1.push_back(x1);
			vec_y1.push_back(y1);
			vec_x2.push_back(x2);
			vec_y2.push_back(y2);
		}
		ImageNameTemp = ImageName;
	}
	OutputFile << ImageName << endl;
	OutputFile << count << endl;
	for (int i = 0; i < vec_score.size(); i++)
	{
		OutputFile << vec_x1[i] << " " << vec_y1[i] << " " << (vec_x2[i] - vec_x1[i]) << " "
			<< (vec_y2[i] - vec_y1[i]) << " " << vec_score[i] << endl;

	}

	return 0;
}

4、在 http://vis-www.cs.umass.edu/fddb/results.html下载fddb evaluate代码,新建一个vs工程,配置好OPENCV,把evaluate中的源文件和头文件加进来,修改evaluate.cpp文件73行

string baseDir = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/";//FDDB图片路径,此路径下需包含文件夹2002,2003
  string listFile = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/fddb/Fold_all.txt";
  string detFile = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/fddb/comp4_det_Foldall_face_results.txt";//转化了格式后的结果文件
  string annotFile = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/fddb/Elsp.txt";
因为我直接在vs上运行,不在cmd上运行这个evaluate程序,所以注释以下几行 代码:

 //if(argc == 1)
  //{
  //  printUsage();
  //  return 0;
  //}
在项目的属性栏中做如下改动

编译,通过。生成ContROC.txt和 DiscROC.txt两个文件

5、安装GUNPLOT,我装的gp501-win32-mingw,

配置perl,参考https://jingyan.baidu.com/article/9f7e7ec0b798ae6f281554e9.html?st=2&os=0&bd_page_type=1&net_type=1安装好之后,修改下载的evaluate代码中的runEvaluate.pl文件:

#!/usr/bin/perl -w

use strict;

#### VARIABLES TO EDIT ####
# where gnuplot is
my $GNUPLOT = "C:/Program Files (x86)/gnuplot/bin/gnuplot"; #gnuplot安装路径
# where the binary is
my $evaluateBin = "evaluate"; 
# where the images are
my $imDir = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing"; #FDDB图片路径
# where the folds are
my $fddbDir = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/FDDB-folds.txt"; 
# where the detections are
my $detDir = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/fddb/"; 
###########################

my $detFormat = 0; # 0: rectangle, 1: ellipse 2: pixels

sub makeGNUplotFile
{
  my $rocFile = shift;
  my $gnuplotFile = shift;
  my $title = shift;
  my $pngFile = shift;


  open(GF, ">$gnuplotFile") or die "Can not open $gnuplotFile for writing\n"; 
  #print GF "$GNUPLOT\n";
  print GF "set term png\n";
  print GF "set size 1,1\n";
  print GF "set output \"$pngFile\"\n";
  #print GF "set xtics 500\n";
  print GF "set ytics 0.1\n";
  print GF "set grid\n";
  #print GF "set size ratio -1\n";
  print GF "set ylabel \"True positive rate\"\n";
  print GF "set xlabel \"False positives\"\n";
  #print GF "set xr [0:2000]\n";
  print GF "set yr [0:1.0]\n";
  print GF "set key right bottom\n";
  print GF "plot \"$rocFile\" using 2:1 title \"$title\" with lines lw 2 \n";
  close(GF);
}

my $gpFile = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/fddb/ContROC.p";
my $gpFile1 = "C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/fddb/DistROC.p";
my $title = "tqy";

# plot the two ROC curves using GNUplot
# plot the two ROC curves using GNUplot
makeGNUplotFile("C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/tempContROC.txt", $gpFile, $title, $detDir."ContROC.png");
makeGNUplotFile("C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/FDDB_testing/FDDB_testing/tempDiscROC.txt", $gpFile1, $title, $detDir."DiscROC.png");


在命令行中runEvaluate.pl的路径下输入perl runEvaluate.pl,得到ContROC.p与DistROC.p。

6、打开gnuplot软件:

a、file->open->contROC.p b、file->output->contROC.p

在对应目录中生成contROC.png;
a、file->open->discROC.p  b、file->output->discROC.p
在对应目录中生成discROC.png

7、如果想将自己的结果与官网上其他公司公布的结果画在一起,在官网上下载ContROC.p,DiscRoc.p等,用写字板打开之后,将自己的检测结果添加进去,同样用gnuplot画出来就行。


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值