17 #include "caffe2/core/db.h" 18 #include "caffe2/core/init.h" 19 #include "caffe2/proto/caffe2.pb.h" 20 #include "caffe2/core/logging.h" 22 CAFFE2_DEFINE_string(input_db,
"",
"The input db.");
23 CAFFE2_DEFINE_string(input_db_type,
"",
"The input db type.");
24 CAFFE2_DEFINE_string(output_db,
"",
"The output db.");
25 CAFFE2_DEFINE_string(output_db_type,
"",
"The output db type.");
26 CAFFE2_DEFINE_int(batch_size, 1000,
"The write batch size.");
32 int main(
int argc,
char** argv) {
35 std::unique_ptr<DB> in_db(caffe2::db::CreateDB(
36 caffe2::FLAGS_input_db_type, caffe2::FLAGS_input_db, caffe2::db::READ));
37 std::unique_ptr<DB> out_db(caffe2::db::CreateDB(
38 caffe2::FLAGS_output_db_type, caffe2::FLAGS_output_db, caffe2::db::NEW));
39 std::unique_ptr<Cursor> cursor(in_db->NewCursor());
40 std::unique_ptr<Transaction> transaction(out_db->NewTransaction());
42 for (; cursor->Valid(); cursor->Next()) {
43 transaction->Put(cursor->key(), cursor->value());
44 if (++count % caffe2::FLAGS_batch_size == 0) {
45 transaction->Commit();
46 LOG(INFO) <<
"Converted " << count <<
" items so far.";
49 LOG(INFO) <<
"A total of " << count <<
" items processed.";
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
An abstract class for the current database transaction while writing.
An abstract class for the cursor of the database while reading.
An abstract class for accessing a database of key-value pairs.