From c251b2581b02904ea6b5501786d4514734aef3d6 Mon Sep 17 00:00:00 2001 From: Jeff Donahue Date: Fri, 7 Aug 2015 15:34:00 -0700 Subject: [PATCH] TestGradientBasedSolver: make tests across solver types more consistent --- src/caffe/test/test_gradient_based_solver.cpp | 91 +++++++++++++++++---------- 1 file changed, 59 insertions(+), 32 deletions(-) diff --git a/src/caffe/test/test_gradient_based_solver.cpp b/src/caffe/test/test_gradient_based_solver.cpp index 235a7d8..54606db 100644 --- a/src/caffe/test/test_gradient_based_solver.cpp +++ b/src/caffe/test/test_gradient_based_solver.cpp @@ -466,23 +466,38 @@ TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdate) { this->TestLeastSquaresUpdate(); } -TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateLROneTenth) { +TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateLROneHundredth) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 0.1; + const Dtype kLearningRate = 0.01; this->TestLeastSquaresUpdate(kLearningRate); } TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithWeightDecay) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 1.0; + const Dtype kLearningRate = 0.01; const Dtype kWeightDecay = 0.5; - this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay); + const Dtype kMomentum = 0; + const int kNumIters = 1; + for (int i = 0; i <= kNumIters; ++i) { + this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i); + } +} + +TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithWeightDecayMultiIter) { + typedef typename TypeParam::Dtype Dtype; + const Dtype kLearningRate = 0.01; + const Dtype kWeightDecay = 0.5; + const Dtype kMomentum = 0; + const int kNumIters = 4; + for (int i = 0; i <= kNumIters; ++i) { + this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i); + } } TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithMomentum) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 1.0; - const Dtype kWeightDecay = 0.0; + const Dtype kLearningRate = 0.01; + const Dtype kWeightDecay = 0; const Dtype kMomentum = 0.5; const int kNumIters = 1; for (int i = 0; i <= kNumIters; ++i) { @@ -492,8 +507,8 @@ TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithMomentum) { TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithMomentumMultiIter) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 1.0; - const Dtype kWeightDecay = 0.0; + const Dtype kLearningRate = 0.01; + const Dtype kWeightDecay = 0; const Dtype kMomentum = 0.5; const int kNumIters = 4; for (int i = 0; i <= kNumIters; ++i) { @@ -504,8 +519,8 @@ TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithMomentumMultiIter) { TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverything) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; - const Dtype kMomentum = 0.9; + const Dtype kWeightDecay = 0.5; + const Dtype kMomentum = 0.5; const int kNumIters = 4; for (int i = 0; i <= kNumIters; ++i) { this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i); @@ -515,7 +530,7 @@ TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverything) { TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverythingAccum) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; + const Dtype kWeightDecay = 0.5; const Dtype kMomentum = 0.9; const int kNumIters = 4; const int kIterSize = 2; @@ -526,7 +541,7 @@ TYPED_TEST(SGDSolverTest, TestLeastSquaresUpdateWithEverythingAccum) { TYPED_TEST(SGDSolverTest, TestSnapshot) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; + const Dtype kWeightDecay = 0.5; const Dtype kMomentum = 0.9; const int kNumIters = 4; for (int i = 1; i <= kNumIters; ++i) { @@ -554,15 +569,15 @@ TYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdate) { this->TestLeastSquaresUpdate(); } -TYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateLROneTenth) { +TYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateLROneHundredth) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 0.1; + const Dtype kLearningRate = 0.01; this->TestLeastSquaresUpdate(kLearningRate); } TYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateWithWeightDecay) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 1.0; + const Dtype kLearningRate = 0.01; const Dtype kWeightDecay = 0.5; this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay); } @@ -570,8 +585,8 @@ TYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateWithWeightDecay) { TYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateWithEverything) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; - const Dtype kMomentum = 0.0; + const Dtype kWeightDecay = 0.5; + const Dtype kMomentum = 0; const int kNumIters = 4; for (int i = 0; i <= kNumIters; ++i) { this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i); @@ -581,8 +596,8 @@ TYPED_TEST(AdaGradSolverTest, TestAdaGradLeastSquaresUpdateWithEverything) { TYPED_TEST(AdaGradSolverTest, TestLeastSquaresUpdateWithEverythingAccum) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; - const Dtype kMomentum = 0.0; + const Dtype kWeightDecay = 0.5; + const Dtype kMomentum = 0; const int kNumIters = 4; const int kIterSize = 2; this->CheckAccumulation(kLearningRate, kWeightDecay, kMomentum, kNumIters, @@ -592,8 +607,8 @@ TYPED_TEST(AdaGradSolverTest, TestLeastSquaresUpdateWithEverythingAccum) { TYPED_TEST(AdaGradSolverTest, TestSnapshot) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; - const Dtype kMomentum = 0.0; + const Dtype kWeightDecay = 0.5; + const Dtype kMomentum = 0; const int kNumIters = 4; for (int i = 1; i <= kNumIters; ++i) { this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i); @@ -620,23 +635,35 @@ TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdate) { this->TestLeastSquaresUpdate(); } -TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateLROneTenth) { +TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateLROneHundredth) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 0.1; + const Dtype kLearningRate = 0.01; this->TestLeastSquaresUpdate(kLearningRate); } TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithWeightDecay) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 1.0; + const Dtype kLearningRate = 0.01; const Dtype kWeightDecay = 0.5; this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay); } +TYPED_TEST(NesterovSolverTest, + TestNesterovLeastSquaresUpdateWithWeightDecayMultiIter) { + typedef typename TypeParam::Dtype Dtype; + const Dtype kLearningRate = 0.01; + const Dtype kWeightDecay = 0.5; + const Dtype kMomentum = 0; + const int kNumIters = 4; + for (int i = 0; i <= kNumIters; ++i) { + this->TestLeastSquaresUpdate(kLearningRate, kWeightDecay, kMomentum, i); + } +} + TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithMomentum) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 1.0; - const Dtype kWeightDecay = 0.0; + const Dtype kLearningRate = 0.01; + const Dtype kWeightDecay = 0; const Dtype kMomentum = 0.5; const int kNumIters = 1; for (int i = 0; i <= kNumIters; ++i) { @@ -646,8 +673,8 @@ TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithMomentum) { TYPED_TEST(NesterovSolverTest, TestLeastSquaresUpdateWithMomentumMultiIter) { typedef typename TypeParam::Dtype Dtype; - const Dtype kLearningRate = 1.0; - const Dtype kWeightDecay = 0.0; + const Dtype kLearningRate = 0.01; + const Dtype kWeightDecay = 0; const Dtype kMomentum = 0.5; const int kNumIters = 4; for (int i = 0; i <= kNumIters; ++i) { @@ -658,7 +685,7 @@ TYPED_TEST(NesterovSolverTest, TestLeastSquaresUpdateWithMomentumMultiIter) { TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithEverything) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; + const Dtype kWeightDecay = 0.5; const Dtype kMomentum = 0.9; const int kNumIters = 4; for (int i = 0; i <= kNumIters; ++i) { @@ -669,7 +696,7 @@ TYPED_TEST(NesterovSolverTest, TestNesterovLeastSquaresUpdateWithEverything) { TYPED_TEST(NesterovSolverTest, TestLeastSquaresUpdateWithEverythingAccum) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; + const Dtype kWeightDecay = 0.5; const Dtype kMomentum = 0.9; const int kNumIters = 4; const int kIterSize = 2; @@ -680,8 +707,8 @@ TYPED_TEST(NesterovSolverTest, TestLeastSquaresUpdateWithEverythingAccum) { TYPED_TEST(NesterovSolverTest, TestSnapshot) { typedef typename TypeParam::Dtype Dtype; const Dtype kLearningRate = 0.01; - const Dtype kWeightDecay = 0.1; - const Dtype kMomentum = 0.0; + const Dtype kWeightDecay = 0.5; + const Dtype kMomentum = 0.9; const int kNumIters = 4; for (int i = 1; i <= kNumIters; ++i) { this->TestSnapshot(kLearningRate, kWeightDecay, kMomentum, i); -- 2.7.4