LayerHelperBase¶
- class paddle.fluid.layer_helper_base. LayerHelperBase ( name, layer_type ) [source]
-
-
to_variable
(
value,
name=None
)
to_variable¶
-
The API will create a
Variable
object from numpy.ndarray or Variable object.- Parameters
-
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
- Returns
-
Tensor
created from the specified numpy.ndarray object, data type and shape is the same asvalue
. - Return type
-
Variable
Examples
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_parameter¶
-
Create parameters for this layers.
- Args:
-
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,
shape=None
)
create_variable_for_type_inference¶
-
Create a temporary variable that should be type inferred layer.
Note
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¶
-
Create Variable for this layers. Returns created Variable.
-
create_global_variable
(
persistable=False,
*args,
**kwargs
)
create_global_variable¶
-
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
)
create_or_get_global_variable¶
-
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_variable_initializer¶
-
Set target Variable’s initializer
- Parameters
-
var – target Variable
initializer – initializer to use
-
to_variable
(
value,
name=None
)