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.
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"
27
C10_DEFINE_string(f_in, "", "The input data file name.");
28
C10_DEFINE_string(f_out, "", "The output data file name.");
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);
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);
40
data->add_string_data(line);
41
data->set_name("text");
44
std::string output_str;
45
tensor_protos.SerializeToString(&output_str);