Repository: lisa-lab/pylearn2

Issue:
MomentumAdjustor error message is misleading
If you try to use MomentumAdjustor with a TrainingAlgorithm other than SGD it will give you an error message saying you need to use a LearningRule, rather than that you need to use SGD.



Discussion:

Resolving patch:
diff --git a/pylearn2/training_algorithms/learning_rule.py b/pylearn2/training_algorithms/learning_rule.py
--- a/pylearn2/training_algorithms/learning_rule.py
+++ b/pylearn2/training_algorithms/learning_rule.py
@@ -223,10 +223,11 @@ def on_monitor(self, model, dataset, algorithm):
     def _apply_momentum(self, algorithm):
         """Updates the momentum on algorithm based on the epochs elapsed."""
         if not hasattr(algorithm, 'learning_rule'):
-            raise ValueError('For MomentumAdjustor to work, you need to ' +
-                             'specify a learning_rule (for instance,' +
-                             ' Momentum) for your training algorithm' +
-                             '(for instance, SGD)')
+            raise ValueError(
+                'For MomentumAdjustor to work, you need to use a '
+                'TrainingAlgorithm that supports learning rules '
+                '(for instance, SGD), and specify a learning_rule '
+                '(for instance, Momentum) for that training algorithm.')
 
         momentum = algorithm.learning_rule.momentum
 


Test patch:
diff --git a/pylearn2/devtools/tests/test_format.py b/pylearn2/devtools/tests/test_format.py
--- a/pylearn2/devtools/tests/test_format.py
+++ b/pylearn2/devtools/tests/test_format.py
@@ -228,7 +228,6 @@
     "scripts/datasets/make_mnistplus.py",
     "scripts/mlp/predict_csv.py",
     "scripts/find_gpu_fields.py",
-    "scripts/tutorials/convolutional_network/tests/test_convnet.py",
     "scripts/tutorials/deep_trainer/test_deep_trainer.py",
     "scripts/icml_2013_wrepl/multimodal/make_wordlist.py",
     "base.py",
@@ -524,7 +523,6 @@
     'scripts/tutorials/tests/test_dbm.py',
     'scripts/tutorials/tests/test_mlp_nested.py',
     'scripts/tutorials/multilayer_perceptron/tests/test_mlp.py',
-    'scripts/tutorials/convolutional_network/tests/test_convnet.py',
     'scripts/tutorials/softmax_regression/tests/test_softmaxreg.py',
     'scripts/tutorials/deep_trainer/__init__.py',
     'scripts/tutorials/deep_trainer/run_deep_trainer.py',
diff --git a/pylearn2/scripts/tutorials/convolutional_network/tests/test_convnet.py b/pylearn2/scripts/tutorials/convolutional_network/tests/test_convnet.py
--- a/pylearn2/scripts/tutorials/convolutional_network/tests/test_convnet.py
+++ b/pylearn2/scripts/tutorials/convolutional_network/tests/test_convnet.py
@@ -14,16 +14,19 @@
 
 import os
 from pylearn2.testing import skip
-from pylearn2.testing import no_debug_mode
 from pylearn2.config import yaml_parse
 
 
 def test_convolutional_network():
-
+    """Test smaller version of convolutional_network.ipynb"""
     skip.skip_if_no_data()
     yaml_file_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                                   '..'))
     save_path = os.path.dirname(os.path.realpath(__file__))
+    # Escape potential backslashes in Windows filenames, since
+    # they will be processed when the YAML parser will read it
+    # as a string
+    save_path.replace('\\', r'\\')
 
     yaml = open("{0}/conv.yaml".format(yaml_file_path), 'r').read()
     hyper_params = {'train_stop': 50,
@@ -42,4 +45,3 @@ def test_convolutional_network():
         os.remove("{}/convolutional_network_best.pkl".format(save_path))
     except OSError:
         pass
-