Skip to content

Commit 5533af3

Browse files
IlyaOvodovvera121
authored andcommitted
Automatic replacement of snapshot_prefix parameter if it is empty or points to a directory. See issue #6110 proposed improvement No.2
1 parent 719c08e commit 5533af3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/caffe/proto/caffe.proto

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,11 @@ message SolverParameter {
317317
optional float clip_gradients = 35 [default = -1];
318318

319319
optional int32 snapshot = 14 [default = 0]; // The snapshot interval
320-
optional string snapshot_prefix = 15; // The prefix for the snapshot.
320+
// The prefix for the snapshot.
321+
// If not set then is replaced by prototxt file path without extention.
322+
// If is set to directory then is augmented by prototxt file name
323+
// without extention.
324+
optional string snapshot_prefix = 15;
321325
// whether to snapshot diff in the results or not. Snapshotting diff will help
322326
// debugging but the final protocol buffer size will be much larger.
323327
optional bool snapshot_diff = 16 [default = false];

src/caffe/util/upgrade_proto.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <google/protobuf/io/zero_copy_stream_impl.h>
33
#include <google/protobuf/text_format.h>
44

5+
#include <boost/filesystem.hpp>
6+
57
#include <map>
68
#include <string>
79

@@ -1101,12 +1103,31 @@ bool UpgradeSolverAsNeeded(const string& param_file, SolverParameter* param) {
11011103
return success;
11021104
}
11031105

1106+
// Replaces snapshot_prefix of SolverParameter if it is not specified
1107+
// or is set to directory
1108+
void UpgradeSnapshotPrefixProperty(const string& param_file,
1109+
SolverParameter* param) {
1110+
using boost::filesystem::path;
1111+
using boost::filesystem::is_directory;
1112+
if (!param->has_snapshot_prefix()) {
1113+
param->set_snapshot_prefix(path(param_file).replace_extension().string());
1114+
LOG(INFO) << "snapshot_prefix was not specified and is set to "
1115+
+ param->snapshot_prefix();
1116+
} else if (is_directory(param->snapshot_prefix())) {
1117+
param->set_snapshot_prefix((path(param->snapshot_prefix()) /
1118+
path(param_file).stem()).string());
1119+
LOG(INFO) << "snapshot_prefix was a directory and is replaced to "
1120+
+ param->snapshot_prefix();
1121+
}
1122+
}
1123+
11041124
// Read parameters from a file into a SolverParameter proto message.
11051125
void ReadSolverParamsFromTextFileOrDie(const string& param_file,
11061126
SolverParameter* param) {
11071127
CHECK(ReadProtoFromTextFile(param_file, param))
11081128
<< "Failed to parse SolverParameter file: " << param_file;
11091129
UpgradeSolverAsNeeded(param_file, param);
1130+
UpgradeSnapshotPrefixProperty(param_file, param);
11101131
}
11111132

11121133
} // namespace caffe

0 commit comments

Comments
 (0)