class paddle.fluid.layer_helper_base. LayerHelperBase ( name, layer_type ) [source]
to_variable ( value, name=None )

The API will create a Variable object from numpy.ndarray or Variable object.

  • value (ndarray) – The numpy.ndarray object that needs to be converted, it can be multi-dimension, and the data type is one of numpy.{float16, float32, float64, int16, int32, int64, uint8, uint16}.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name


Tensor created from the specified numpy.ndarray object, data type and shape is the same as value .

Return type



import numpy as np
import paddle.fluid as fluid

with fluid.dygraph.guard():
    x = np.ones([2, 2], np.float32)
    y = fluid.dygraph.to_variable(x)
create_parameter ( attr, shape, dtype=None, is_bias=False, default_initializer=None, stop_gradient=False, type=VarType.LOD_TENSOR )

Create parameters for this layers.


attr: [ParamAttr] should be the parameter attribute for this parameter shape: shape of the parameter dtype: data type of this parameter is_bias: if this is a bias parameter default_initializer: set the default initializer for this parameter

Returns created parameter Variable.

create_variable_for_type_inference ( dtype, stop_gradient=False )

Create a temporary variable that should be type inferred layer.


The default type will be set to LOD_TENSOR. However, when the var is used as operator output, its type will be updated based on operator’s VarTypeInference implementation in infer_var_type.

create_variable ( *args, **kwargs )

Create Variable for this layers. Returns created Variable.

create_global_variable ( persistable=False, *args, **kwargs )

create global variable, note that there is no initializer for this global variable. :param persistable: True if it is a checkpoint value. :type persistable: bool :param *args: See create_var’s documentation :param **kwargs: See create_var’s documentation

Returns(Variable): the created variable.

create_or_get_global_variable ( name, *args, **kwargs )

Creates a global variable if not exists and returns the variable and a boolean flag which is true when it is a new variable.

set_variable_initializer ( var, initializer )

Set target Variable’s initializer

  • var – target Variable

  • initializer – initializer to use