提交 c5ad7185 编写于 作者: Y Youwei Song 提交者: Jiabin Yang

add set_value cn doc, test=develop (#1470)

上级 7f211856
......@@ -68,7 +68,7 @@ Program是Paddle Fluid对于计算图的一种静态描述,使用Program的构
.. py:method:: clone(for_test=False)
**注意:**
**1.** ``Program.clone()`` **方法不会克隆例如** :ref:`cn_api_fluid_io_PyReader` **这样的数据读取相关的部分,这可能会造成的数据读取部分在克隆后丢失**
**1.** ``Program.clone()`` **方法不会克隆例如** :ref:`cn_api_fluid_io_DataLoader` **这样的数据读取相关的部分,这可能会造成的数据读取部分在克隆后丢失**
**2. 此API当** ``for_test=True`` **时将会裁剪部分OP和变量。为防止错误的裁剪,推荐在** :ref:`cn_api_fluid_backward_append_backward` **和执行优化器之前使用** ``clone(for_test=True)`` 。
......
......@@ -99,6 +99,37 @@ Variable
x = fc(data)
print(x.numpy())
.. py:method:: set_value()
**注意:该API只在** `Dygraph <../../user_guides/howto/dygraph/DyGraph.html>`_ **模式下生效**
为此 :ref:`api_guide_Variable` 设置一个新的值。
**参数:**
- **value**: ( :ref:`api_guide_Variable` 或 ``ndarray`` ) 要赋值给此 :ref:`api_guide_Variable` 的新的值。
返回:无
抛出异常: ``ValueError`` - 当要赋于的新值的 ``shape`` 和此 :ref:`api_guide_Variable` 原有的 ``shape`` 不同时,抛出 ``ValueError`` 。
**示例代码**
.. code-block:: python
import paddle.fluid as fluid
from paddle.fluid.dygraph.base import to_variable
from paddle.fluid.dygraph import FC
import numpy as np
data = np.ones([3, 32, 32], dtype='float32')
with fluid.dygraph.guard():
fc = fluid.dygraph.FC("fc", 4)
t = to_variable(data)
fc(t) # 使用默认参数值调用前向
custom_weight = np.random.randn(1024, 4).astype("float32")
fc.weight.set_value(custom_weight) # 将参数修改为自定义的值
out = fc(t) # 使用新的参数值调用前向
.. py:method:: backward()
**注意:**
......@@ -290,11 +321,7 @@ Variable
.. py:attribute:: name
**注意:**
**1. 在非** `Dygraph <../../user_guides/howto/dygraph/DyGraph.html>`_ **模式下,那么同一个** :ref:`api_guide_Block` **中的两个或更多** :ref:`api_guide_Variable` **拥有相同** ``name`` **将意味着他们会共享相同的内容。通常我们使用这种方式来实现参数共享**
**2. 该属性在** `Dygraph <../../user_guides/howto/dygraph/DyGraph.html>`_ **模式下一经初始化即不能修改,这是由于在动态执行时,** :ref:`api_guide_Variable` **的生命周期将由** ``Python`` **自行控制不再需要通过该属性来修改**
**注意:在非** `Dygraph <../../user_guides/howto/dygraph/DyGraph.html>`_ **模式下,那么同一个** :ref:`api_guide_Block` **中的两个或更多** :ref:`api_guide_Variable` **拥有相同** ``name`` **将意味着他们会共享相同的内容。通常我们使用这种方式来实现参数共享**
此 :ref:`api_guide_Variable` 的名字(str)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册