(size, sigma)
return tf.reshape(g, shape=[size, size, 1, 1])
Function to mimic the 'fspecial' gaussian MATLAB function.
Function to mimic the 'fspecial' gaussian MATLAB function.
Function to mimic the fspecial gaussian MATLAB function .
def f_special_gauss(size, sigma):
  """Function to mimic the 'fspecial' gaussian MATLAB function."""
  size = tf.convert_to_tensor(size, tf.int32)
  sigma = tf.convert_to_tensor(sigma)

  coords = tf.cast(tf.range(size), sigma.dtype)
  coords -= tf.cast(size - 1, sigma.dtype) / 2.0

  g = tf.square(coords)
  g *= -0.5 / tf.square(sigma)

  g = tf.reshape(g, shape=[1, -1]) + tf.reshape(g, shape=[-1, 1])
  g = tf.reshape(g, shape=[1, -1])  # For tf.nn.softmax().
  g = tf.nn.softmax(g)
  return tf.reshape(g, shape=[size, size, 1, 1])
def f_special_gauss ( size , sigma ) : size = tf . convert_to_tensor ( size , tf . int32 ) sigma = tf . convert_to_tensor ( sigma ) coords = tf . cast ( tf . range ( size ) , sigma . dtype ) coords -= tf . cast ( size - 1 , sigma . dtype ) / 2.0 g = tf . square ( coords ) g *= - 0.5 / tf . square ( sigma ) g = tf . reshape ( g , shape = [ 1 , - 1 ] ) + tf . reshape ( g , shape = [ - 1 , 1 ] ) g = tf . reshape ( g , shape = [ 1 , - 1 ] ) # For tf.nn.softmax(). g = tf . nn . softmax ( g ) return tf . reshape ( g , shape = [ size , size , 1 , 1 ] )