diff --git a/paddle/fluid/API.spec b/paddle/fluid/API.spec index 049b9ae2897c168d5ac2178a07aec130939a66a2..b5974eba2715ddd9161b2033d5247e3d64a06eb1 100644 --- a/paddle/fluid/API.spec +++ b/paddle/fluid/API.spec @@ -253,7 +253,7 @@ paddle.fluid.layers.elementwise_min (ArgSpec(args=['x', 'y', 'axis', 'act', 'nam paddle.fluid.layers.elementwise_pow (ArgSpec(args=['x', 'y', 'axis', 'act', 'name'], varargs=None, keywords=None, defaults=(-1, None, None)), ('document', '6fc5d7492830d60c7fa61b3bc8f0d7e7')) paddle.fluid.layers.elementwise_mod (ArgSpec(args=['x', 'y', 'axis', 'act', 'name'], varargs=None, keywords=None, defaults=(-1, None, None)), ('document', '4101ee1f9280f00dce54054ccc434890')) paddle.fluid.layers.elementwise_floordiv (ArgSpec(args=['x', 'y', 'axis', 'act', 'name'], varargs=None, keywords=None, defaults=(-1, None, None)), ('document', '67e6101c31314d4082621e8e443cfb68')) -paddle.fluid.layers.uniform_random_batch_size_like (ArgSpec(args=['input', 'shape', 'dtype', 'input_dim_idx', 'output_dim_idx', 'min', 'max', 'seed'], varargs=None, keywords=None, defaults=('float32', 0, 0, -1.0, 1.0, 0)), ('document', 'cfa120e583cd4a5bfa120c8a26f98a28')) +paddle.fluid.layers.uniform_random_batch_size_like (ArgSpec(args=['input', 'shape', 'dtype', 'input_dim_idx', 'output_dim_idx', 'min', 'max', 'seed'], varargs=None, keywords=None, defaults=('float32', 0, 0, -1.0, 1.0, 0)), ('document', '571c963b9b49f1a323d2ea2343f10dd2')) paddle.fluid.layers.gaussian_random (ArgSpec(args=['shape', 'mean', 'std', 'seed', 'dtype'], varargs=None, keywords=None, defaults=(0.0, 1.0, 0, 'float32')), ('document', 'dd4ddb66c78a2564e5d1e0e345d8286f')) paddle.fluid.layers.sampling_id (ArgSpec(args=['x', 'min', 'max', 'seed', 'dtype'], varargs=None, keywords=None, defaults=(0.0, 1.0, 0, 'float32')), ('document', '9ac9bdc45be94494d8543b8cec5c26e0')) paddle.fluid.layers.gaussian_random_batch_size_like (ArgSpec(args=['input', 'shape', 'input_dim_idx', 'output_dim_idx', 'mean', 'std', 'seed', 'dtype'], varargs=None, keywords=None, defaults=(0, 0, 0.0, 1.0, 0, 'float32')), ('document', '2aed0f546f220364fb1da724a3176f74')) @@ -307,7 +307,7 @@ paddle.fluid.layers.filter_by_instag (ArgSpec(args=['ins', 'ins_tag', 'filter_ta paddle.fluid.layers.shard_index (ArgSpec(args=['input', 'index_num', 'nshards', 'shard_id', 'ignore_value'], varargs=None, keywords=None, defaults=(-1,)), ('document', '3c6b30e9cd57b38d4a5fa1ade887f779')) paddle.fluid.layers.hard_swish (ArgSpec(args=['x', 'threshold', 'scale', 'offset', 'name'], varargs=None, keywords=None, defaults=(6.0, 6.0, 3.0, None)), ('document', 'bd763b9ca99239d624c3cb4626e3627a')) paddle.fluid.layers.mse_loss (ArgSpec(args=['input', 'label'], varargs=None, keywords=None, defaults=None), ('document', '88b967ef5132567396062d5d654b3064')) -paddle.fluid.layers.uniform_random (ArgSpec(args=['shape', 'dtype', 'min', 'max', 'seed'], varargs=None, keywords=None, defaults=('float32', -1.0, 1.0, 0)), ('document', '126ede8ce0e751244b1b54cd359c89d7')) +paddle.fluid.layers.uniform_random (ArgSpec(args=['shape', 'dtype', 'min', 'max', 'seed'], varargs=None, keywords=None, defaults=('float32', -1.0, 1.0, 0)), ('document', '34e7c1ff0263baf9551000b6bb3bc47e')) paddle.fluid.layers.data (ArgSpec(args=['name', 'shape', 'append_batch_size', 'dtype', 'lod_level', 'type', 'stop_gradient'], varargs=None, keywords=None, defaults=(True, 'float32', 0, VarType.LOD_TENSOR, True)), ('document', '9d7806e31bdf727c1a23b8782a09b545')) paddle.fluid.layers.read_file (ArgSpec(args=['reader'], varargs=None, keywords=None, defaults=None), ('document', 'd5b41c7b2df1b064fbd42dcf435268cd')) paddle.fluid.layers.double_buffer (ArgSpec(args=['reader', 'place', 'name'], varargs=None, keywords=None, defaults=(None, None)), ('document', '556fa82daf62cbb0fb393f4125daba77')) diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index bdbd4cf723bc207a2105ab4cb40e5ada6d71530b..40f0d717cb59b3718ac4430a1602ea207587e81c 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -12602,28 +12602,64 @@ def uniform_random_batch_size_like(input, max=1.0, seed=0): """ - ${comment} + This OP initializes a variable with random values sampled from a + uniform distribution in the range [min, max). The input_dim_idx used to get the input dimension value which will be used to resize the output dimension. + + .. code-block:: text + + *Case 1: + Given: + input =[[0.946741 , 0.1357001 , 0.38086128]] # input.shape=[1,3] + shape=[2,4] + + result.shape[output_dim_idx] = input.shape[input_dim_idx], + output_dim_idx = 0, + input_dim_idx = 0, + result.shape[0] = input.shape[0], + then: + result=[[ 0.3443427 , -0.23056602, 0.3477049 , 0.06139076]] # result.shape=[1,4] + + *Case 2: + + Given: + input =[[0.946741 , 0.1357001 , 0.38086128]] # input.shape=[1,3] + shape=[2,4] + input_dim_idx=1 + output_dim_idx=1 + + result.shape[output_dim_idx] = input.shape[input_dim_idx], + output_dim_idx = 1, + input_dim_idx = 1, + result.shape[1] = input.shape[1], + then: + result=[[-0.23133647, -0.84195036, 0.21441269], + [-0.08774924, 0.25605237, -0.09403259]] # result.shape=[2,3] Args: - input (Variable): ${input_comment} - shape (tuple|list): ${shape_comment} - input_dim_idx (Int): ${input_dim_idx_comment} - output_dim_idx (Int): ${output_dim_idx_comment} - min (Float): ${min_comment} - max (Float): ${max_comment} - seed (Int): ${seed_comment} - dtype(np.dtype|core.VarDesc.VarType|str): The type of data : float32, float_16, int etc + input (Variable): A Tensor. Supported data types: float32, float64. + shape (tuple|list): A python list or python tuple. The shape of the output Tensor, the data type is int. + input_dim_idx (int, optional): An index used to get the input dimension value which will be used to resize the output dimension. Default 0. + output_dim_idx (int, optional): An index used to indicate the specific dimension that will be replaced by corresponding input dimension value. Default 0. + min (float, optional): The lower bound on the range of random values to generate, the min is included in the range. Default -1.0. + max (float, optional): The upper bound on the range of random values to generate, the max is excluded in the range. Default 1.0. + seed (int, optional): Random seed used for generating samples. 0 means use a seed generated by the system.Note that if seed is not 0, this operator will always generate the same random numbers every time. + dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of output Tensor. Supported data types: float32, float64. Default float32. Returns: - out (Variable): ${out_comment} + Variable: A Tensor of the specified shape filled with uniform_random values. The shape of the Tensor is determined by the shape parameter and the specified dimension of the input Tensor. Examples: .. code-block:: python import paddle.fluid as fluid - import paddle.fluid.layers as layers + + # example 1: + input = fluid.data(name="input", shape=[1, 3], dtype='float32') + out_1 = fluid.layers.uniform_random_batch_size_like(input, [2, 4]) # out_1.shape=[1, 4] - input = layers.data(name="input", shape=[13, 11], dtype='float32') - out = layers.uniform_random_batch_size_like(input, [-1, 11]) + # example 2: + out_2 = fluid.layers.uniform_random_batch_size_like(input, [2, 4], input_dim_idx=1, output_dim_idx=1) # out_2.shape=[2, 3] + + """ helper = LayerHelper('uniform_random_batch_size_like', **locals()) @@ -16982,8 +17018,8 @@ def mse_loss(input, label): @templatedoc() def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): """ - This operator initializes a variable with random values sampled from a - uniform distribution. The random result is in set [min, max). + This OP initializes a variable with random values sampled from a + uniform distribution in the range [min, max). Examples: :: @@ -16995,24 +17031,23 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): result=[[0.8505902, 0.8397286]] Args: - shape (list|tuple|Variable): The shape of the output tensor, the data type of the integer is int, - and if the shape type is list or tuple, its elements can be an integer - or a tensor with the shape [1], the data type of the tensor is int64. - If the shape type is Variable,it ia a 1D tensor, the data type of the tensor is int64. - dtype(np.dtype|core.VarDesc.VarType|str, optional): The data type of the output tensor, such as float32, float64. + shape (list|tuple|Variable): The shape of the output Tensor, if the shape is a list or tuple, + its elements can be an integer + or a Tensor with the shape [1], and the type of the Tensor is int64. + If the shape is a Variable, it is a 1-D Tensor, and the type of the Tensor is int64. + dtype(np.dtype|core.VarDesc.VarType|str, optional): The type of the output Tensor. Supported data types: float32, float64. Default: float32. - min (float, optional): Minimum value of uniform random, It's a closed interval. Default -1.0. - max (float, optional): Maximun value of uniform random, It's an open interval. Default 1.0. + min (float, optional): The lower bound on the range of random values to generate, the min is included in the range. Default -1.0. + max (float, optional): The upper bound on the range of random values to generate, the max is excluded in the range. Default 1.0. seed (int, optional): Random seed used for generating samples. 0 means use a seed generated by the system. Note that if seed is not 0, this operator will always generate the same random numbers every time. Default 0. - Returns: a Tensor with randomly initialized results whose data type is determined by the dtype parameter - and whose dimension is determined by the shape parameter. - Return type: Variable + Returns: + Variable: A Tensor of the specified shape filled with uniform_random values. - Throw exception: + Raises: TypeError: The shape type should be list or tupple or variable. Examples: @@ -17031,7 +17066,7 @@ def uniform_random(shape, dtype='float32', min=-1.0, max=1.0, seed=0): # example 3: # attr shape is a Variable, the data type must be int64 - var_shape = fluid.layers.data(name='var_shape',shape=[2],append_batch_size=False) + var_shape = fluid.data(name='var_shape', shape=[2], dtype="int64") result_3 = fluid.layers.uniform_random(var_shape) """