【问题标题】:Tensorflow mask from one-hot encoding来自 one-hot 编码的 TensorFlow 掩码
【发布时间】:2017-01-07 19:27:43
【问题描述】:

我有 examples = tf.placeholder(tf.int32, [batch_size]) 形式的 OHE 标签,其中每个示例都是 int 范围内的 int

我的输出是一个softmax概率分布的形式,形状为[batch_size, ohe_size]

我正在尝试研究如何创建一个掩码,该掩码将为我提供每个示例的概率分布。例如

probs = [[0.1, 0.6, 0.3]
         [0.2, 0.1, 0.7]
         [0.9, 0.1, 0.0]]
examples = [2, 2, 0]

some_mask_func(probs, example) # <- Need this function    
> [0.3, 0.7, 0.9]

【问题讨论】:

  • 您能解释一下您是如何从输入中获得该输出的吗?
  • @martianwars 我将在帖子中澄清这些示例是标签而不是输入
  • 不,我在问你,你究竟是如何产生[0.3, 0.7, 0.9]的?
  • 不知道为什么这很重要?
  • 不,我不太明白你对 examplesprobs 做了什么来得到那个

标签: python tensorflow


【解决方案1】:

如果我正确理解了你的例子,你需要tf.gather_nd

range = tf.range(tf.shape(examples)[0])
indices = tf.pack([range, examples], axis=1)
result = tf.gather_nd(probs, indices)

【讨论】:

  • 谢谢,这正是我要找的
猜你喜欢
  • 1970-01-01
  • 2018-05-09
  • 2016-12-11
  • 1970-01-01
  • 2017-06-21
  • 1970-01-01
  • 1970-01-01
  • 2021-04-14
  • 2017-06-07
相关资源
最近更新 更多