【问题标题】:Getting largest index from tensor从张量中获取最大索引
【发布时间】:2018-12-28 21:36:52
【问题描述】:

我的 CNN 产生了以下结果(来自 model.predict()):

Tensor("input_1:0", shape=(?, 2, 26, 1), dtype=float32)
[9.9952221e-01 2.3613637e-04 1.9953270e-06 1.6922619e-05 2.2012556e-04
 2.4441533e-07 3.5276526e-07 7.4913805e-07 4.0657511e-07 8.7760031e-07]

我想从这个 numpy 数组中获取最大值的索引。现在,我已经尝试过这样做(x 是上面的数组):

result = x.index(max(x))

相反,这会引发错误,指出此数据类型不支持 .index?

【问题讨论】:

    标签: python numpy tensorflow machine-learning keras


    【解决方案1】:

    您可以简单地使用np.argmax 函数:

    import numpy as np
    
    preds = model.predict(test_data)
    pred_class = np.argmax(preds, axis=-1)
    

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 1970-01-01
      • 2022-10-23
      • 1970-01-01
      • 2018-12-20
      • 2020-06-10
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多