【问题标题】:How to use argmax tensorflow function in 3d array?如何在 3d 数组中使用 argmax tensorflow 函数?
【发布时间】:2017-09-01 05:38:01
【问题描述】:

我想知道如何在 3D 数组中使用tf.argmax

我的输入数据是这样的:

[[[0, -1, 5, 2, 1], [2, 2, 3, 2, 5], [6, 1, 2, 4, -1]], 
[[-1, -2, 3, 2, 1], [0, 3, 2, 7, -1], [-1, 5, 2, 1, 3]]]

我想通过这个输入数据得到 argmax 的输出,如下所示:

[[2, 4, 0], [2, 3, 1]]

我想以这种格式使用softmax_cross_entropy_with_logitsfunction。

我应该如何使用tf.nn.softmax_cross_entropy_with_logits函数和tf.equal(tf.argmax)tf.reduce_mean(tf.cast)

【问题讨论】:

    标签: python tensorflow softmax argmax


    【解决方案1】:

    您可以使用tf.argmaxaxis=3

    a = tf.constant([[[0, -1, 5, 2, 1], [2, 2, 3, 2, 5], [6, 1, 2, 4, -1]], 
            [[-1, -2, 3, 2, 1], [0, 3, 2, 7, -1], [-1, 5, 2, 1, 3]]])
    b = tf.argmax(a, axis=2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 2020-04-27
      • 2019-09-30
      • 2017-12-30
      • 2014-05-06
      • 2017-01-26
      • 1970-01-01
      相关资源
      最近更新 更多