Exemplo n.º 1
0
def uniform(name, shape, scale=0.05, dtype=tf.sg_floatx, summary=True, regularizer=None, trainable=True):
    r"""Creates a tensor variable of which initial values are 
    random numbers based on uniform distribution.
    
    Note that the default value of `scale` (=0.05) is different from 
    the min/max values (=0.0, 1.0) of tf.random_uniform_initializer.
    
    Args:
      name: The name of the new variable.
      shape: A tuple/list of integers or an integer. 
        If shape is an integer, it's converted to a list.
      scale: A Python scalar. All initial values should be in range `[-scale, scale)`. Default is .05.
      dtype: The data type. Only floating point types are supported. Default is float32.
      summary: If True, add this constant to tensor board summary.
      regularizer:  A (Tensor -> Tensor or None) function; the result of applying it on a newly created variable
        will be added to the collection tf.GraphKeys.REGULARIZATION_LOSSES and can be used for regularization
      trainable: If True, add this constant to trainable collection. Default is True.

    Returns:
      A `Variable`.
    """
    shape = shape if isinstance(shape, (tuple, list)) else [shape]
    x = tf.get_variable(name, shape, dtype=dtype,
                        initializer=tf.random_uniform_initializer(minval=-scale, maxval=scale),
                        regularizer=regularizer, trainable=trainable)
    # add summary
    if summary:
        tf.sg_summary_param(x)
    return x
Exemplo n.º 2
0
def uniform(name, shape, scale=0.05, dtype=tf.sg_floatx, summary=True):
    r"""Creates a tensor variable of which initial values are 
    random numbers based on uniform distribution.
    
    Note that the default value of `scale` (=0.05) is different from 
    the min/max values (=0.0, 1.0) of tf.random_uniform_initializer.
    
    Args:
      name: The name of the new variable.
      shape: A tuple/list of integers or an integer. 
        If shape is an integer, it's converted to a list.
      scale: A Python scalar. All initial values should be in range `[-scale, scale)`. Default is .05.
      dtype: The data type. Only floating point types are supported. Default is float32.
      summary: If True, add this constant to tensor board summary.
    
    Returns:
      A `Variable`.
    """
    shape = shape if isinstance(shape, (tuple, list)) else [shape]
    x = tf.get_variable(name,
                        shape,
                        dtype=dtype,
                        initializer=tf.random_uniform_initializer(
                            minval=-scale, maxval=scale))
    # add summary
    if not tf.get_variable_scope().reuse and summary:
        tf.sg_summary_param(x)
    return x
Exemplo n.º 3
0
def uniform(name, shape, scale=0.05, dtype=tf.sg_floatx):
    shape = shape if isinstance(shape, (tuple, list)) else [shape]
    x = tf.get_variable(name, shape, dtype=dtype,
                        initializer=tf.random_uniform_initializer(minval=-scale, maxval=scale))
    # add summary
    if not tf.get_variable_scope().reuse:
        tf.sg_summary_param(x)
    return x
Exemplo n.º 4
0
def uniform(name, shape, scale=0.05, dtype=tf.sg_floatx):
    r"""Returns an initializer of random numbers based on uniform distribution.
    Note that the default value of `scale` (=0.05) is different from 
    the min/max values (=0.0, 1.0) of tf.random_uniform_initializer.
    """
    shape = shape if isinstance(shape, (tuple, list)) else [shape]
    x = tf.get_variable(name,
                        shape,
                        dtype=dtype,
                        initializer=tf.random_uniform_initializer(
                            minval=-scale, maxval=scale))
    # add summary
    if not tf.get_variable_scope().reuse:
        tf.sg_summary_param(x)
    return x