From f436cb20df62ed7c5760e8da6f13da28606ac86d Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Wed, 14 May 2014 12:28:55 -0700 Subject: [PATCH 1/2] Write/create/truncate prototxt when saving to fix #341 WriteProtoToTextFile now saves the prototxt whether or not the file already exists and sets the permissions to owner read/write and group + other read. Thanks @beam2d and @chyh1990 for pointing out the open modes bug. --- src/caffe/util/io.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/caffe/util/io.cpp b/src/caffe/util/io.cpp index 122d1a77a77..44858f48a36 100644 --- a/src/caffe/util/io.cpp +++ b/src/caffe/util/io.cpp @@ -44,7 +44,7 @@ bool ReadProtoFromTextFile(const char* filename, Message* proto) { } void WriteProtoToTextFile(const Message& proto, const char* filename) { - int fd = open(filename, O_WRONLY); + int fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); FileOutputStream* output = new FileOutputStream(fd); CHECK(google::protobuf::TextFormat::Print(proto, output)); delete output; From a894796977227aa34a58e273a5d5a93d2dafbffd Mon Sep 17 00:00:00 2001 From: Evan Shelhamer Date: Wed, 14 May 2014 12:35:33 -0700 Subject: [PATCH 2/2] fix workaround in net prototxt upgrade --- tools/upgrade_net_proto_text.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tools/upgrade_net_proto_text.cpp b/tools/upgrade_net_proto_text.cpp index aefdc7e2961..8a77f752cc2 100644 --- a/tools/upgrade_net_proto_text.cpp +++ b/tools/upgrade_net_proto_text.cpp @@ -44,13 +44,8 @@ int main(int argc, char** argv) { NetParameterPrettyPrint net_param_pretty; NetParameterToPrettyPrint(net_param, &net_param_pretty); - // TODO(jdonahue): figure out why WriteProtoToTextFile doesn't work - // (no file is created). - // WriteProtoToTextFile(net_param_pretty, argv[2]); - ofstream output_proto; - output_proto.open(argv[2]); - output_proto << net_param_pretty.DebugString(); - output_proto.close(); + // Save new format prototxt. + WriteProtoToTextFile(net_param_pretty, argv[2]); LOG(ERROR) << "Wrote upgraded NetParameter text proto to " << argv[2]; return !success;