Repository: lisa-lab/pylearn2

Issue:
Maxout data augmentation broken
pylearn2/scripts/papers/maxout/cifar10.yaml (convolutional maxout net with data augmentation) gets the same test_y_misclass as cifar10_no_aug.yaml (the same thing without data augmentation).

I was able to get data augmentation to work using pylearn2 at commit 481dbebce3e701049efaea9ca12aa750 and theano at commit 1668349072ba0fa1b8a7612e40



Discussion:
floatX=float32?

On Thu, Jul 31, 2014 at 3:11 PM, AlassaneNdiaye notifications@github.com
wrote:

> I tried running both cifar10.yaml and cifar10_no_aug.yaml using the latest
> version of pylearn2 and theano and using the flags THEANO_FLAGS=device=gpu
> but I got the error
> 
> assert 'Cuda' in str(type(filters))
> 
> Did you run them under the same settings or am I doing something wrong?
> 
> —
> Reply to this email directly or view it on GitHub
> https://github.com/lisa-lab/pylearn2/issues/1057#issuecomment-50804844.

I am looking at it right now. For now, all I know is the bug was introduced in the commit 7fb7037c73bcedb5e2c0ad47a46c46f9d7114113.

The problem seems to be that `randomize_datasets()` is not called on the dataset that is actually used for training, which was the case previously, but on a different dataset.
Therefore, calling that function has no effect on training.
@memimo What was the reason behind that change in the maxout scripts?
I'll investigate why `train_iteration_mode: 'even_shuffled_sequential'` instantiates a different dataset, and if we can find a workaround.

Actually, the fact that the datasets are different does not seem to be caused by the change in train_iteration_mode, that commit may simply have revealed an earlier problem.
I'll continue investigating.

The culprit is actually c95841666e45fec450a4368dcbdfdf4192c0046e.
It appears that now, the `&train` object defined, and the `*train` reference are different objects instead.
@dwf do you have any idea what the cause is, or how to fix it?

Whoa. No, I do not. That should have _nothing_ to do with YAML reference
parsing, and if I recall correctly there is a test for this very case.

I'm at Google right now but I will have a look at this tonight.

train_iteration_mode `even_shuffled_sequential` was added because of change in iterator in case `mod(data_size, batch_size) != 0` it raised an error.

I have a fix, standby.

I've instructed @memimo how to do the fix + how to add a simple test.


Resolving patch:
diff --git a/pylearn2/config/yaml_parse.py b/pylearn2/config/yaml_parse.py
--- a/pylearn2/config/yaml_parse.py
+++ b/pylearn2/config/yaml_parse.py
@@ -232,7 +232,8 @@ def _instantiate_proxy_tuple(proxy, bindings=None):
             obj.yaml_src = proxy.yaml_src
         except AttributeError:  # Some classes won't allow this.
             pass
-        return obj
+        bindings[proxy] = obj
+        return bindings[proxy]
 
 
 def instantiate_all(graph):


Test patch:
diff --git a/pylearn2/config/tests/__init__.py b/pylearn2/config/tests/__init__.py
new file mode 100644
--- /dev/null
+++ b/pylearn2/config/tests/__init__.py
@@ -0,0 +1 @@
+"""Tests for the YAML config system."""
diff --git a/pylearn2/config/tests/test_yaml_parse.py b/pylearn2/config/tests/test_yaml_parse.py
--- a/pylearn2/config/tests/test_yaml_parse.py
+++ b/pylearn2/config/tests/test_yaml_parse.py
@@ -228,6 +228,17 @@ def test_pkl_yaml_src_field():
         os.remove(fn)
 
 
+def test_instantiate_regression():
+    """
+    Test a case where instantiated objects were not getting correctly
+    reused across references.
+    """
+    yaml = ("{'a': &test !obj:pylearn2.config.tests.test_yaml_parse.DumDum {},"
+            " 'b': *test}")
+    obj = load(yaml)
+    assert obj['a'] is obj['b']
+
+
 if __name__ == "__main__":
     test_multi_constructor_obj()
     test_duplicate_keywords()