Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
0492158d
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0492158d
编写于
12月 05, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
polish
test=develop
上级
b4db31ba
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
9 addition
and
30 deletion
+9
-30
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+3
-4
python/paddle/fluid/imperative/layers.py
python/paddle/fluid/imperative/layers.py
+2
-7
python/paddle/fluid/layer_helper.py
python/paddle/fluid/layer_helper.py
+1
-16
python/paddle/fluid/tests/unittests/test_imperative.py
python/paddle/fluid/tests/unittests/test_imperative.py
+3
-3
未找到文件。
python/paddle/fluid/framework.py
浏览文件 @
0492158d
...
...
@@ -293,7 +293,6 @@ class Variable(core.VarBase):
if
is_new_var
:
self
.
desc
.
set_type
(
type
)
elif
self
.
desc
.
type
()
!=
type
:
# sys.stderr.write('%s vs %s\n' % (self.desc.type(), type))
raise
ValueError
(
"Variable {0} has been created before. The "
"previous type is {1}; the new type is {2}. They"
" are not matched"
.
format
(
self
.
name
,
...
...
@@ -358,16 +357,16 @@ class Variable(core.VarBase):
self
.
stop_gradient
=
stop_gradient
self
.
is_data
=
is_data
def
numpy
(
self
):
def
_
numpy
(
self
):
scope
=
_imperative_tracer
().
get_scope
(
self
.
block
.
desc
)
tensor
=
core
.
get_variable_tensor
(
scope
,
self
.
desc
.
name
())
return
np
.
array
(
tensor
)
def
backward
(
self
):
def
_
backward
(
self
):
scope
=
_imperative_tracer
().
get_scope
(
self
.
block
.
desc
)
self
.
_run_backward
(
scope
)
def
grad
(
self
):
def
_gradient
(
self
):
return
np
.
array
(
self
.
_grad
())
def
__str__
(
self
):
...
...
python/paddle/fluid/imperative/layers.py
浏览文件 @
0492158d
...
...
@@ -35,13 +35,8 @@ class PyLayer(core.Layer):
var_inputs
=
[]
for
x
in
inputs
:
if
isinstance
(
x
,
np
.
ndarray
):
py_var
=
base
.
to_variable
(
x
)
var_inputs
.
append
(
py_var
)
elif
isinstance
(
x
,
framework
.
Variable
):
var_inputs
.
append
(
x
)
else
:
raise
ValueError
(
"not var or ndarray %s"
%
type
(
x
))
py_var
=
base
.
to_variable
(
x
)
var_inputs
.
append
(
py_var
)
outputs
=
self
.
forward
(
var_inputs
)
return
outputs
...
...
python/paddle/fluid/layer_helper.py
浏览文件 @
0492158d
...
...
@@ -49,23 +49,8 @@ class LayerHelper(object):
def
startup_program
(
self
):
return
default_startup_program
()
def
_np_to_variable
(
self
,
x
):
tensor
=
core
.
LoDTensor
()
tensor
.
set
(
x
,
core
.
CPUPlace
())
return
Variable
(
self
.
main_program
.
current_block
(),
type
=
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
name
=
None
,
shape
=
x
.
shape
,
dtype
=
x
.
dtype
)
def
to_variable
(
self
,
x
):
if
isinstance
(
x
,
Variable
):
return
x
elif
isinstance
(
x
,
np
.
ndarray
):
return
base
.
to_variable
(
x
,
self
.
main_program
.
current_block
())
else
:
raise
ValueError
(
"inputs wrong type %s
\n
"
%
x
)
return
base
.
to_variable
(
x
,
self
.
main_program
.
current_block
())
def
append_op
(
self
,
*
args
,
**
kwargs
):
return
self
.
main_program
.
current_block
().
append_op
(
*
args
,
**
kwargs
)
...
...
python/paddle/fluid/tests/unittests/test_imperative.py
浏览文件 @
0492158d
...
...
@@ -43,9 +43,9 @@ class TestImperative(unittest.TestCase):
l
=
MyLayer
()
x
=
l
(
np
.
array
([
1.0
,
2.0
,
-
1.0
],
dtype
=
np
.
float32
))[
0
]
self
.
assertIsNotNone
(
x
)
sys
.
stderr
.
write
(
"%s output: %s
\n
"
%
(
x
,
x
.
numpy
()))
x
.
backward
()
sys
.
stderr
.
write
(
"grad %s
\n
"
%
l
.
_x_for_debug
.
grad
())
sys
.
stderr
.
write
(
"%s output: %s
\n
"
%
(
x
,
x
.
_
numpy
()))
x
.
_
backward
()
sys
.
stderr
.
write
(
"grad %s
\n
"
%
l
.
_x_for_debug
.
_gradient
())
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录