Ваш вопрос не совсем понятен. Однако ниже показано, как загрузить выборку данных MNIST с помощью простых функций в TensorFlow и Keras.
1). Загрузить часть MNIST с помощью TensorFlow.
from tensorflow.examples.tutorials.mnist import input_data
data = input_data.read_data_sets('./tmp/mnist_data', one_hot = True)
data_slice = 3000
train_x = data.train.images[:data_slice,:]
train_y = data.train.labels[:data_slice,:]
test_x = data.test.images[:data_slice,:]
test_y = data.test.labels[:data_slice,:]
train_x.shape
'Output': (3000, 784)
2). Загрузить часть MNIST с помощью Keras.
import keras
# import dataset
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
# flatten the features from 28*28 pixel to 784 wide vector
x_train = np.reshape(x_train, (-1, 784)).astype('float32')
x_test = np.reshape(x_test, (-1, 784)).astype('float32')
# one-hot encode the targets
y_train = keras.utils.to_categorical(y_train)
y_test = keras.utils.to_categorical(y_test)
data_slice = 3000
x_train = x_train[:data_slice,:]
y_train = y_train[:data_slice,:]
x_test = x_test[:data_slice,:]
y_test = y_test[:data_slice,:]
x_train.shape
'Output': (3000, 784)
y_train.shape
'Output': (3000, 10)