是否可以采用Tensorflow中的张量模式?

DM *_*nzo 6 python-3.x tensorflow

我正在尝试在Tensorflow中构建一个DAG,我需要采用目标各个区域的模式(最常见的值).这是为了构建下采样目标.

现在,我正在为我可能遇到的每种情况预先处理下采样目标,保存它们,然后加载它们.显然,如果它被集成到我的Tensorflow图中,这将更容易,因此我可以在运行时下采样.

但我到处寻找,我找不到任何证据,证明tf.reduce_mode其功能与此相同tf.reduce_mean.有没有办法在Tensorflow图中构建此功能?

gre*_*ess 1

我的想法是我们得到唯一的数字及其计数。然后我们找到出现最频繁的数字。最后,我们通过使用数字张量中的索引来获取这些数字(可能不止一个)。

samples = tf.constant([10, 32, 10, 5, 7, 9, 9, 9])
unique, _, count = tf.unique_with_counts(samples)
max_occurrences = tf.reduce_max(count)
max_cond = tf.equal(count, max_occurrences)
max_numbers = tf.squeeze(tf.gather(unique, tf.where(max_cond)))

with tf.Session() as sess:
  print 'Most frequent Numbers\n', sess.run(max_numbers)
> Most frequent Numbers
  9
Run Code Online (Sandbox Code Playgroud)