- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图使用来自 tensorflow 的 cifar-10 预测单个图像的类别。
我找到了这段代码,但是失败并出现了这个错误:
赋值要求两个张量的形状匹配。 lhs 形状= [18,384] rhs 形状= [2304,384]我知道这是因为批处理的大小只有 1。(使用 expand_dims 我创建了一个假批处理。)
但我不知道如何解决这个问题?
我到处搜索,但没有解决方案..提前致谢!
from PIL import Image
import tensorflow as tf
from tensorflow.models.image.cifar10 import cifar10
width = 24
height = 24
categories = ["airplane","automobile","bird","cat","deer","dog","frog","horse","ship","truck" ]
filename = "path/to/jpg" # absolute path to input image
im = Image.open(filename)
im.save(filename, format='JPEG', subsampling=0, quality=100)
input_img = tf.image.decode_jpeg(tf.read_file(filename), channels=3)
tf_cast = tf.cast(input_img, tf.float32)
float_image = tf.image.resize_image_with_crop_or_pad(tf_cast, height, width)
images = tf.expand_dims(float_image, 0)
logits = cifar10.inference(images)
_, top_k_pred = tf.nn.top_k(logits, k=5)
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
saver = tf.train.Saver()
ckpt = tf.train.get_checkpoint_state('/tmp/cifar10_train')
if ckpt and ckpt.model_checkpoint_path:
print("ckpt.model_checkpoint_path ", ckpt.model_checkpoint_path)
saver.restore(sess, ckpt.model_checkpoint_path)
else:
print('No checkpoint file found')
exit(0)
sess.run(init_op)
_, top_indices = sess.run([_, top_k_pred])
for key, value in enumerate(top_indices[0]):
print (categories[value] + ", " + str(_[0][key]))
编辑
我试图放置一个占位符,第一个形状为 None,但出现此错误:必须完全定义新变量 (local3/weights) 的形状,而不是 (?, 384)。
现在我真的迷路了..这是新代码:
from PIL import Image
import tensorflow as tf
from tensorflow.models.image.cifar10 import cifar10
import itertools
width = 24
height = 24
categories = [ "airplane","automobile","bird","cat","deer","dog","frog","horse","ship","truck" ]
filename = "toto.jpg" # absolute path to input image
im = Image.open(filename)
im.save(filename, format='JPEG', subsampling=0, quality=100)
x = tf.placeholder(tf.float32, [None, 24, 24, 3])
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
# Restore variables from training checkpoint.
input_img = tf.image.decode_jpeg(tf.read_file(filename), channels=3)
tf_cast = tf.cast(input_img, tf.float32)
float_image = tf.image.resize_image_with_crop_or_pad(tf_cast, height, width)
images = tf.expand_dims(float_image, 0)
i = images.eval()
print (i)
sess.run(init_op, feed_dict={x: i})
logits = cifar10.inference(x)
_, top_k_pred = tf.nn.top_k(logits, k=5)
variable_averages = tf.train.ExponentialMovingAverage(
cifar10.MOVING_AVERAGE_DECAY)
variables_to_restore = variable_averages.variables_to_restore()
saver = tf.train.Saver(variables_to_restore)
ckpt = tf.train.get_checkpoint_state('/tmp/cifar10_train')
if ckpt and ckpt.model_checkpoint_path:
print("ckpt.model_checkpoint_path ", ckpt.model_checkpoint_path)
saver.restore(sess, ckpt.model_checkpoint_path)
else:
print('No checkpoint file found')
exit(0)
_, top_indices = sess.run([_, top_k_pred])
for key, value in enumerate(top_indices[0]):
print (categories[value] + ", " + str(_[0][key]))
最佳答案
我认为这是因为通过 tf.Variable
或 tf.get_variable
获取的变量必须具有完整定义的形状。您可以检查您的代码并给出完整定义的形状。
关于python - Tensorflow 和 cifar 10,测试单个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40266275/
为了进行微调,您将使用 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。我
我是一名优秀的程序员,十分优秀!