Skip to content

Commit 16377ce

Browse files
Add KMNIST dataset
1 parent d62662a commit 16377ce

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ from extra_keras_datasets import emnist
9696

9797
---
9898

99+
### KMNIST-KMNIST
100+
101+
```
102+
from extra_keras_datasets import kmnist
103+
(input_train, target_train), (input_test, target_test) = kmnist.load_data(type='kmnist')
104+
```
105+
106+
<a href="./assets/kmnist-kmnist.png"><img src="./assets/kmnist-kmnist.png" width="500" style="border: 3px solid #f6f8fa;" /></a>
107+
108+
---
109+
110+
### KMNIST-K49
111+
112+
```
113+
from extra_keras_datasets import kmnist
114+
(input_train, target_train), (input_test, target_test) = kmnist.load_data(type='k49')
115+
```
116+
117+
<a href="./assets/kmnist-k49.png"><img src="./assets/kmnist-k49.png" width="500" style="border: 3px solid #f6f8fa;" /></a>
118+
119+
---
120+
99121
## Contributors and other references
100122
* **[tlindbloom](https://stackoverflow.com/users/4008755/tlindbloom) on StackOverflow:** [loading EMNIST-letters dataset](https://stackoverflow.com/questions/51125969/loading-emnist-letters-dataset/53547262#53547262) in [emnist.py](./emnist.py).
101123

assets/kmnist-k49.png

123 KB
Loading

assets/kmnist-kmnist.png

133 KB
Loading

kmnist.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'''
2+
Import the KMNIST dataset
3+
Source: https://arxiv.org/abs/1812.01718
4+
Description: Japanese character MNIST dataset.
5+
6+
~~~ Important note ~~~
7+
Please cite the following paper when using or referencing the dataset:
8+
Clanuwat, T., Bober-Irizar, M., Kitamoto, A., Lamb, A., Yamamoto, K., & Ha, D. (2018). Deep learning for classical Japanese literature. arXiv preprint arXiv:1812.01718. Retrieved from https://arxiv.org/abs/1812.01718
9+
10+
'''
11+
12+
from keras.utils.data_utils import get_file
13+
import numpy as np
14+
15+
def load_data(path='kmnist.npz', type='kmnist'):
16+
"""Loads the KMNIST dataset.
17+
# Arguments
18+
path: path where to cache the dataset locally
19+
(relative to ~/.keras/datasets).
20+
type: any of kmnist, k49
21+
# Returns
22+
Tuple of Numpy arrays: `(input_train, target_train), (input_test, target_test)`.
23+
"""
24+
# Load training images
25+
path_train = get_file(
26+
f'{path}_{type}_train_imgs',
27+
origin=f'http://codh.rois.ac.jp/kmnist/dataset/{type}/{type}-train-imgs.npz'
28+
)
29+
input_train = np.load(path_train)['arr_0']
30+
31+
# Load training labels
32+
path_train_labels = get_file(
33+
f'{path}_{type}_train_labels',
34+
origin=f'http://codh.rois.ac.jp/kmnist/dataset/{type}/{type}-train-labels.npz'
35+
)
36+
target_train = np.load(path_train_labels)['arr_0']
37+
38+
# Load testing images
39+
path_test = get_file(
40+
f'{path}_{type}_test_imgs',
41+
origin=f'http://codh.rois.ac.jp/kmnist/dataset/{type}/{type}-test-imgs.npz'
42+
)
43+
input_test = np.load(path_test)['arr_0']
44+
45+
# Load testing labels
46+
path_test_labels = get_file(
47+
f'{path}_{type}_test_labels',
48+
origin=f'http://codh.rois.ac.jp/kmnist/dataset/{type}/{type}-test-labels.npz'
49+
)
50+
target_test = np.load(path_test_labels)['arr_0']
51+
52+
# Return data
53+
return (input_train, target_train), (input_test, target_test)

0 commit comments

Comments
 (0)