Added sanity check for AdaGradSolver; added MNIST examples for solvers
authorqipeng <pengrobertqi@163.com>
Tue, 26 Aug 2014 06:02:56 +0000 (23:02 -0700)
committerJeff Donahue <jeff.donahue@gmail.com>
Mon, 1 Sep 2014 18:33:41 +0000 (11:33 -0700)
examples/mnist/mnist_autoencoder_solver_adagrad.prototxt [new file with mode: 0644]
examples/mnist/mnist_autoencoder_solver_nesterov.prototxt [new file with mode: 0644]
examples/mnist/train_mnist_autoencoder_adagrad.sh [new file with mode: 0755]
examples/mnist/train_mnist_autoencoder_nesterov.sh [new file with mode: 0755]
include/caffe/solver.hpp

diff --git a/examples/mnist/mnist_autoencoder_solver_adagrad.prototxt b/examples/mnist/mnist_autoencoder_solver_adagrad.prototxt
new file mode 100644 (file)
index 0000000..6193351
--- /dev/null
@@ -0,0 +1,15 @@
+net: "mnist_autoencoder.prototxt"
+test_iter: 50
+test_interval: 100
+test_compute_loss: true
+base_lr: 0.01
+lr_policy: "fixed"
+display: 20
+max_iter: 4000000
+weight_decay: 0.0005
+snapshot: 10000
+snapshot_prefix: "mnist_autoencoder_train"
+momentum: 0.9
+# solver mode: CPU or GPU
+solver_mode: GPU
+solver_type: ADAGRAD
diff --git a/examples/mnist/mnist_autoencoder_solver_nesterov.prototxt b/examples/mnist/mnist_autoencoder_solver_nesterov.prototxt
new file mode 100644 (file)
index 0000000..1748730
--- /dev/null
@@ -0,0 +1,15 @@
+net: "mnist_autoencoder.prototxt"
+test_iter: 50
+test_interval: 100
+test_compute_loss: true
+base_lr: 0.0001
+lr_policy: "fixed"
+display: 20
+max_iter: 4000000
+weight_decay: 0.0005
+snapshot: 10000
+snapshot_prefix: "mnist_autoencoder_train"
+momentum: 0.95
+# solver mode: CPU or GPU
+solver_mode: GPU
+solver_type: NESTEROV
diff --git a/examples/mnist/train_mnist_autoencoder_adagrad.sh b/examples/mnist/train_mnist_autoencoder_adagrad.sh
new file mode 100755 (executable)
index 0000000..628c74b
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+TOOLS=../../build/tools
+
+$TOOLS/caffe.bin train --solver=mnist_autoencoder_solver.prototxt
diff --git a/examples/mnist/train_mnist_autoencoder_nesterov.sh b/examples/mnist/train_mnist_autoencoder_nesterov.sh
new file mode 100755 (executable)
index 0000000..8f004c4
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash
+TOOLS=../../build/tools
+
+$TOOLS/caffe.bin train --solver=mnist_autoencoder_solver_nesterov.prototxt
index b3c7f6f..a73ba2c 100644 (file)
@@ -100,12 +100,15 @@ template <typename Dtype>
 class AdaGradSolver : public SGDSolver<Dtype> {
  public:
   explicit AdaGradSolver(const SolverParameter& param)
-      : SGDSolver<Dtype>(param) {}
+      : SGDSolver<Dtype>(param) { constructor_sanity_check(); }
   explicit AdaGradSolver(const string& param_file)
-      : SGDSolver<Dtype>(param_file) {}
+      : SGDSolver<Dtype>(param_file) { constructor_sanity_check(); }
 
  protected:
   virtual void ComputeUpdateValue();
+  void constructor_sanity_check() {
+    CHECK_EQ(0, this->param_.momentum()) << "Momentum cannot be used with AdaGrad.";
+  }
 
   DISABLE_COPY_AND_ASSIGN(AdaGradSolver);
 };