- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我对机器学习比较陌生,目前几乎没有开发它的经验。
所以我的问题是:在训练和评估来自tensorflow tutorial的cifar10数据集之后我想知道如何使用示例图像对其进行测试?
我可以训练和评估 Imagenet tutorial from the caffe machine-learning framework并且使用 python API 在自定义应用程序上使用经过训练的模型相对容易。
如有任何帮助,我们将不胜感激!
最佳答案
这不是问题的 100% 答案,但它是一种类似的解决方法,基于问题评论中建议的 MNIST NN 训练示例。
基于 TensorFlow begginer MNIST 教程,感谢 this tutorial ,这是一种使用自定义数据训练和使用神经网络的方法。
请注意,正如@Yaroslav Bulatov 在评论中提到的那样,对于诸如 CIFAR10 之类的教程也应该做类似的事情。
import input_data
import datetime
import numpy as np
import tensorflow as tf
import cv2
from matplotlib import pyplot as plt
import matplotlib.image as mpimg
from random import randint
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
x = tf.placeholder("float", [None, 784])
W = tf.Variable(tf.zeros([784,10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x,W) + b)
y_ = tf.placeholder("float", [None,10])
cross_entropy = -tf.reduce_sum(y_*tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
#Train our model
iter = 1000
for i in range(iter):
batch_xs, batch_ys = mnist.train.next_batch(100)
sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
#Evaluationg our model:
correct_prediction=tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy=tf.reduce_mean(tf.cast(correct_prediction,"float"))
print "Accuracy: ", sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels})
#1: Using our model to classify a random MNIST image from the original test set:
num = randint(0, mnist.test.images.shape[0])
img = mnist.test.images[num]
classification = sess.run(tf.argmax(y, 1), feed_dict={x: [img]})
'''
#Uncomment this part if you want to plot the classified image.
plt.imshow(img.reshape(28, 28), cmap=plt.cm.binary)
plt.show()
'''
print 'Neural Network predicted', classification[0]
print 'Real label is:', np.argmax(mnist.test.labels[num])
#2: Using our model to classify MNIST digit from a custom image:
# create an an array where we can store 1 picture
images = np.zeros((1,784))
# and the correct values
correct_vals = np.zeros((1,10))
# read the image
gray = cv2.imread("my_digit.png", 0 ) #0=cv2.CV_LOAD_IMAGE_GRAYSCALE #must be .png!
# rescale it
gray = cv2.resize(255-gray, (28, 28))
# save the processed images
cv2.imwrite("my_grayscale_digit.png", gray)
"""
all images in the training set have an range from 0-1
and not from 0-255 so we divide our flatten images
(a one dimensional vector with our 784 pixels)
to use the same 0-1 based range
"""
flatten = gray.flatten() / 255.0
"""
we need to store the flatten image and generate
the correct_vals array
correct_val for a digit (9) would be
[0,0,0,0,0,0,0,0,0,1]
"""
images[0] = flatten
my_classification = sess.run(tf.argmax(y, 1), feed_dict={x: [images[0]]})
"""
we want to run the prediction and the accuracy function
using our generated arrays (images and correct_vals)
"""
print 'Neural Network predicted', my_classification[0], "for your digit"
如需进一步的图像调节(白色背景中的数字应完全变暗)和更好的神经网络训练(准确度>91%),请查看 TensorFlow 的高级 MNIST 教程或我提到的第二个教程。
关于python - 如何测试tensorflow cifar10 cnn教程模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33784214/
为了进行微调,您将使用 CIFAR-100 数据集“bus”和“tiger”类的数据。你的任务是找出如何微调预训练的 CNN 模型,使用训练数据(我认为每个类 500 个图像)“bus”和“tiger
我想使用 CIFAR-10 数据集,但我只想要 Frog 、狗、猫、马和鸟类,到目前为止我已经使用了以下代码: # Plot ad hoc CIFAR10 instances from ker
我尝试为 CIFAR-10 数据库构建神经网络。我使用了 Pytorch 框架。 我有一个关于数据加载步骤的问题。 transform_train = T.Compose([ T.Random
我想使用较少的训练数据样本来训练深度神经网络,以减少测试我的代码的时间。我想知道如何使用 Keras TensorFlow 对 Cifar-10 数据集进行子集化。我有以下代码用于训练 Cifar-1
在机器学习方面,我是一个相对初学者。 我一直在使用 Keras 和 TensorFlow 作为后端,但由于某种原因,当我使用 CIFAR-10 数据集时,我没有获得很好的准确性。 这是我的代码。 mo
美好的一天! (或夜晚) CIFAR-10 数据集上的全连接神经网络训练集的误分类错误可以有多低(对于 < 30 个隐藏层)? 是否有可能达到 0.001 或 0? 你能告诉我你的经历吗? 附注我想从
我正在尝试了解 Tensorflow,并且看到了官方示例之一,即 Cifar-10 模型。 在 cifar10.py ,在 inference() 中,您可以看到以下几行: with tf.varia
我想创建一个与 cifar-10 数据集格式相同的数据集,以便与 Tensorflow 一起使用。它应该有图像和标签。基本上,我希望能够获取 cifar-10 代码,但具有不同的图像和标签,并运行该代
我试图在 python 中加载 CIFAR-10 数据集,但它显示的键的名称非常不正常。 dict.keys() 给出以下输出: dict_keys([b'labels', b'batch_label
我已尝试修改 CIFAR-10 示例以在新的 TensorFlow 分布式运行时上运行。但是,在尝试运行该程序时出现以下错误: InvalidArgumentError: Cannot assign
我正在使用 cifar-10 数据集来训练我的分类器。我已经下载了数据集并尝试显示数据集中的图像。我使用了以下代码: from six.moves import cPickle as pickle f
为了让所有事情变得清楚,让我展示整个模型,这非常简单: from keras.datasets import cifar10 #much more libraries imported # simpl
我正在尝试使用深度学习技术构建一个分类器,并使用 cifar-10 数据集来构建一个分类器。我尝试构建一个具有 1024 个隐藏节点的分类器。每个图像的大小为 32*32*3(R-G-B)。由于我的计
我试图在 tensorflow 中使用 cifar100 数据集训练图像分类器模型,但准确率没有增加超过 1.2%。我用谷歌搜索了这个问题并找到了几种解决方案,但我的模型仍然表现不佳。 我实现了一些步
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 2 年前。 Improve this ques
我想使用 cifar 数据集和 keras 框架训练单层神经网络。由于数据集的每个图像都是 32 x 32 x 3,所以我不太确定如何使用没有卷积的单层网络来处理图像。我认为将每个图像展平为形状为 N
我试图使用来自 tensorflow 的 cifar-10 预测单个图像的类别。 我找到了这段代码,但是失败并出现了这个错误: 赋值要求两个张量的形状匹配。 lhs 形状= [18,384] rhs
我正在尝试下载 CIFAR-10 图像数据集; http://www.cs.toronto.edu/~kriz/cifar.html 在 R 中,但我似乎无法提取文件。我已经尝试了所有三种格式 .bi
我正在尝试通过为 cifar 数据集构建分类器来熟悉神经网络。我决定从 tflearn 存储库中获取一个示例,但是我遇到了麻烦。 有一些注意事项: 我正在使用 Jupyter Notebook 来测试
我正在尝试在 Keras 中的 CIFAR-10 数据集上训练 CNN,但只能获得 10% 左右的准确率,基本上是随机的。我正在训练超过 50 个 epoch,批量大小为 32,学习率为 0.01。我
我是一名优秀的程序员,十分优秀!