Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
7c7cdf08
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
7c7cdf08
编写于
11月 23, 2020
作者:
C
Chen Weihang
提交者:
GitHub
11月 23, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove fluid & variable in program (#28966)
上级
8ff35506
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
12 deletion
+18
-12
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+18
-12
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
7c7cdf08
...
@@ -1297,9 +1297,12 @@ class Variable(object):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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):
...
@@ -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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录