summaryrefslogtreecommitdiff
path: root/tools/caffe.cpp
diff options
context:
space:
mode:
authorJ Yegerlehner <jyegerlehner@yahoo.com>2015-04-03 16:11:23 -0500
committerJ Yegerlehner <jyegerlehner@yahoo.com>2015-08-22 12:51:55 -0500
commitff19d5f5c010dd8d6bfcf768b4fe27d0458f17df (patch)
tree721e4a100606b44441db4e563b027ed590c3a146 /tools/caffe.cpp
parentc6b9f580540f5aa16d05d8e283f9e0050dda2fb5 (diff)
downloadcaffeonacl-ff19d5f5c010dd8d6bfcf768b4fe27d0458f17df.tar.gz
caffeonacl-ff19d5f5c010dd8d6bfcf768b4fe27d0458f17df.tar.bz2
caffeonacl-ff19d5f5c010dd8d6bfcf768b4fe27d0458f17df.zip
Add signal handler and early exit/snapshot to Solver.
Add signal handler and early exit/snapshot to Solver. Add signal handler and early exit/snapshot to Solver. Also check for exit and snapshot when testing. Skip running test after early exit. Fix more lint. Rebase on master. Finish rebase on master. Fixups per review comments. Redress review comments. Lint. Correct error message wording.
Diffstat (limited to 'tools/caffe.cpp')
-rw-r--r--tools/caffe.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/tools/caffe.cpp b/tools/caffe.cpp
index 9f31b37a..ff63860a 100644
--- a/tools/caffe.cpp
+++ b/tools/caffe.cpp
@@ -12,6 +12,7 @@ namespace bp = boost::python;
#include "boost/algorithm/string.hpp"
#include "caffe/caffe.hpp"
+#include "caffe/util/signal_handler.h"
using caffe::Blob;
using caffe::Caffe;
@@ -39,6 +40,12 @@ DEFINE_string(weights, "",
"separated by ','. Cannot be set simultaneously with snapshot.");
DEFINE_int32(iterations, 50,
"The number of iterations to run.");
+DEFINE_string(sigint_effect, "stop",
+ "Optional; action to take when a SIGINT signal is received: "
+ "snapshot, stop or none.");
+DEFINE_string(sighup_effect, "snapshot",
+ "Optional; action to take when a SIGHUP signal is received: "
+ "snapshot, stop or none.");
// A simple registry for caffe commands.
typedef int (*BrewFunction)();
@@ -126,6 +133,22 @@ void CopyLayers(caffe::Solver<float>* solver, const std::string& model_list) {
}
}
+// Translate the signal effect the user specified on the command-line to the
+// corresponding enumeration.
+caffe::SolverAction::Enum GetRequestedAction(
+ const std::string& flag_value) {
+ if (flag_value == "stop") {
+ return caffe::SolverAction::STOP;
+ }
+ if (flag_value == "snapshot") {
+ return caffe::SolverAction::SNAPSHOT;
+ }
+ if (flag_value == "none") {
+ return caffe::SolverAction::NONE;
+ }
+ LOG(FATAL) << "Invalid signal effect \""<< flag_value << "\" was specified";
+}
+
// Train / Finetune a model.
int train() {
CHECK_GT(FLAGS_solver.size(), 0) << "Need a solver definition to train.";
@@ -165,7 +188,14 @@ int train() {
Caffe::set_solver_count(gpus.size());
}
- shared_ptr<Solver<float> > solver(caffe::GetSolver<float>(solver_param));
+ caffe::SignalHandler signal_handler(
+ GetRequestedAction(FLAGS_sigint_effect),
+ GetRequestedAction(FLAGS_sighup_effect));
+
+ shared_ptr<caffe::Solver<float> >
+ solver(caffe::GetSolver<float>(solver_param));
+
+ solver->SetActionFunction(signal_handler.GetActionFunction());
if (FLAGS_snapshot.size()) {
LOG(INFO) << "Resuming from " << FLAGS_snapshot;