Python 是否可以只加载mnist或其他元组的一部分

Python 是否可以只加载mnist或其他元组的一部分,python,tensorflow,keras,mnist,Python,Tensorflow,Keras,Mnist,我正忙着用MNIST、Tensorflow和Keras构建OCR,但由于在MNIST中出现错误,我上传MNIST数据集时遇到问题。我是否可以只上载前几个没有设置错误的项目您可以从此处手动下载数据集,并使用您需要的: 你的问题不太清楚。然而,下面是如何使用TensorFlow和Keras中的简单函数加载MNIST的数据样本 一,。用TensorFlow加载MNIST的一部分 2.向MNIST的一部分加载KERA 你面临什么样的错误。?如何加载mnist数据。? from tensorflow.ex

我正忙着用MNIST、Tensorflow和Keras构建OCR,但由于在MNIST中出现错误,我上传MNIST数据集时遇到问题。我是否可以只上载前几个没有设置错误的项目

您可以从此处手动下载数据集,并使用您需要的:


你的问题不太清楚。然而,下面是如何使用TensorFlow和Keras中的简单函数加载MNIST的数据样本

一,。用TensorFlow加载MNIST的一部分

2.向MNIST的一部分加载KERA


你面临什么样的错误。?如何加载mnist数据。?
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)
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)