Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MNIST data with Keras

I am currently playing around with MNIST data as part of course on using numpy and tensorflow. I was running the code they provided in course and I noticed a few warnings from tensorflow when running this snippet of code:

from tensorflow.examples.tutorials.mnist import input_data

mnist = input_data.read_data_sets("../data/mnist_data/", one_hot=True)

I looked into the documentation and read that this is deprecated and one should use MNIST from keras instead. So I changed the above code to this

from keras.datasets import mnist
from keras.models import Sequential, load_model
from keras.layers.core import Dense, Dropout, Activation
from keras.utils import np_utils

(X_train, y_train), (X_test, y_test) = mnist.load_data()

my issue now is that in the course material they use this function:

training_digits, training_labels = mnist.train.next_batch(5000)

that function next_batch() isn't available with keras and the original MNIST dataset is pretty large. Is there a clever way to this with keras?

Many thanks in advance!

like image 245
afettouhi Avatar asked Jul 26 '26 15:07

afettouhi


1 Answers

you can set batch_size and use one shot iterator() as described here Keras Mnist documentation

like image 60
nag Avatar answered Jul 29 '26 05:07

nag