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 C10_DEFINE_string(input_db,
"",
"The input db.");
23 C10_DEFINE_string(input_db_type,
"",
"The input db type.");
24 C10_DEFINE_string(output_db,
"",
"The output db.");
25 C10_DEFINE_string(output_db_type,
"",
"The output db type.");
26 C10_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 FLAGS_input_db_type, FLAGS_input_db, caffe2::db::READ));
37 std::unique_ptr<DB> out_db(caffe2::db::CreateDB(
38 FLAGS_output_db_type, 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 % FLAGS_batch_size == 0) {
45 transaction->Commit();
46 LOG(INFO) <<
"Converted " << count <<
" items so far.";
49 LOG(INFO) <<
"A total of " << count <<
" items processed.";
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.
bool GlobalInit(int *pargc, char ***pargv)
Initialize the global environment of caffe2.