pytorch

Форк
0
/
tsv_2_proto.cc 
49 строк · 1.5 Кб
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 <sstream>
18
#include <string>
19

20
#include "caffe2/core/blob_serialization.h"
21
#include "caffe2/core/db.h"
22
#include "caffe2/core/init.h"
23
#include "caffe2/core/logging.h"
24
#include "caffe2/proto/caffe2_pb.h"
25
#include "caffe2/utils/proto_utils.h"
26

27
C10_DEFINE_string(f_in, "", "The input data file name.");
28
C10_DEFINE_string(f_out, "", "The output data file name.");
29

30
int main(int argc, char** argv) {
31
  caffe2::GlobalInit(&argc, &argv);
32
  std::ifstream f_in(FLAGS_f_in);
33
  std::ofstream f_out(FLAGS_f_out);
34
  std::string line;
35
  caffe2::TensorProtos tensor_protos;
36
  while (std::getline(f_in, line)) {
37
    caffe2::TensorProto* data = tensor_protos.add_protos();
38
    data->set_data_type(caffe2::TensorProto::STRING);
39
    data->add_dims(1);
40
    data->add_string_data(line);
41
    data->set_name("text");
42
  }
43
  f_in.close();
44
  std::string output_str;
45
  tensor_protos.SerializeToString(&output_str);
46
  f_out << output_str;
47
  f_out.close();
48
  return 0;
49
}
50

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

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

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

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