vector_to_parameters¶
- paddle.nn.utils. vector_to_parameters ( vec, parameters, name=None ) [source]
-
Transform a 1-D Tensor to the input
parameters
.- Parameters
-
vec (Tensor) – A 1-D Tensor, which will be sliced and copied to the input
parameters
.parameters (Iterable[Tensor]) – Iterable Tensors that are trainable parameters of a Layer.
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.
Examples
>>> import paddle >>> weight_attr = paddle.ParamAttr(initializer=paddle.nn.initializer.Constant(3.)) >>> linear1 = paddle.nn.Linear(10, 15, weight_attr) >>> vec = paddle.nn.utils.parameters_to_vector(linear1.parameters()) >>> linear2 = paddle.nn.Linear(10, 15) >>> # copy weight of linear1 to linear2 >>> paddle.nn.utils.vector_to_parameters(vec, linear2.parameters()) >>> print((linear1.weight == linear2.weight).all()) Tensor(shape=[], dtype=bool, place=Place(cpu), stop_gradient=True, True)