- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我最近正在制作一个基于 TensorFlow CNN、MNIST 数据集和服务器接口(interface)的项目。
在预测部分,我使用tf.argmax()来获取最大的logit,这将是预测值。但是,它返回的值似乎不是正确的答案。
预测函数大约是这样的:
self.img = tf.reshape(tf.image.convert_image_dtype(img, tf.float32), shape=[1, 28, 28, 1])
self._create_model()
saver = tf.train.Saver()
ckpt = tf.train.get_checkpoint_state('../checkpoints/')
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
saver.restore(sess, ckpt.model_checkpoint_path)
pred = tf.nn.softmax(self.logits)
prediction = tf.argmax(pred, 1)
logit = sess.run(pred)
result = sess.run(prediction)[0]
print(logit)
print(result)
return result
结果是:
127.0.0.1 - - [19/Apr/2018 21:35:47] "POST /index.html HTTP/1.1" 200 -
[[ 0. 0. 0. 0. 0. 1. 0. 0. 0. 0.]]
1
如您所见,logits 显示最大数字的索引是 5,但是 tf.argmax() 给了我 1> 相反。
顺便说一下,my model是基本的 MNIST CNN 模型,如您在链接中看到的。
那么这个tf.argmax()函数发生了什么,或者我的代码有问题?
最佳答案
由于您的 logit
(pred
) 和 result
(prediction[0]
) 来自两个不同的 sess.run
,我想知道运行之间是否存在一些差异。例如,图中有一个迭代器将输入发送到模型。通过不同的运行,迭代器发送不同的数据,从而导致不同的预测。如果将 pred
和 prediction
放在同一个 sess.run
中,如下所示,将会很有趣:
logit, result = sess.run((pred, prediction))
print(logit)
print(result[0])
关于python - tf.argmax() 返回意外结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49923675/
我试图沿一个轴边缘化数组,并检查一维峰值是否出现在与原始二维峰值相同的相关索引处。在什么情况下(x 的形式)以下断言会失败? def check(x,axis=None): import nu
为什么会有一个blas子程序 ISAMAX适用于 argmax abs 但不适用于 argmax ? 在 C++ 中使用 std::max_element使用编译器优化标志 -O3 我得到的速度与 b
为什么 TensorFlow 张量在 Numpy 中的数学函数中的行为与在 Keras 中的数学函数中的行为不同? Numpy 数组在与 TensorFlow Tensor 相同的情况下似乎表现正常。
我想要做什么,但 argmax 只给我第一个值为 True 的值: Se = pd.Series(np.arange(6), index=list("abcdef")) #a 0 #b 1
下面的输出 import numpy as np print(np.argmax([i for i in range(0, 10)])) print(np.argmax(i for i in rang
我有一个形状为 (n, n, g) 的 3D 数组,我需要每个 (n, n) argmax,即结果应该是两个长度为 g 的索引向量 (x, y)。 直观的解决方案是: array = np.rando
我有一个如下所示的多维数组: my_array = np.arange(2)[:,None,None] *np.arange(4)[:, None]*np.arange(8) 我正在寻找二维 argm
我想使用一个函数,该函数将张量作为输入并返回张量各轴上最大值的索引。我知道存在一个函数 tf.argmax() 具有完全相同的功能,但是我如何自己实现它(在实现某些自定义函数时这可能是必要的)? 现在
假设我有矩阵 import numpy as np A = np.matrix([[1,2,3,33],[4,5,6,66],[7,8,9,99]]) 我试图理解函数 argmax,据我所知它返
看代码吧~ ? 1
我有一个形状为(n, m, s) 的矩阵A。在第 0 个轴的每个位置,我需要对应于 (m, s) 形数组中最大值的位置。 例如: np.random.seed(1) A = np.random.ran
我正在学习 tensorflow,在各种示例中,我已经看到我们使用 tf.argmax(logits, 1) 从 logits 中获得预测.据我了解logits是概率值和 tf.argmax()会给索
JavaScript 对我来说远不是一种熟悉的语言。我有一个逻辑,我正在尝试优化速度。它包括找到二维数组(矩形)的 argmax、行和列索引。目前,我有一个天真的实现 function argMax2
我最近正在制作一个基于 TensorFlow CNN、MNIST 数据集和服务器接口(interface)的项目。 在预测部分,我使用tf.argmax()来获取最大的logit,这将是预测值。但是,
我有一些数据y_hat,看起来像: [[0. 1. 0. ... 0. 0. 0.] [0. 1. 0. ... 0. 0. 0.] [0. 1. 0. ... 0. 0. 0.] ... [
我有一个形状为 [batch_size, channel, depth, height, width] 的张量: torch.Size([1, 1, 32, 64, 64]) 数据: tensor([
我想测试tf.argmax()的功能,但是当我运行代码时,遇到了错误。这是我的代码 import tensorflow as tf a=tf.argmax([1,0,0],1) with tf.Se
我目前正致力于创建一种排名算法来对学生之间的关系进行排名。在我的 NxN 矩阵 F 中: F[i, j] 指的是学生 i 和学生 j 之间的关系。值越高,关系越强。 我的问题是这样的。为了创建一个由
我有一个 numpy 矩阵,我想获取每一行中最大值的索引。例如 [[1,2,3],[1,3,2],[3,2,1]] 会回来 [0,1,2] 但是,当每行中的最大值超过 1 个时,numpy.argma
所以我知道 numpy argmax 沿轴检索最大值。因此, x = np.array([[12,11,10,9],[16,15,14,13],[20,19,18,17]]) print(x) pri
我是一名优秀的程序员,十分优秀!