Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"weights" added to solver parameters, "snapshot_prefix" field default initialization #6123

Merged
merged 2 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Automatic replacement of snapshot_prefix parameter if it is empty or …
…points to a directory. See issue #6110 proposed improvement No.2
  • Loading branch information
IlyaOvodov committed Feb 10, 2018
commit 6fa4c62dcca954b7f8ae26e7f7314e235dd6a3b4
6 changes: 5 additions & 1 deletion src/caffe/proto/caffe.proto
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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