Is it possible to use tensor mode in tensor flow?

I am trying to create a DAG in Tensorflow where I need to take the mode (most common value) of certain areas of my target. This is done to create a downsampled goal.

Currently, I am pre-processing the targets with downsampling for each individual situation that I may encounter, saving them, and then loading them. Obviously, that would be much simpler if it were integrated into my Tensorflow graph so that I could lower the performance at runtime.

But I searched everywhere, and I cannot find any evidence of tf.reduce_mode , which will function just like tf.reduce_mean . Is there a way to build this functionality in a Tensorflow graph?

+5
source share
1 answer

My idea is that we get unique numbers and their number. Then we find the numbers that appear most often. Finally, we get these numbers (there can be more than one) using their indices in the tensor of the number counter.

 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 
0
source

Source: https://habr.com/ru/post/1272506/


All Articles