本文整理汇总了C++中Datum::add_multi_label方法的典型用法代码示例。如果您正苦于以下问题:C++ Datum::add_multi_label方法的具体用法?C++ Datum::add_multi_label怎么用?C++ Datum::add_multi_label使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Datum
的用法示例。
在下文中一共展示了Datum::add_multi_label方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
map_name_contxt.insert(std::make_pair(filename, contxt));
}
input.close();
}
leveldb::DB* db;
leveldb::Options options;
options.error_if_exists = true;
options.create_if_missing = true;
options.write_buffer_size = 268435456;
LOG(INFO)<< "Opening leveldb " << argv[4];
leveldb::Status status = leveldb::DB::Open(options, argv[4], &db);
CHECK(status.ok()) << "Failed to open leveldb " << argv[4];
string root_folder(argv[1]);
Datum datum;
int count = 0;
leveldb::WriteBatch* batch = new leveldb::WriteBatch();
int data_size;
bool data_size_initialized = false;
for (int line_id = 0; line_id < lines.size(); ++line_id)
{
const std::pair<string, vector<float> >& name_label = lines[line_id];
const string& name = name_label.first;
const vector<float>& cur_labels = name_label.second;
const vector<float>& cur_conxts = map_name_contxt.find(name)->second;
// set image name
datum.set_img_name(name);
// set image data
{
const string img_full_name = root_folder + name;
cv::Mat cv_img = cv::imread(img_full_name, CV_LOAD_IMAGE_COLOR);
if (!cv_img.data)
{
LOG(ERROR)<< "Could not open or find file " << img_full_name;
return false;
}
datum.set_channels(3);
datum.set_height(cv_img.rows);
datum.set_width(cv_img.cols);
datum.clear_data();
datum.clear_float_data();
string* datum_string = datum.mutable_data();
for (int c = 0; c < 3; ++c)
{
for (int h = 0; h < cv_img.rows; ++h)
{
for (int w = 0; w < cv_img.cols; ++w)
{
datum_string->push_back(
static_cast<char>(cv_img.at<cv::Vec3b>(h, w)[c]));
}
}
}
}
// set multi-label
{
datum.set_num_multi_label(NUMLABEL);
datum.clear_multi_label();
datum.mutable_multi_label->Reserve(cur_labels.size());
for (int i = 0; i < cur_labels.size(); ++i)
datum.add_multi_label(cur_labels[i]);
}
// set context
{
datum.set_num_context(NUMCONTEXT);
datum.clear_context();
datum.mutable_context->Reserve(cur_conxts.size());
for (int i = 0; i < cur_conxts.size(); ++i)
datum.add_context(cur_conxts[i]);
}
string value;
// get the value
datum.SerializeToString(&value);
batch->Put(name, value);
if (++count % 1000 == 0)
{
db->Write(leveldb::WriteOptions(), batch);
LOG(ERROR)<< "Processed " << count << " files.";
delete batch;
batch = new leveldb::WriteBatch();
}
}
// write the last batch
if (count % 1000 != 0)
{
db->Write(leveldb::WriteOptions(), batch);
LOG(ERROR)<< "Processed " << count << " files.";
}
delete batch;
delete db;
return 0;
}