【问题标题】:preparing training data that I can use tf.argmax for testing准备训练数据,我可以使用 tf.argmax 进行测试
【发布时间】:2017-09-07 22:03:53
【问题描述】:

我正在使用 CIFAR 进行 Tensorflow 训练,但我正在将 MNIST 代码更改为我现在需要的代码,但我无法找到让 tf.argmax 按照其原始设计完成这项工作的方法。现在需要像转数组一样,

[2, 7, 1, 5, 3]

进入

[[0, 1, 0, 0, 0, 0, 0, 0], 
 [0, 0, 0, 0, 0, 0, 0, 1], 
 [0, 1, 0, 0, 0, 0, 0, 0],
 [0, 0, 0, 0, 0, 1, 0, 0],
 [0, 0, 0, 1, 0, 0, 0, 0]] 

我该怎么做?我用的是CIFAR 100数据库,这里可以get my code

【问题讨论】:

  • 在这里发布代码。不要只是发布问题并期望有人为您解决问题。

标签: python-3.x numpy machine-learning tensorflow neural-network


【解决方案1】:

看来您需要的是one-hot encoding。要获得 one-hot 编码,请将索引指定为 python 列表并将其与所需的 depth 一起传递给 tf.one_hot

# a numpy array could also work
In [85]: idx = [2, 7, 1, 5, 3]

In [86]: one_hot_vec = tf.one_hot(idx, depth=8, dtype=tf.int32)

In [87]: sess = tf.InteractiveSession()

In [91]: one_hot_vec = tf.one_hot(idx, depth=8, dtype=tf.int32)

In [92]: one_hot_vec.eval()
Out[92]: 
array([[0, 0, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 1],
       [0, 1, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 0]], dtype=int32)

【讨论】:

  • @Divakar 我也很困惑。让我们看看 OP 对此有何评论。
猜你喜欢
  • 2018-03-26
  • 2018-03-29
  • 2014-11-15
  • 2017-02-22
  • 1970-01-01
  • 2019-09-30
  • 1970-01-01
  • 2019-03-15
  • 2021-02-16
相关资源
最近更新 更多