- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 MNIST 数据库训练模型。我正在编写 Tensorflow 教程 Tensorflow tutorial .导入数据库的建议方法是使用 mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True)
但我需要使用类似的东西:
with open('my/directory/train-images-idx3-ubyte.gz', 'rb') as f:
train_images = extract_images(f)
with open('my/directory/train-labels-idx1-ubyte.gz', 'rb') as f:
train_labels = extract_images(f)
...
train_images, train_lables, test_images, test_lables
一起使用的问题:
def main(_):
# Import data
mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True)
# Create the model
x = tf.placeholder(tf.float32, [None, 784])
# Define loss and optimizer
y_ = tf.placeholder(tf.float32, [None, 10])
# Build the graph for the deep net
y_conv, keep_prob = deepnn(x)
with tf.name_scope('loss'):
cross_entropy = tf.nn.softmax_cross_entropy_with_logits(labels=y_,
logits=y_conv)
cross_entropy = tf.reduce_mean(cross_entropy)
with tf.name_scope('adam_optimizer'):
train_step = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy)
with tf.name_scope('accuracy'):
correct_prediction = tf.equal(tf.argmax(y_conv, 1), tf.argmax(y_, 1))
correct_prediction = tf.cast(correct_prediction, tf.float32)
accuracy = tf.reduce_mean(correct_prediction)
graph_location = tempfile.mkdtemp()
print('Saving graph to: %s' % graph_location)
train_writer = tf.summary.FileWriter(graph_location)
train_writer.add_graph(tf.get_default_graph())
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(20000):
batch = mnist.train.next_batch(50)
if i % 100 == 0:
train_accuracy = accuracy.eval(feed_dict={
x: batch[0], y_: batch[1], keep_prob: 1.0})
print('step %d, training accuracy %g' % (i, train_accuracy))
train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})
print('test accuracy %g' % accuracy.eval(feed_dict={
x: mnist.test.images, y_: mnist.test.labels, keep_prob: 1.0}))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--data_dir', type=str,
default='/tmp/tensorflow/mnist/input_data',
help='Directory for storing input data')
FLAGS, unparsed = parser.parse_known_args()
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
最佳答案
使用 TF2 导入 mnist 数据集的推荐方法如下:
从 tensorflow.keras.datasets 导入 mnist
(X_train, Y_train), (X_test, Y_test) = mnist.load_data()
关于python - Tensorflow - 如何导入 MNIST 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50203272/
我的机器学习算法已经学习了 MNIST 数据库中的 70000 张图像。我想在 MNIST 数据集中未包含的图像上对其进行测试。但是,我的预测函数无法读取我的测试图像的数组表示。 如何在外部图像上测试
我正在尝试创建我自己的 MNIST 数据版本。我已将训练和测试数据转换为以下文件; test-images-idx3-ubyte.gz test-labels-idx1-ubyte.gz train-
我通过 pip 在我的 Windows 设备上安装了 python-mnist 包,正如 Github 文档中所述,方法是在我的 Anaconda 终端中输入以下命令: pip install pyt
描述 Fashion Mnist 是一个类似于 Mnist 的图像数据集. 涵盖 10 种类别的 7 万 (6 万训练集 + 1 万测试集) 个不同商品的图片. Tensor
该模型现在只能使用 tf. 识别单个字母。我怎样才能让它识别连续的字母单词? 最佳答案 手写数字识别。 ... MNIST 是一个广泛用于手写数字分类任务的数据集。它由 70,000 个标记为 28x
我已经从 MNIST 训练集中解压了第一张图像,并且可以访问 (28,28) 矩阵。 [[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0
这是我学习的一部分。我知道标准化确实有助于提高准确性,因此将 mnist 值除以 255。这会将所有像素除以 255,因此 28*28 的所有像素的值将在 0.0 到 1.0 范围内. 现在我厌倦了将
我已成功将 MNIST 数据下载到扩展名为 .npy 的文件中。当我打印第一张图像的几列时。我得到以下结果。这里每个数字代表什么? a= np.load("training_set.npy") pri
我用tensorflow写了一个程序来处理Kaggle的数字识别问题。程序可以正常运行,但训练准确率总是很低,大约10%,如下: step 0, training accuracy 0.11 step
在 cnn_mnist.py例如,脚本首先加载训练和测试数据,如您从 120 行到 124 行中看到的那样。当我打印 print(train_data.shape) 时,我得到 (55000, 784
我研究神经网络有一段时间了,用python和numpy做了一个实现。我用 XOR 做了一个非常简单的例子,它运行良好。所以我想我更进一步尝试 MNIST 数据库。 这是我的问题。我正在使用具有 784
我目前正在研究手写数字识别问题。 首先,我针对 MNIST 数据集测试了示例手写数字。 我的准确率为 53%,我需要 90% 以上的准确率。 以下是我迄今为止为提高准确性所做的尝试。 创建了我自己的数
我正在尝试使用我自己的数字图像数据集测试 mnist。 我为此写了一个 python 脚本,但它给出了一个错误。错误在代码的第 16 行。实际上我无法发送图像进行测试。给我一些建议。提前致谢。 imp
我知道这可能是一个愚蠢的问题,但我真的不明白为什么。下面是我尝试从训练数据中打印单个图像和具有相同索引的标签的代码 import matplotlib.pyplot as plt from tenso
我尝试使用以下数据集在 python 中制作一个能够识别手写数字的脚本:http://deeplearning.net/data/mnist/mnist.pkl.gz . 关于这个问题和我试图实现的算
我正在尝试解决 Android 设备上的 MNIST 分类问题。我已经有一个经过训练的模型,现在我希望能够识别照片上的单个数字。 拍完照片后,我会进行一些预处理,然后再将图像传递给模型。这是原始图像的
MNIST 数据集介绍 MNIST 包含 0~9 的手写数字, 共有 60000 个训练集和 10000 个测试集. 数据的格式为单通道 28*28 的灰度图. LeNet 模型
我想导入 mnist digits 数字以在一个图中显示,并编写这样的代码, import keras from keras.datasets import mnist import matplotl
我目前正在研究数字手写识别问题。我发现很多state-of-art算法对mnist dateset采用了一些预处理方法,比如deskewing和jittering(我不知道'jittering'是什么
我到处找,但找不到我想要的。基本上,MNIST 数据集具有像素值在范围 [0, 255] 内的图像。 .人们说,一般来说,最好做到以下几点: 将数据缩放到 [0,1]范围。 将数据标准化为具有零均值和
我是一名优秀的程序员,十分优秀!