2
* Copyright (c) 2016-present, Facebook, Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
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.");
28
using caffe2::db::Cursor;
30
using caffe2::db::Transaction;
32
int main(int argc, char** argv) {
33
caffe2::GlobalInit(&argc, &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.";