Reputation: 3233
I have been using tensorflow to implement a Convolutional neural network, I have a requirement that the the output values be less than a given value MAX_VAL
I tried creating a matrix filled with MAX_VAL and then using tf.select and tf.greater :
filled = tf.fill(output.get_shape(),MAX_VAL)
modoutput = tf.select(tf.greater(output, filled), filled, output)
But this doesn't work because the shape of output is not known statically: It is [?, 30] and tf.fill requires an explicit shape.
Any idea how do i implement this?
Upvotes: 1
Views: 1779
Reputation: 126154
There is an alternative solution that uses tf.fill()
like your initial version. Instead of using Tensor.get_shape()
to get the static shape of output
, use the tf.shape()
operator to get the dynamic shape of output
when the step runs:
output = ...
filled = tf.fill(tf.shape(output), MAX_VAL)
modoutput = tf.select(tf.greater(output, filled), filled, output)
(Note also that the tf.clip_by_value()
operator might be useful for your purposes.)
Upvotes: 2
Reputation: 3233
I figured out a way to do it.
Instead of using tf.fill I used tf.ones_like
filled = MAX_VAL*tf.ones_like(output)
modoutput = tf.select(tf.greater(output, filled), filled, output)
Please mention if there is a faster or better way to do this is possible.
Upvotes: 0