在wider face验证集上验证自己检测器的性能

1、首先训练时用wider face的训练集进行训练(不要用验证集)

2、在http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/WiderFace_Results.html下载Evaluation code:Evaluation, Plotting scripts and the PR curves

3、用wider face中的验证集val进行测试,得到检测结果格式为 score x1 y1 x2 y2,与wider face要求的格式

< image name i >
< number of faces in this image = im >
< face i1 >
< face i2 >
...

< face im >

而且The detection result for each image should be a text file, with the same name of the image. The detection results are organized by the event categories. For example, if the directory of a testing image is "./0--Parade/0_Parade_marchingband_1_5.jpg", the detection result should be writtern in the text file in "./0--Parade/0_Parade_marchingband_1_5.txt".(每一张图片都应该有一个txt文件,而且txt文件目录应该和数据集原来的目录一致),所以我写了个C++程序将检测结果转化为需要的格式,然后在下好的Evaluation code的eval_tools目录下新建一个mkdir_event_list.m文件用于创建文件夹目录:

split_file = './ground_truth/wider_face_val';
[~, ~, ~] = rmdir('C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/WiderfaceEvaluationResults/WiderfaceEvaluationResults/pred', 's');
mkdir('C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/WiderfaceEvaluationResults/WiderfaceEvaluationResults/pred');
data = load(split_file);
for i=1:numel(data.event_list)
    directoryname=fullfile('C:/Users/qingyun.tang/Documents/Visual Studio 2013/Projects/WiderfaceEvaluationResults/WiderfaceEvaluationResults/pred/',data.event_list{i});
    mkdir(directoryname);
end

//在创建的C++工程目录下创建pred文件夹,所以上面目录为为C++工程目录+'/pred'
#include "stdafx.h"
#include
#include
#include
#include
#include
#include
#include
using namespace std;



//字符串分割函数
vector split(string str, string pattern)
{
	vector ret;
	if (pattern.empty()) return ret;
	size_t start = 0, index = str.find_first_of(pattern, 0);
	while (index != str.npos)
	{
		if (start != index)
			ret.push_back(str.substr(start, index - start));
		start = index + 1;
		index = str.find_first_of(pattern, start);
	}
	if (!str.substr(start).empty())
		ret.push_back(str.substr(start));
	return ret;
}
int _tmain(int argc, _TCHAR* argv[])
{
	ifstream InputFile("comp4_det_widerfacevalfilelist_face.txt");//自己检测器的检测结果
	string rootpath = "pred//";
	string line, ImageNameTemp;
	stringstream ss;
	int count = 1;
	vector vec_score;
	vector vec_x1;
	vector vec_y1;
	vector vec_x2;
	vector 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
		{
			vector vec_string;
			vec_string = split(ImageNameTemp, "/");
			ofstream OutputFile(rootpath+vec_string[0] + "//" + vec_string[1] + ".txt");
			OutputFile << vec_string[1] << 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(vec_score).swap(vec_score);
			vec_x1.clear();
			vector(vec_x1).swap(vec_x1);
			vec_y1.clear();
			vector(vec_y1).swap(vec_y1);
			vec_x2.clear();
			vector(vec_x2).swap(vec_x2);
			vec_y2.clear();
			vector(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;
	}
	vector vec_string;
	vec_string = split(ImageName, "/");
	ofstream OutputFile(rootpath+vec_string[0] + "//" + vec_string[1] + ".txt");
	OutputFile << vec_string[1] << 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、将输出的pred文件夹放到eval_tools目录下,在wider_eval的line21修改自己检测器的名字,删除eval_tools\plot\baselines\Val\setting_int文件夹下的.DS_Store,运行wider_eval.m

5、如果要在wider face测试集上验证自己的结果,需要与wider face官方联系。

你可能感兴趣的:(人脸检测)