diff --git a/docs/programming_guide/source_zh_cn/initializer.ipynb b/docs/programming_guide/source_zh_cn/initializer.ipynb index b70044f5ea4e749f7fc9fb088a84d0352181db0b..54ba60c4e84c5a1364044e9ee0248e7e12726682 100644 --- a/docs/programming_guide/source_zh_cn/initializer.ipynb +++ b/docs/programming_guide/source_zh_cn/initializer.ipynb @@ -1,37 +1,24 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# 网络参数的初始化\n", - "\n", - "[![](https://gitee.com/mindspore/docs/raw/master/resource/_static/logo_source.png)](https://gitee.com/mindspore/docs/blob/master/docs/programming_guide/source_zh_cn/initializer.ipynb) [![](https://gitee.com/mindspore/docs/raw/master/resource/_static/logo_notebook.png)](https://obs.dualstack.cn-north-4.myhuaweicloud.com/mindspore-website/notebook/master/programming_guide/mindspore_initializer.ipynb) [![](https://gitee.com/mindspore/docs/raw/master/resource/_static/logo_modelarts.png)](https://authoring-modelarts-cnnorth4.huaweicloud.com/console/lab?share-url-b64=aHR0cHM6Ly9vYnMuZHVhbHN0YWNrLmNuLW5vcnRoLTQubXlodWF3ZWljbG91ZC5jb20vbWluZHNwb3JlLXdlYnNpdGUvbm90ZWJvb2svbW9kZWxhcnRzL3Byb2dyYW1taW5nX2d1aWRlL21pbmRzcG9yZV9pbml0aWFsaXplci5pcHluYg==&imagename=MindSpore1.1.1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, +"metadata": {}, "source": [ - "## 概述\n", + "## outline\n", "\n", - "MindSpore提供了权重初始化模块,用户可以通过封装算子和initializer方法来调用字符串、Initializer子类或自定义Tensor等方式完成对网络参数进行初始化。Initializer类是MindSpore中用于进行初始化的基本数据结构,其子类包含了几种不同类型的数据分布(Zero,One,XavierUniform,HeUniform,HeNormal,Constant,Uniform,Normal,TruncatedNormal)。下面针对封装算子和initializer方法两种参数初始化模式进行详细介绍。" + "MindSpore provides a weight initialization module, and users can initialize network parameters by calling strings, Initializer subclass or custom Tensor through encapsulation operator and initializer method. The Initializer class is the basic data structure used for initialization in MindSpore, and its subclass contains several different types of data distribution ( Zero, One, XavierUniform, HeUniform, HeNormal, Constant, Uniform, Normal, TruncatedNormal ). The two parameter initialization modes of encapsulation operator and initializer method are introduced in detail below." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## 使用封装算子对参数初始化 \n", - "MindSpore提供了多种参数初始化的方式,并在部分算子中封装了参数初始化的功能。本节将介绍带有参数初始化功能的算子对参数进行初始化的方法,以`Conv2d`算子为例,分别介绍以字符串,`Initializer`子类和自定义`Tensor`等方式对网络中的参数进行初始化,以下代码示例中均以`Initializer`的子类`Normal`为例,代码示例中`Normal`均可替换成`Initializer`子类中任何一个。" + "## Initialize parameters using encapsulation operators\n", + "MindSpore provides a variety of parameter initialization methods, and encapsulates the function of parameter initialization in some operators. In this section, we will introduce the initialization method of parameters by operators with parameter initialization function. Taking ' Conv2d ' operator as an example, we will introduce the initialization of parameters in the network by string, ' Initializer ' subclass and custom ' Tensor ' respectively. The following code examples take the ' Normal ' subclass of ' Initializer ' as an example, and the ' Normal ' in the code example can be replaced by any one of the ' Initializer ' subclasses." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### 字符串 \n", - "使用字符串对网络参数进行初始化,字符串的内容需要与`Initializer`子类的名称保持一致,使用字符串方式进行初始化将使用`Initializer`子类中的默认参数,例如使用字符串`Normal`等同于使用`Initializer`的子类`Normal()`,代码样例如下:" + "### String \n", + "Using string to initialize the network parameters, the content of the string needs to be consistent with the name of the ' Initializer ' subclass. Using string to initialize the network parameters will use the default parameters in the ' Initializer ' subclass, such as using the string ' Normal ' is equivalent to using the ' Initializer ' subclass ' Normal ( ) ',The code sample is as follows :" ] }, { @@ -93,8 +80,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Initializer子类 \n", - "使用`Initializer`子类对网络参数进行初始化,与使用字符串对参数进行初始化的效果类似,不同的是使用字符串进行参数初始化是使用`Initializer`子类的默认参数,如要使用`Initializer`子类中的参数,就必须使用`Initializer`子类的方式对参数进行初始化,以`Normal(0.2)`为例,代码样例如下:" + "### Initializer subclass \n", + Initializing network parameters using the ' Initializer ' subclass is similar to initializing parameters using strings. The difference is that initializing parameters using strings is the default parameter using the ' Initializer ' subclass. If you want to use parameters in the ' Initializer ' subclass, you must initialize parameters using the ' Initializer ' subclass, taking ' Normal ( 0.2 ) ' as an example,The code sample is as follows :" ] }, { @@ -157,8 +144,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 自定义的Tensor \n", - "除上述两种初始化方法外,当网络要使用MindSpore中没有的数据类型对参数进行初始化,用户可以通过自定义`Tensor`的方式来对参数进行初始化,代码样例如下:" + "### self-defined Tensor \n", + "In addition to the above two initialization methods, when the network is to use the data types not in MindSpore to initialize the parameters, the user can initialize the parameters by custom ' Tensor ',Code like the following :" ] }, { @@ -207,33 +194,33 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## 使用initializer方法对参数初始化\n", + "## Initialize parameters using the initializer method\n", "\n", - "在上述代码样例中,给出了如何在网络中进行参数初始化的方法,如在网络中使用nn层封装`Conv2d`算子,参数`weight_init`作为要初始化的数据类型传入`Conv2d`算子,算子会在初始化时通过调用`Parameter`类,进而调用封装在`Parameter`类中的`initializer`方法来完成对参数的初始化。然而有一些算子并没有像`Conv2d`那样在内部对参数初始化的功能进行封装,如`Conv3d`算子的权重就是作为参数传入`Conv3d`算子,此时就需要手动的定义权重的初始化。\n", + "In the above code samples, the method of how to initialize the parameters in the network is given. For example, the nn layer is used to encapsulate the ‘ Conv2d ’ operator in the network, and the parameter ‘ weight _ init ’ is introduced into the ‘ Conv2d ’ operator as the data type to be initialized. The operator will initialize the parameters by calling the ‘ Parameter ’ class, and then calling the ‘ initializer ’ method encapsulated in the ‘ Parameter ’ class. However, some operators do not encapsulate the function of parameter initialization inside as ‘ Conv2d ’ does. For example, the weight of ‘ Conv3d ’ operator is introduced into the ‘ Conv3d ’ operator as a parameter, and the initialization of the weight needs to be manually defined.\n", "\n", - "当对参数进行初始化时,可以使用`initializer`方法调用`Initializer`子类中不同的数据类型来对参数进行初始化,进而产生不同类型的数据。\n", + "When initializing parameters, you can use the ' initializer ' method to invoke different data types in the ' initializer ' subclass to initialize parameters and then generate different types of data.\n", "\n", - "使用initializer进行参数初始化时,支持传入的参数有`init`、`shape`、`dtype`:\n", + "When initializing parameters with initializer, the incoming parameters are supported by ' init ', ' shape ', and ' dtype ' :\n", "\n", - "- `init`:支持传入`Tensor`、 `str`、 `Initializer的子类`。\n", + "- `init`:Support incoming`Tensor`、 `str`、 `Initializer's subclass`。\n", "\n", - "- `shape`:支持传入`list`、 `tuple`、 `int`。\n", + "- `shape`:Support incoming`list`、 `tuple`、 `int`。\n", "\n", - "- `dtype`:支持传入`mindspore.dtype`。" + "- `dtype`:Support incoming`mindspore.dtype`。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### init参数为Tensor" + "### init parameter is Tensor" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "代码样例如下:" + "Code like the following :" ] }, { @@ -268,7 +255,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "输出如下:\n", + "The output is as follows :\n", "\n", "```text\n", "[[[[[108 108 108 ... 108 108 108]\n", @@ -293,14 +280,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### init参数为str" + "### The init parameter is str" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "代码样例如下:" + "Code like the following :" ] }, { @@ -329,7 +316,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "输出如下:\n", + "The output is as follows :\n", "\n", "```text\n", "[[[[[0 0 0 ... 0 0 0]\n", @@ -354,14 +341,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### init参数为Initializer子类" + "###init parameter is Initializer subclass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "代码样例如下:" + "Code like the following :" ] }, { @@ -413,14 +400,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### 在Parameter中的应用" + "### Application in Parameter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "代码样例如下:" + "Code like the following :" ] }, { @@ -481,4 +468,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file