未验证 提交 cfc69f3e 编写于 作者: B Bai Yifan 提交者: GitHub

Fix distillation doc (#161)

上级 0ae32c6e
......@@ -4,7 +4,7 @@
merge
---------
.. py:function:: paddleslim.dist.merge(teacher_program, student_program, data_name_map, place, scope=fluid.global_scope(), name_prefix='teacher_')
.. py:function:: paddleslim.dist.merge(teacher_program, student_program, data_name_map, place, scope=None, name_prefix='teacher_')
`源代码 <https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L19>`_
......@@ -16,8 +16,8 @@ merge将teacher_program融合到student_program中。在融合的program中,
- **student_program** (Program)-定义了student模型的 `paddle program <https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/fluid_cn/Program_cn.html#program>`_
- **data_name_map** (dict)-teacher输入接口名与student输入接口名的映射,其中dict的 *key* 为teacher的输入名,*value* 为student的输入名
- **place** (fluid.CPUPlace()|fluid.CUDAPlace(N))-该参数表示程序运行在何种设备上,这里的N为GPU对应的ID
- **scope** (Scope)-该参数表示程序使用的变量作用域,如果不指定将使用默认的全局作用域。默认值: `fluid.global_scope() <https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/fluid_cn/global_scope_cn.html#global-scope>`_
- **name_prefix** (str)-merge操作将统一为teacher的 `Variables <https://www.paddlepaddle.org.cn/documentation/docs/zh/1.3/api_guides/low_level/program.html#variable>`_ 添加的名称前缀name_prefix。默认值:'teacher_'
- **scope** (Scope)-该参数表示程序使用的变量作用域,如果不指定将使用默认的全局作用域。默认值: None
- **name_prefix** (str)-merge操作将统一为teacher的 `Variables <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/beginners_guide/basic_concept/variable.html#variable>`_ 添加的名称前缀name_prefix。默认值:'teacher_'
**返回:** 无
......@@ -53,7 +53,7 @@ merge将teacher_program融合到student_program中。在融合的program中,
fsp_loss
---------
.. py:function:: paddleslim.dist.fsp_loss(teacher_var1_name, teacher_var2_name, student_var1_name, student_var2_name, program=fluid.default_main_program())
.. py:function:: paddleslim.dist.fsp_loss(teacher_var1_name, teacher_var2_name, student_var1_name, student_var2_name, program=None)
`源代码 <https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L90>`_
......@@ -65,13 +65,14 @@ fsp_loss为program内的teacher var和student var添加fsp loss,出自论文 `
- **teacher_var2_name** (str): teacher_var2的名称. 对应的variable是一个形为`[batch_size, y_channel, height, width]`的4-D特征图Tensor,数据类型为float32或float64。只有y_channel可以与teacher_var1的x_channel不同,其他维度必须与teacher_var1相同
- **student_var1_name** (str): student_var1的名称. 对应的variable需与teacher_var1尺寸保持一致,是一个形为`[batch_size, x_channel, height, width]`的4-D特征图Tensor,数据类型为float32或float64
- **student_var2_name** (str): student_var2的名称. 对应的variable需与teacher_var2尺寸保持一致,是一个形为`[batch_size, y_channel, height, width]`的4-D特征图Tensor,数据类型为float32或float64。只有y_channel可以与student_var1的x_channel不同,其他维度必须与student_var1相同
- **program** (Program): 用于蒸馏训练的fluid program。默认值: `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/1.3/api_cn/fluid_cn.html#default-main-program>`_
- **program** (Program): 用于蒸馏训练的fluid program, 如果未指定则使用 `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/fluid_cn/default_main_program_cn.html#default-main-program>`_ 。默认值:None
**返回:** 由teacher_var1, teacher_var2, student_var1, student_var2组合得到的fsp_loss
**使用示例:**
.. code-block:: python
import paddle.fluid as fluid
import paddleslim.dist as dist
student_program = fluid.Program()
......@@ -98,21 +99,24 @@ fsp_loss为program内的teacher var和student var添加fsp loss,出自论文 `
l2_loss
------------
.. py:function:: paddleslim.dist.l2_loss(teacher_var_name, student_var_name, program=fluid.default_main_program())[[源代码]](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L118)
.. py:function:: paddleslim.dist.l2_loss(teacher_var_name, student_var_name, program=None)
`源代码 <https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L118>`_
: l2_loss为program内的teacher var和student var添加l2 loss
l2_loss为program内的teacher var和student var添加l2 loss
**参数:**
- **teacher_var_name** (str): teacher_var的名称.
- **student_var_name** (str): student_var的名称.
- **program** (Program): 用于蒸馏训练的fluid program。默认值: `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/1.3/api_cn/fluid_cn.html#default-main-program>`_
- **program** (Program): 用于蒸馏训练的fluid program。如果未指定则使用 `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/fluid_cn/default_main_program_cn.html#default-main-program>`_ 。默认值:None
**返回:** 由teacher_var, student_var组合得到的l2_loss
**使用示例:**
.. code-block:: python
import paddle.fluid as fluid
import paddleslim.dist as dist
student_program = fluid.Program()
......@@ -139,7 +143,9 @@ l2_loss
soft_label_loss
-------------------
.. py:function:: paddleslim.dist.soft_label_loss(teacher_var_name, student_var_name, program=fluid.default_main_program(), teacher_temperature=1., student_temperature=1.)[[源代码]](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L136)
.. py:function:: paddleslim.dist.soft_label_loss(teacher_var_name, student_var_name, program=None, teacher_temperature=1., student_temperature=1.)
`源代码 <https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L136>`_
soft_label_loss为program内的teacher var和student var添加soft label loss,出自论文 `Distilling the Knowledge in a Neural Network <https://arxiv.org/pdf/1503.02531.pdf>`_
......@@ -147,7 +153,7 @@ soft_label_loss为program内的teacher var和student var添加soft label loss,
- **teacher_var_name** (str): teacher_var的名称.
- **student_var_name** (str): student_var的名称.
- **program** (Program): 用于蒸馏训练的fluid program。默认值: `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/1.3/api_cn/fluid_cn.html#default-main-program>`_
- **program** (Program): 用于蒸馏训练的fluid program。如果未指定则使用 `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/fluid_cn/default_main_program_cn.html#default-main-program>`_ 。默认值:None
- **teacher_temperature** (float): 对teacher_var进行soft操作的温度值,温度值越大得到的特征图越平滑
- **student_temperature** (float): 对student_var进行soft操作的温度值,温度值越大得到的特征图越平滑
......@@ -182,14 +188,16 @@ soft_label_loss为program内的teacher var和student var添加soft label loss,
loss
--------
.. py:function:: paddleslim.dist.loss(loss_func, program=fluid.default_main_program(), **kwargs) [[源代码]](https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L165)
.. py:function:: paddleslim.dist.loss(loss_func, program=None, **kwargs)
`源代码 <https://github.com/PaddlePaddle/PaddleSlim/blob/develop/paddleslim/dist/single_distiller.py#L165>`_
: loss函数支持对任意多对teacher_var和student_var使用自定义损失函数
loss函数支持对任意多对teacher_var和student_var使用自定义损失函数
**参数:**
- **loss_func**( python function): 自定义的损失函数,输入为teacher var和student var,输出为自定义的loss
- **program** (Program): 用于蒸馏训练的fluid program。默认值: `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/1.3/api_cn/fluid_cn.html#default-main-program>`_
- **program** (Program): 用于蒸馏训练的fluid program。如果未指定则使用 `fluid.default_main_program() <https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api_cn/fluid_cn/default_main_program_cn.html#default-main-program>`_ 。默认值:None
- **\**kwargs** : loss_func输入名与对应variable名称
**返回** :自定义的损失函数loss
......@@ -197,6 +205,7 @@ loss
**使用示例:**
.. code-block:: python
import paddle.fluid as fluid
import paddleslim.dist as dist
student_program = fluid.Program()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册