pytorch

Форк
0
/
convert_db.cc 
51 строка · 1.8 Кб
1
/**
2
 * Copyright (c) 2016-present, Facebook, Inc.
3
 *
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
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
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.
15
 */
16

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
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.");
27

28
using caffe2::db::Cursor;
29
using caffe2::db::DB;
30
using caffe2::db::Transaction;
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
      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());
41
  int count = 0;
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.";
47
    }
48
  }
49
  LOG(INFO) << "A total of " << count << " items processed.";
50
  return 0;
51
}
52

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.