Function to (download and) load the MNIST data :param mode: train or test :return: images and the corresponding labels
(mode='train')
| 3 | |
| 4 | |
| 5 | def load_data(mode='train'): |
| 6 | """ |
| 7 | Function to (download and) load the MNIST data |
| 8 | :param mode: train or test |
| 9 | :return: images and the corresponding labels |
| 10 | """ |
| 11 | from tensorflow.examples.tutorials.mnist import input_data |
| 12 | mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) |
| 13 | if mode == 'train': |
| 14 | x_train, y_train, x_valid, y_valid = mnist.train.images, mnist.train.labels, \ |
| 15 | mnist.validation.images, mnist.validation.labels |
| 16 | return x_train, y_train, x_valid, y_valid |
| 17 | elif mode == 'test': |
| 18 | x_test, y_test = mnist.test.images, mnist.test.labels |
| 19 | return x_test, y_test |
| 20 | |
| 21 | |
| 22 | def randomize(x, y): |