def SoftThreshold(t, threshold_ratio, name=None):
 assert (threshold_ratio >= 0)
 with tf.op_scope([t, threshold_ratio], name, 'soft_thresholding') as name:
  saved_shape = tf.shape(t)
  t2 = tf.reshape(t, tf.concat(0, [tf.slice(saved_shape, [0], [1]), (-1)]))
  t_abs = tf.abs(t2)
  t_x = (tf.sign(t2) * tf.nn.relu((t_abs - (tf.reduce_mean(t_abs, [0], keep_dims=True) * threshold_ratio))))
  return tf.reshape(t_x, saved_shape, name=name)

def SoftThreshold ( t , threshold_ratio , name = None ) : assert ( threshold_ratio >= 0 ) with tf . op_scope ( [ t , threshold_ratio ] , name , 'soft_thresholding' ) as name : saved_shape = tf . shape ( t ) t2 = tf . reshape ( t , tf . concat ( 0 , [ tf . slice ( saved_shape , [ 0 ] , [ 1 ] ) , ( - 1 ) ] ) ) t_abs = tf . abs ( t2 ) t_x = ( tf . sign ( t2 ) * tf . nn . relu ( ( t_abs - ( tf . reduce_mean ( t_abs , [ 0 ] , keep_dims = True ) * threshold_ratio ) ) ) ) return tf . reshape ( t_x , saved_shape , name = name )
soft-threshold a tensor by the mean value .