python 3.x - Tensorflow clamp values outside specific range -
i have been using tensorflow implement convolutional neural network, have requirement the output values less given value max_val
i tried creating matrix filled max_val , using tf.select , tf.greater :
filled = tf.fill(output.get_shape(),max_val) modoutput = tf.select(tf.greater(output, filled), filled, output) but doesn't work because shape of output not known statically: [?, 30] , tf.fill requires explicit shape.
any idea how implement this?
there alternative solution uses tf.fill() initial version. instead of using tensor.get_shape() static shape of output, use tf.shape() operator dynamic shape of output when step runs:
output = ... filled = tf.fill(tf.shape(output), max_val) modoutput = tf.select(tf.greater(output, filled), filled, output) (note tf.clip_by_value() operator might useful purposes.)
Comments
Post a Comment