Caffe2 - C++ API
A deep learning, cross platform ML framework
convert_db.cc
1 
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"
21 
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.");
27 
28 using caffe2::db::Cursor;
29 using caffe2::db::DB;
31 
32 int main(int argc, char** argv) {
33  caffe2::GlobalInit(&argc, &argv);
34 
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());
41  int count = 0;
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.";
47  }
48  }
49  LOG(INFO) << "A total of " << count << " items processed.";
50  return 0;
51 }
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.
Definition: init.cc:34
An abstract class for the current database transaction while writing.
Definition: db.h:77
An abstract class for the cursor of the database while reading.
Definition: db.h:38
An abstract class for accessing a database of key-value pairs.
Definition: db.h:96