Skip to content

Commit

Permalink
Automatic replacement of snapshot_prefix parameter if it is empty or …
Browse files Browse the repository at this point in the history
…points to a directory. See issue BVLC#6110 proposed improvement No.2
  • Loading branch information
IlyaOvodov committed Feb 10, 2018
1 parent c326294 commit 6fa4c62
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/caffe/proto/caffe.proto
Expand Up @@ -186,7 +186,11 @@ message SolverParameter {
optional float clip_gradients = 35 [default = -1];

optional int32 snapshot = 14 [default = 0]; // The snapshot interval
optional string snapshot_prefix = 15; // The prefix for the snapshot.
// The prefix for the snapshot.
// If not set then is replaced by prototxt file path without extention.
// If is set to directory then is augmented by prototxt file name
// without extention.
optional string snapshot_prefix = 15;
// whether to snapshot diff in the results or not. Snapshotting diff will help
// debugging but the final protocol buffer size will be much larger.
optional bool snapshot_diff = 16 [default = false];
Expand Down
21 changes: 21 additions & 0 deletions src/caffe/util/upgrade_proto.cpp
Expand Up @@ -2,6 +2,8 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>

#include <boost/filesystem.hpp>

#include <map>
#include <string>

Expand Down Expand Up @@ -1095,12 +1097,31 @@ bool UpgradeSolverAsNeeded(const string& param_file, SolverParameter* param) {
return success;
}

// Replaces snapshot_prefix of SolverParameter if it is not specified
// or is set to directory
void UpgradeSnapshotPrefixProperty(const string& param_file,
SolverParameter* param) {
using boost::filesystem::path;
using boost::filesystem::is_directory;
if (!param->has_snapshot_prefix()) {
param->set_snapshot_prefix(path(param_file).replace_extension().string());
LOG(INFO) << "snapshot_prefix was not specified and is set to "
+ param->snapshot_prefix();
} else if (is_directory(param->snapshot_prefix())) {
param->set_snapshot_prefix((path(param->snapshot_prefix()) /
path(param_file).stem()).string());
LOG(INFO) << "snapshot_prefix was a directory and is replaced to "
+ param->snapshot_prefix();
}
}

// Read parameters from a file into a SolverParameter proto message.
void ReadSolverParamsFromTextFileOrDie(const string& param_file,
SolverParameter* param) {
CHECK(ReadProtoFromTextFile(param_file, param))
<< "Failed to parse SolverParameter file: " << param_file;
UpgradeSolverAsNeeded(param_file, param);
UpgradeSnapshotPrefixProperty(param_file, param);
}

} // namespace caffe

0 comments on commit 6fa4c62

Please sign in to comment.