I'm trying to construct a DAG in Tensorflow where I need to take the mode (most frequent value) of individual regions of my target. This is in order to construct a downsampled target.
Right now, I'm pre-processing the downsampled targets for every individual situation I might encounter, saving them, and then loading them. Obviously, this would all be much easier if it was integrated into my Tensorflow graph, so that I could downsample at runtime.
But I've looked everywhere, and I can find no evidence of a tf.reduce_mode
, that would function the same as tf.reduce_mean
. Is there any way to construct this functionality in a Tensorflow graph?
The easiest[A] way to evaluate the actual value of a Tensor object is to pass it to the Session. run() method, or call Tensor. eval() when you have a default session (i.e. in a with tf.
You can use tf. slice on higher dimensional tensors as well. You can also use tf. strided_slice to extract slices of tensors by 'striding' over the tensor dimensions.
TensorFlow uses graphs as the format for saved models when it exports them from Python. Graphs are also easily optimized, allowing the compiler to do transformations like: Statically infer the value of tensors by folding constant nodes in your computation ("constant folding").
TensorFlow, as the name indicates, is a framework to define and run computations involving tensors. A tensor is a generalization of vectors and matrices to potentially higher dimensions. Internally, TensorFlow represents tensors as n-dimensional arrays of base datatypes.
My idea is that we get the unique numbers and their counts. We then find the numbers that appear most frequently. Finally we fetch those numbers (could be more than one) out by using their indices in the number-count tensor.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With