I am using MNIST dataset from keras -
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
Before loading the data, how can I shuffle this dataset?
I am using MNIST dataset from keras -
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
Before loading the data, how can I shuffle this dataset?
I think it is not possible to do this with keras.datasets.mnist.load_data()
.
You have different options:
Download the dataset yourself and load it directly from your files. Then shuffle and split it
Use tensorflow_datasets
. Example:
import tensorflow_dataset as tfds
(df_train,df_test)=tfds.load('minst',split=['train','test'],shuffle_files=True, as_supervised=True)
Build a dataset from your x_train,x_test,y_train,y_test. Then shuffel and split it again.
You can use as tensorflow suggests,
import tensorflow as tf
import tensorflow_datasets as tfds
(ds_train, ds_test), ds_info = tfds.load(
'mnist',
split=['train', 'test'],
shuffle_files=True,
as_supervised=True,
with_info=True,
)
I am not sure but you can use this and convert into numpy as follows:
import numpy as np
ds_test_np = np.array(list(ds_test.as_numpy_iterator()))
ds_train_np = np.array(list(ds_train.as_numpy_iterator()))