google :: protobuf :: TextFormat :: Parse无法成功解析原型文件

时间:2018-04-12 09:36:05

标签: deep-learning protocol-buffers caffe

我有一个解算器文件,如下所示。

train_net: "../Prototxtfiles/VGGNet/train.prototxt"
test_net: "../Prototxtfiles/VGGNet/test.prototxt"
test_iter: 172
test_interval: 1000
base_lr: 0.0010000000475
display: 10
max_iter: 30000
lr_policy: "multistep"
gamma: 0.10000000149
momentum: 0.899999976158
weight_decay: 0.000500000023749
snapshot: 5000
snapshot_prefix: "../Prototxtfiles/VGGNet/CROWDSENSING_SSD_500x500"
solver_mode: GPU
device_id: 0
debug_info: false
snapshot_after_train: true
test_initialization: false
average_loss: 10
stepvalue: 10000
stepvalue: 20000
stepvalue: 30000
iter_size: 4
type: "SGD"
eval_type: "detection"
ap_version: "11point"

我尝试使用下面的代码读取文件

bool ReadProtoFromTextFile(const char* filename, Message* proto) {
  int fd = open(filename, O_RDONLY);
  CHECK_NE(fd, -1) << "File not found: " << filename;
  google::protobuf::io::FileInputStream* input = new FileInputStream(fd);
  bool success = google::protobuf::TextFormat::Parse(input, proto);
  delete input;
  close(fd);
  return success;
}

我无法解析Windows,但它适用于Linux。 可能是什么问题?

编辑:

可能是什么问题?我可以使用相同的代码阅读此原型文件。

net: "models/bvlc_googlenet/train_val.prototxt"
test_iter: 1000
test_interval: 4000
test_initialization: false
display: 40
average_loss: 40
base_lr: 0.01
lr_policy: "step"
stepsize: 320000
gamma: 0.96
max_iter: 10000000
momentum: 0.9
weight_decay: 0.0002
snapshot: 40000
snapshot_prefix: "models/bvlc_googlenet/bvlc_googlenet"
solver_mode: GPU

1 个答案:

答案 0 :(得分:0)

如果你可以在Linux上解析它,但你不能在Windows上,我会说你的问题是一个编码问题。

https://superuser.com/questions/294219/what-are-the-differences-between-linux-and-windows-txt-files-unicode-encoding

例如,如果您使用Notepad ++打开文件,您应该能够看到这些特殊字符。

阅读其他帖子,听起来像TextFormat只期待UTF-8编码的字符: What does the protobuf text format look like?

如何构建原型文件?