Repository: lisa-lab/pylearn2

Issue:
SVHN bugs
~~`which_set='splitted_train'` and `which_set='valid'` fail because `split_train_valid` returns [four values, not two](https://github.com/lisa-lab/pylearn2/blob/393a75583e20b7ec7a539bdde66eb06596afe90d/pylearn2/datasets/svhn.py#L238-239). There's an easy fix, which is to simply turn the first two as a tuple and the last two as a tuple, because `split_train_valid` used to do this and apparently [the relevant code still expects this](https://github.com/lisa-lab/pylearn2/blob/393a75583e20b7ec7a539bdde66eb06596afe90d/pylearn2/datasets/svhn.py#L248).~~

Also, [this](https://github.com/lisa-lab/pylearn2/blob/393a75583e20b7ec7a539bdde66eb06596afe90d/pylearn2/datasets/svhn.py#L260-261) looks totally suspicious and I suspect that `which_set='train_all'` has incorrect labels.



Discussion:
First part was fixed in #1371, thanks to @sandeepkbhat.
The second part is indeed suspicious.

~~I saw that, but it looks like it got merged away or something -- it's not in master ([current link](https://github.com/lisa-lab/pylearn2/blob/master/pylearn2/datasets/svhn.py#L238-239) as of the time of this comment).~~

EDIT: nevermind, I'm not sure why, but github gave me an old copy.


Resolving patch:
diff --git a/pylearn2/datasets/svhn.py b/pylearn2/datasets/svhn.py
--- a/pylearn2/datasets/svhn.py
+++ b/pylearn2/datasets/svhn.py
@@ -265,7 +265,10 @@ def split_train_valid(path, num_valid_train=400,
             if which_set == 'train_all':
                 train_x, train_y = load_data("{0}train_32x32.mat".format(path))
                 data_x = numpy.concatenate((data_x, train_x))
-                data_y = numpy.concatenate((data_y, data_y))
+                data_y = numpy.concatenate((data_y, train_y))
+
+        assert data_x.shape[0] == sizes[which_set]
+        assert data_y.shape[0] == sizes[which_set]
 
         if shuffle:
             index = range(data_x.shape[0])
@@ -273,9 +276,6 @@ def split_train_valid(path, num_valid_train=400,
             data_x = data_x[index, :]
             data_y = data_y[index, :]
 
-        assert data_x.shape[0] == sizes[which_set]
-        assert data_y.shape[0] == sizes[which_set]
-
         # .mat labels for SVHN are in range [1,10]
         # So subtract 1 to map labels to range [0,9]
         # This is consistent with range for MNIST dataset labels
@@ -486,7 +486,10 @@ def split_train_valid(path, num_valid_train=400,
             if which_set == 'train_all':
                 train_x, train_y = load_data("{0}train_32x32.mat".format(path))
                 data_x = numpy.concatenate((data_x, train_x))
-                data_y = numpy.concatenate((data_y, data_y))
+                data_y = numpy.concatenate((data_y, train_y))
+
+        assert data_x.shape[0] == sizes[which_set]
+        assert data_y.shape[0] == sizes[which_set]
 
         if shuffle:
             index = range(data_x.shape[0])
@@ -494,7 +497,4 @@ def split_train_valid(path, num_valid_train=400,
             data_x = data_x[index, :]
             data_y = data_y[index, :]
 
-        assert data_x.shape[0] == sizes[which_set]
-        assert data_y.shape[0] == sizes[which_set]
-
         return data_x, data_y


Test patch: