python - 是否可以只加载 mnist 或其他元组的一部分
问题描述
我正忙着用 构建 OCR MNIST
,但是由于 in 出现错误,我在上传数据集Tensorflow
时Keras
遇到了问题。我可以只上传前几项而不设置错误吗MNIST
MNIST
解决方案
你的问题不是很清楚。然而,下面是如何使用 TensorFlow 和 Keras 中的简单函数加载 MNIST 的数据样本。
1)。使用 TensorFlow 加载 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)
2).使用 Keras 加载 MNIST 的一部分。
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)
推荐阅读
- r - 按列值对数据框中的行值进行排序
- mysql - 使用 charset latin1 创建的 MySql VIEW 所有配置都设置为 utf8
- java - 带有 Autowired 注释的 AbstractClass Junit
- c# - 为什么我在主视图的控制器的后期操作中得到部分视图数据为空?
- html - 链接第一次后无法点击
- android - Android 空白网格项目
- php - ajax上传图片和表单中的另一个数据
- javascript - 无法将分配的默认值更改为日期类型 angularjs 的输入
- python - Heroku 和 Django 的 Debug=False 时出现 500 错误
- mongodb - mongodb区分数组中映射的键,它是文档的属性