- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在构建 DNN 来预测对象是否存在于图像中。我的网络有两个隐藏层,最后一层看起来像这样:
# Output layer
W_fc2 = weight_variable([2048, 1])
b_fc2 = bias_variable([1])
y = tf.matmul(h_fc1, W_fc2) + b_fc2
然后我有标签的占位符:
y_ = tf.placeholder(tf.float32, [None, 1], 'Output')
我分批进行训练(因此输出层形状中的第一个参数为无)。
我使用以下损失函数:
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(
y[:, :1], y_[:, :1], name='xentropy')
loss = tf.reduce_mean(cross_entropy, name='xentropy_mean')
predict_hand = tf.greater(y, 0.5)
correct_prediction = tf.equal(tf.to_float(predict_hand), y_)
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
但是在运行时我得到了以下错误:
Rank mismatch: Rank of labels (received 2) should equal rank of logits minus 1 (received 2).
我想我应该 reshape 标签层,但不确定它期望什么。我在 documentation 中查找它说:
logits: Unscaled log probabilities of rank r and shape [d_0, d_1, ..., d_{r-2}, num_classes] and dtype float32 or float64. labels: Tensor of shape [d_0, d_1, ..., d_{r-2}] and dtype int32 or int64. Each entry in labels must be an index in [0, num_classes).
如果我只有一个类,我的标签应该是什么样子(现在只有 0 或 1)?任何帮助表示赞赏
最佳答案
来自 tf.nn.sparse_softmax_cross_entropy_with_logits
的文档*:
"A common use case is to have logits of shape [batch_size, num_classes] and labels of shape [batch_size]. But higher dimensions are supported."
所以我想你的标签张量应该是 [None]
的形状。请注意,形状为 [None, 1]
或形状为 [None]
的给定张量将包含相同数量的元素。
具有具体虚拟值的示例输入:
>>> logits = np.array([[11, 22], [33, 44], [55, 66]])
>>> labels = np.array([1, 0, 1])
小批量中有 3 个示例,第一个示例的 logits
是 11 和 22,并且有 2 个类:0 和 1。
关于python - 等级不匹配 : Rank of labels (received 2) should equal rank of logits minus 1 (received 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40350849/
这可能是一个简单的“不可能”的答案,但我想确定一下。我目前正在使用 LibreOffice,但如果可以在 Excel 中使用,我可以切换。 我有一个包含几个表格的电子表格,每个表格都有不同数据的相同测
我有一个应用程序,并且在主gradle文件中编写: task myTask { def command = "wsimport -s src" + File.separator + "main
我正在尝试使用点云库从点云中分割一个平面,并且我有一些有关平面模型的先验信息(即法线应该类似于z轴,高度(d)应该大约为0) 。 有没有办法强制我的RANSAC算法选择与我先前模型相似的系数?我认为可
我正在为一个发票项目开发一个基于 excel 的设备数据库。每个独特的项目都有自己的工作簿,但我正在尝试构建一个模板工作簿来限制每个项目的发票中有多少手动工作。每件设备都有一个型号、序列号和允许的地址
嗨, friend 们,我正在开发位置查找应用程序,每次我进入 map 页面时,我都会收到如下警告: "Received memory warning. Level=1" 应用程序崩溃后,我不知道该怎
我在状态中设置了 score、topicTotal 和 level,我正在打印它们中的每一个。 topicTotal 是所有分数相加的最终分数,level 基于它们的 topicTotal。 scor
这个问题在这里已经有了答案: How can I change an element's class with JavaScript? (33 个答案) 关闭 4 年前。
是否可以根据条件扩展 Ember 类?像这样的事情: A.reopen({ if (condition) { init: function() { this.super();
我有以下 DataFrame,其中包含两组动物以及它们每天吃多少食物, df = pd.DataFrame({'animals': ['cat', 'cat', 'dog', 'dog', 'rat'
下面的代码尝试使用 mpi 查找数组的最大数量.但是我不断收到以下错误: Rank 2 in job 47 caused collective abort of all ranks. Exit sta
我在 Tensorflow 文档主页上找到以下关于在等级>2 时使用 matmul 操作的内容: https://www.tensorflow.org/api_docs/python/math_ops
我试图弄清楚如何将Android Library项目分发给某些Beta用户,但是在分发并将其用于示例项目时遇到了一些问题。我正在尝试分发AAR文件。 我的示例项目中的所有内容都可以正常编译,但出现错误
我收到了以下 gradle 构建文件 (gae.gradle),其中包含来自 SpringSource 的示例项目,但是当我尝试使用 gradle 运行它时: gradle gae 它生成错误: FA
我想知道基于我的数据库结构的排名: 我有一个模型 Post 属于一个名为 Edition 的模型(也是 one Edition 有很多 Post). 一个Post有很多Like。 我想根据特定 Edi
我试图在登录页面中向正文添加一个类“bodyLogin”,并在所有其他页面中将其删除。angular的方式应该怎么做? 最佳答案 正如 Jeremy 所建议的那样,我使用了 ng 类,但在自动设置 $
我从 PHPClasses 网站获得了以下 ELO 类。 $S2) { $E = 120 - round(1 / (1 + pow(10, (($R2 - $R1)
我是 Matlab/Octave 用户。 Numpy 文档说 array 比 matrix 更可取。有没有一种方便的方法来处理 rank-1 数组,而不需要不断地 reshape 它? 例子: dat
比如说,我使用 MPI 运行一个并行程序。执行命令 mpirun -n 8 -npernode 2 总共启动8个进程。即每个节点有 2 个进程,总共有 4 个节点。 (OpenMPI 1.5)。其中
我需要按分区(或组)对行进行排名,即如果我的源表是: NAME PRICE ---- ----- AAA 1.59 AAA 2.00 AAA 0.75 BBB 3.48 BBB 2.19 B
我必须从文件中填充 CMake 变量缓存。 我在defaultConfig.externalNativeBuild.cmake.arguments(-C options.cmake)中添加了一个参数。
我是一名优秀的程序员,十分优秀!