1. 程式人生 > >在wider face驗證集上驗證自己檢測器的效能

在wider face驗證集上驗證自己檢測器的效能

1、首先訓練時用wider face的訓練集進行訓練(不要用驗證集)

3、用wider face中的驗證集val進行測試,得到檢測結果格式為<image name i> 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<iostream>
#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<vector>
#include<windows.h>
using namespace std;



//字串分割函式
vector<string> split(string str, string pattern)
{
	vector<string> 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<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
		{
			vector<string> 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<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;
	}
	vector<string> 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官方聯絡。