diff --git a/docs/programming_guide/source_en/initializer.md b/docs/programming_guide/source_en/initializer.md index 9d6a454772287f5ea8c376b7427c3a286857b704..c00bd47be1824e390b47b4baf0c6a9521fbc72e1 100644 --- a/docs/programming_guide/source_en/initializer.md +++ b/docs/programming_guide/source_en/initializer.md @@ -1,36 +1,16 @@ # Initialization of Network Parameters -Translator: [Karlos Ma](https://gitee.com/Mavendetta985) - - - -- [Initialization of Network Parameters](#initialization-of-network-parameters) - - [Overview](#overview) - - [Using Encapsulation Operator to Initialize Parameters](#using-encapsulation-operator-to-initialize-parameters) - - [Character String](#character-string) - - [Initializer Subclass](#initializer-subclass) - - [The Custom of the Tensor](#the-custom-of-the-tensor) - - [Using the Initializer Method to Initialize Parameters](#using-the-initializer-method-to-initialize-parameters) - - [The Parameter of Init is Tensor](#the-parameter-of-init-is-tensor) - - [The Parameter of Init is Str](#the-parameter-of-init-is-str) - - [The Parameter of Init is the Subclass of Initializer](#the-parameter-of-init-is-the-subclass-of-initializer) - - [Application in Parameter](#application-in-parameter) - - - - - ## Overview -MindSpore provides a weight initialization module, which allows users to initialize network parameters by encapsulated operators and initializer methods to call strings, initializer subclasses, or custom Tensors. The Initializer class is the basic data structure used for initialization in MindSpore. Its subclasses contain several different types of data distribution (Zero, One, XavierUniform, Heuniform, Henormal, Constant, Uniform, Normal, TruncatedNormal). The following two parameter initialization modes, encapsulation operator and initializer method, are introduced in detail. +MindSpore provides a weight initialization module that allows users to initialize network parameters by wrapping operators and initializer methods to call strings, Initializer subclasses or custom Tensor. Class Initializer is the basic data structure in MindSpore to initialize network parameters,its subclasses contain several different types of data distributions (Zero, One, XavierUniform, HeUniform, HeNormal, Constant, Uniform, Normal, TruncatedNormal). The following is a detailed description of the two parameter initialization modes, the wrapper operator and the initializer method. -## Using Encapsulation Operator to Initialize Parameters +## Parameter initialization using wrapper operator -Mindspore provides a variety of methods of initializing parameters, and encapsulates parameter initialization functions in some operators. This section will introduce the method of initialization of parameters by operators with parameter initialization function. Taking `Conv2D` operator as an example, it will introduce the initialization of parameters in the network by strings, `Initializer` subclass and custom `Tensor`, etc. `Normal`, a subclass of `Initializer`, is used in the following code examples and can be replaced with any of the subclasses of Initializer in the code examples. +MindSpore provides various ways to initialize parameters and encapsulates parameter initialization in some operators. In this section, we will introduce the methods of initializing parameters in operators with parameter initialization function, taking the Conv2d operator as an example, and introduce the initialization of parameters in the network by strings, Initializer subclasses and custom Tensor, etc. The following code examples take Normal, a subclass of Initializer, as an example. Normal can be replaced by any of the Initializer subclasses. -### Character String +### String -Network parameters are initialized using a string. The contents of the string need to be consistent with the name of the `Initializer` subclass. Initialization using a string will use the default parameters in the `Initializer` subclass. For example, using the string `Normal` is equivalent to using the `Initializer` subclass `Normal()`. The code sample is as follows: +Using a string to initialize the network parameters, the content of the string needs to be consistent with the name of the subclass of Initializer, using the string approach to initialization will use the default parameters in the Initializer subclass, for example, using the string Normal is equivalent to using the Initializer subclass Normal (), code examples are as follows: ```python import numpy as np @@ -78,9 +58,9 @@ print(output) 6.74417242e-05 -2.27325838e-02]]]] ``` -### Initializer Subclass +### Initializer subclass -`Initializer` subclass is used to initialize network parameters, which is similar to the effect of using string to initialize parameters. The difference is that using string to initialize parameters uses the default parameter of the `Initializer` subclass. If you want to use the parameters in the `Initializer` subclass, the `Initializer` subclass must be used to initialize the parameters. Taking `Normal(0.2)` as an example, the code sample is as follows: +Using the Initializer subclass to initialize the network parameters is similar to using a string to initialize the parameters, the difference is that using a string to initialize the parameters is using the default parameters of the Initializer subclass, such as to use the parameters in the Initializer subclass, you must use the Initializer subclass way to initialize the parameters To initialize, take Normal(0.2) as an example, the code sample is as follows: ```python import numpy as np @@ -129,9 +109,9 @@ print(output) 1.3488382e-03 -4.5465171e-01]]]] ``` -### The Custom of the Tensor +### Customized Tensor -In addition to the above two initialization methods, when the network wants to use data types that are not available in MindSpore, users can customize `Tensor` to initialize the parameters. The code sample is as follows: +In addition to the above two initialization methods, when the network wants to initialize the parameters with data types not available in MindSpore, the user can initialize the parameters by means of a custom Tensor, as shown in the following code example. ```python import numpy as np @@ -180,6 +160,7 @@ When initializer is used for parameter initialization, the parameters passed in ### The Parameter of Init is Tensor The code sample is shown below: +>>>>>>> master ```python import numpy as np @@ -199,25 +180,6 @@ output = conv3d(input_data, weight) print(output) ``` -```text -The output is as follows: -[[[[[108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108] - ... - [108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108]] - ... - [[108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108] - ... - [108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108] - [108 108 108 ... 108 108 108]]]]] -``` - ### The Parameter of Init is Str The code sample is as follows: