在深度学习模型训练中,我们很可能只需要原来1/3,或1/5的样本量,手动筛选耗时耗力。用c++实现自动筛选比较自动化和省事。 要实现0-521625每2个取一个,521625-764126全取,764126- 每3个取一个,代码如下:
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
ifstream infile_widerface;
ifstream infile1_celebA;
ofstream outfile;
infile_widerface.open("D:/mtcnn/train/48/label_widerface-train.txt");
//infile1_celebA.open("D:/mtcnn/train/48/label_txt/label_celebA-train.txt");
outfile.open("D:/mtcnn/train/48/clsbbox_widerface-train.txt");
string img, line;
int clas, i = 0;
float offsetx1, offsety1, offsetx2, offsety2;
while (getline(infile_widerface, line))
{
if (i <= 521625)
{
if (i % 2 == 0)
{
outfile << line << endl;
}
}
else if (i > 521625 && i < 764125)
{
outfile << line << endl;
}
else
{
if (i % 4 == 0)
{
outfile << line << endl;
}
}
i++;
cout << i << endl;
}
//while (getline(infile1_celebA, line))
//{
// if (i % 3 == 0)
// {
// outfile << line << endl;
// }
// i++;
// cout << i << endl;
//}
infile_widerface.close();
//infile1_celebA.close();
outfile.close();
return 0;
}