|
|
@ -1297,9 +1297,12 @@ class Variable(object):
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
import paddle
|
|
|
|
|
|
|
|
import paddle.static as static
|
|
|
|
|
|
|
|
|
|
|
|
cur_program = fluid.Program()
|
|
|
|
paddle.enable_static()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cur_program = static.Program()
|
|
|
|
cur_block = cur_program.current_block()
|
|
|
|
cur_block = cur_program.current_block()
|
|
|
|
new_variable = cur_block.create_var(name="X",
|
|
|
|
new_variable = cur_block.create_var(name="X",
|
|
|
|
shape=[-1, 23, 48],
|
|
|
|
shape=[-1, 23, 48],
|
|
|
@ -1307,10 +1310,10 @@ class Variable(object):
|
|
|
|
print(new_variable._to_readable_code())
|
|
|
|
print(new_variable._to_readable_code())
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if self.type == core.VarDesc.VarType.SELECTED_ROWS or self.type == core.VarDesc.VarType.LOD_TENSOR:
|
|
|
|
if self.type == core.VarDesc.VarType.SELECTED_ROWS or self.type == core.VarDesc.VarType.LOD_TENSOR:
|
|
|
|
var_str = "{name} : fluid.{type}.shape{shape}.astype({dtype})".\
|
|
|
|
var_str = "{name} : paddle.{type}.shape{shape}.astype({dtype})".\
|
|
|
|
format(i="{", e="}", name=self.name, type=self.type, shape=self.shape, dtype=self.dtype)
|
|
|
|
format(i="{", e="}", name=self.name, type=self.type, shape=self.shape, dtype=self.dtype)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
var_str = "{name} : fluid.{type})".\
|
|
|
|
var_str = "{name} : paddle.{type})".\
|
|
|
|
format(i="{", e="}", name=self.name, type=self.type)
|
|
|
|
format(i="{", e="}", name=self.name, type=self.type)
|
|
|
|
|
|
|
|
|
|
|
|
if type(self) == Parameter:
|
|
|
|
if type(self) == Parameter:
|
|
|
@ -4270,9 +4273,12 @@ class Program(object):
|
|
|
|
Examples:
|
|
|
|
Examples:
|
|
|
|
.. code-block:: python
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
|
|
|
|
import paddle.fluid as fluid
|
|
|
|
import paddle
|
|
|
|
|
|
|
|
import paddle.static as static
|
|
|
|
|
|
|
|
|
|
|
|
cur_program = fluid.Program()
|
|
|
|
paddle.enable_static()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cur_program = static.Program()
|
|
|
|
cur_block = cur_program.current_block()
|
|
|
|
cur_block = cur_program.current_block()
|
|
|
|
new_var = cur_block.create_var(name="X",
|
|
|
|
new_var = cur_block.create_var(name="X",
|
|
|
|
shape=[-1, 23, 48],
|
|
|
|
shape=[-1, 23, 48],
|
|
|
@ -4470,7 +4476,7 @@ class Program(object):
|
|
|
|
# Due to parameter sharing usage for train and test, so we need to use startup program of train
|
|
|
|
# Due to parameter sharing usage for train and test, so we need to use startup program of train
|
|
|
|
# instead of using test startup program, while nothing is in test's startup program
|
|
|
|
# instead of using test startup program, while nothing is in test's startup program
|
|
|
|
|
|
|
|
|
|
|
|
# In Paddle Fluid we will share weights by using the same Variable name. In train and test program
|
|
|
|
# In Paddle we will share weights by using the same Tensor name. In train and test program
|
|
|
|
# all parameters will have the same name and this can make train and test program sharing parameters,
|
|
|
|
# all parameters will have the same name and this can make train and test program sharing parameters,
|
|
|
|
# that's why we need to use startup program of train. And for startup program of test, it has nothing,
|
|
|
|
# that's why we need to use startup program of train. And for startup program of test, it has nothing,
|
|
|
|
# since it is a new program.
|
|
|
|
# since it is a new program.
|
|
|
@ -4823,7 +4829,7 @@ class Program(object):
|
|
|
|
## 0
|
|
|
|
## 0
|
|
|
|
## the default random seed is 0
|
|
|
|
## the default random seed is 0
|
|
|
|
|
|
|
|
|
|
|
|
# Here we need to set random seed before we use fluid.layers.dropout
|
|
|
|
# Here we need to set random seed before we use paddle.nn.functional.dropout
|
|
|
|
prog.random_seed = 1
|
|
|
|
prog.random_seed = 1
|
|
|
|
z_var = F.dropout(x_var, 0.7)
|
|
|
|
z_var = F.dropout(x_var, 0.7)
|
|
|
|
|
|
|
|
|
|
|
@ -5098,8 +5104,8 @@ class Program(object):
|
|
|
|
for var in prog.list_vars():
|
|
|
|
for var in prog.list_vars():
|
|
|
|
print(var)
|
|
|
|
print(var)
|
|
|
|
|
|
|
|
|
|
|
|
# var img : fluid.VarType.LOD_TENSOR.shape(-1, 1, 28, 28).astype(VarType.FP32)
|
|
|
|
# var img : paddle.VarType.LOD_TENSOR.shape(-1, 1, 28, 28).astype(VarType.FP32)
|
|
|
|
# var label : fluid.VarType.LOD_TENSOR.shape(-1, 1).astype(VarType.INT64)
|
|
|
|
# var label : paddle.VarType.LOD_TENSOR.shape(-1, 1).astype(VarType.INT64)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
for each_block in self.blocks:
|
|
|
|
for each_block in self.blocks:
|
|
|
|
for each_var in list(each_block.vars.values()):
|
|
|
|
for each_var in list(each_block.vars.values()):
|
|
|
@ -5132,8 +5138,8 @@ class Program(object):
|
|
|
|
# Here will print all parameters in current program, in this example,
|
|
|
|
# Here will print all parameters in current program, in this example,
|
|
|
|
# the result is like:
|
|
|
|
# the result is like:
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# persist trainable param fc_0.w_0 : fluid.VarType.LOD_TENSOR.shape(13, 10).astype(VarType.FP32)
|
|
|
|
# persist trainable param fc_0.w_0 : paddle.VarType.LOD_TENSOR.shape(13, 10).astype(VarType.FP32)
|
|
|
|
# persist trainable param fc_0.b_0 : fluid.VarType.LOD_TENSOR.shape(10,).astype(VarType.FP32)
|
|
|
|
# persist trainable param fc_0.b_0 : paddle.VarType.LOD_TENSOR.shape(10,).astype(VarType.FP32)
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Here print(param) will print out all the properties of a parameter,
|
|
|
|
# Here print(param) will print out all the properties of a parameter,
|
|
|
|
# including name, type and persistable, you can access to specific
|
|
|
|
# including name, type and persistable, you can access to specific
|
|
|
|