Repository: chainer/chainer

Issue:
get_cifar100() does not work
`get_cifar100()` causes the following error.

```
>>> chainer.datasets.get_cifar100()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/chainer/datasets/cifar.py", line 84, in get_cifar100
    raw = _retrieve_cifar('cifar-100')
  File "/usr/local/lib/python2.7/dist-packages/chainer/datasets/cifar.py", line 145, in _retrieve_cifar
    return download.cache_or_load_file(path, creator, numpy.load)
  File "/usr/local/lib/python2.7/dist-packages/chainer/dataset/download.py", line 145, in cache_or_load_file
    content = creator(temp_path)
  File "/usr/local/lib/python2.7/dist-packages/chainer/datasets/cifar.py", line 127, in creator
    d = _pickle_load(archive.extractfile(file_name))
  File "/usr/lib/python2.7/tarfile.py", line 2143, in extractfile
    tarinfo = self.getmember(member)
  File "/usr/lib/python2.7/tarfile.py", line 1827, in getmember
    raise KeyError("filename %r not found" % name)
KeyError: "filename 'cifar-100-batches-py/data_batch_1' not found"
```

cifar-100's directory structure seems to be different from cifar-10's.

```
$ tar xvzf cifar-100-python.tar.gz 
cifar-100-python/
cifar-100-python/file.txt~
cifar-100-python/train
cifar-100-python/test
cifar-100-python/meta

$ tar xvzf cifar-10-python.tar.gz 
cifar-10-batches-py/
cifar-10-batches-py/data_batch_4
cifar-10-batches-py/readme.html
cifar-10-batches-py/test_batch
cifar-10-batches-py/data_batch_3
cifar-10-batches-py/batches.meta
cifar-10-batches-py/data_batch_2
cifar-10-batches-py/data_batch_5
cifar-10-batches-py/data_batch_1
```

They should not be retrieved with the same logic.
https://github.com/pfnet/chainer/blob/master/chainer/datasets/cifar.py#L126



Discussion:

Resolving patch:
diff --git a/chainer/datasets/cifar.py b/chainer/datasets/cifar.py
--- a/chainer/datasets/cifar.py
+++ b/chainer/datasets/cifar.py
@@ -81,7 +81,7 @@ def get_cifar100(withlabel=True, ndim=3, scale=1.):
         datasets are arrays of images.
 
     """
-    raw = _retrieve_cifar('cifar-100')
+    raw = _retrieve_cifar_100()
     train = _preprocess_cifar(raw['train_x'], raw['train_y'],
                               withlabel, ndim, scale)
     test = _preprocess_cifar(raw['test_x'], raw['test_y'],
@@ -106,6 +106,32 @@ def _preprocess_cifar(images, labels, withlabel, ndim, scale):
         return images
 
 
+def _retrieve_cifar_100():
+    root = download.get_dataset_directory('pfnet/chainer/cifar')
+    path = os.path.join(root, 'cifar-100.npz')
+    url = 'https://www.cs.toronto.edu/~kriz/cifar-100-python.tar.gz'
+
+    def creator(path):
+
+        def load(archive, file_name):
+            d = _pickle_load(archive.extractfile(file_name))
+            x = d['data'].reshape((-1, 3072))
+            y = numpy.array(d['fine_labels'], dtype=numpy.uint8)
+            return x, y
+
+        archive_path = download.cached_download(url)
+        with tarfile.open(archive_path, 'r:gz') as archive:
+            train_x, train_y = load(archive, 'cifar-100-python/train')
+            test_x, test_y = load(archive, 'cifar-100-python/test')
+
+        numpy.savez_compressed(path, train_x=train_x, train_y=train_y,
+                               test_x=test_x, test_y=test_y)
+        return {'train_x': train_x, 'train_y': train_y,
+                'test_x': test_x, 'test_y': test_y}
+
+    return download.cache_or_load_file(path, creator, numpy.load)
+
+
 def _retrieve_cifar(name):
     root = download.get_dataset_directory('pfnet/chainer/cifar')
     path = os.path.join(root, '{}.npz'.format(name))


Test patch: