读取caffe训练数据文件txt,每行包括文件地址与类别标签。
string src;
std::ifstream infile(src);
std::vector<std::pair<std::string, int> > lines;
std::string filename;
int label;
while (infile >> filename >> label) {
lines.push_back(std::make_pair(filename, label));
}
for (int line_id = 0; line_id < lines.size(); ++line_id) {
string fn = lines[line_id].first;
size_t p = fn.rfind('.');
std::string enc = fn.substr(p);
if ( en == "png" )
{
std::vector<uchar> buf;
cv::imencode("."+enc , cv_img, buf);
}
}
bool ReadFileToDatum(const string& filename, const int label,Datum* datum)
{
std::streampos size;
fstream file(filename.c_str(), ios::in | ios::binary | ios::ate);
if