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];
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/text_format.h>
+#include <boost/filesystem.hpp>
+
#include <map>
#include <string>
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