Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
55f73ba5
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
55f73ba5
编写于
9月 23, 2022
作者:
A
Aurelius84
提交者:
GitHub
9月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[OpAttr]Fix dropout2d/3d static API (#46434)
上级
cbf3f4ba
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
10 deletion
+27
-10
python/paddle/fluid/tests/unittests/test_dropout_op.py
python/paddle/fluid/tests/unittests/test_dropout_op.py
+26
-9
python/paddle/nn/functional/common.py
python/paddle/nn/functional/common.py
+1
-1
未找到文件。
python/paddle/fluid/tests/unittests/test_dropout_op.py
浏览文件 @
55f73ba5
...
...
@@ -1112,16 +1112,18 @@ class TestDropoutBackward(unittest.TestCase):
class
TestDropOutWithProbTensor
(
unittest
.
TestCase
):
def
setUp
(
self
):
shapes
=
[[
10
,
10
],
[
10
,
10
,
10
],
[
10
,
10
,
10
,
10
]]
self
.
inputs
=
[
np
.
random
.
random
(
shape
).
astype
(
"float32"
)
for
shape
in
shapes
]
self
.
init_info
()
self
.
input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
self
.
place
=
paddle
.
CUDAPlace
(
0
)
if
paddle
.
is_compiled_with_cuda
()
else
paddle
.
CPUPlace
()
def
init_info
(
self
):
self
.
shape
=
[
10
,
10
]
self
.
api
=
paddle
.
nn
.
functional
.
dropout
def
api_case
(
self
,
x
):
p
=
paddle
.
assign
([
0.5
])
out
=
paddle
.
nn
.
functional
.
dropout
(
x
=
x
,
p
=
p
,
training
=
True
)
out
=
self
.
api
(
x
=
x
,
p
=
p
,
training
=
True
)
return
out
def
run_static
(
self
,
x
):
...
...
@@ -1131,6 +1133,8 @@ class TestDropOutWithProbTensor(unittest.TestCase):
with
program_guard
(
main_program
):
input
=
paddle
.
static
.
data
(
shape
=
x
.
shape
,
name
=
'x'
,
dtype
=
'float32'
)
out
=
self
.
api_case
(
input
)
sgd
=
paddle
.
optimizer
.
SGD
(
learning_rate
=
0.1
)
sgd
.
minimize
(
paddle
.
mean
(
out
))
exe
=
paddle
.
static
.
Executor
(
self
.
place
)
res
=
exe
.
run
(
feed
=
{
'x'
:
x
},
fetch_list
=
[
out
])
...
...
@@ -1144,10 +1148,23 @@ class TestDropOutWithProbTensor(unittest.TestCase):
return
out
def
test_p_tensor
(
self
):
for
x
in
self
.
inputs
:
static_res
=
self
.
run_static
(
x
)
dygraph_res
=
self
.
run_dygraph
(
x
)
np
.
testing
.
assert_array_equal
(
static_res
,
dygraph_res
)
static_res
=
self
.
run_static
(
self
.
input
)
dygraph_res
=
self
.
run_dygraph
(
self
.
input
)
np
.
testing
.
assert_array_equal
(
static_res
,
dygraph_res
)
class
TestDropOut2DWithProbTensor
(
TestDropOutWithProbTensor
):
def
init_info
(
self
):
self
.
shape
=
[
2
,
3
,
10
,
10
]
self
.
api
=
paddle
.
nn
.
functional
.
dropout2d
class
TestDropOut3DWithProbTensor
(
TestDropOutWithProbTensor
):
def
init_info
(
self
):
self
.
shape
=
[
2
,
3
,
8
,
8
,
8
]
self
.
api
=
paddle
.
nn
.
functional
.
dropout3d
class
TestRandomValue
(
unittest
.
TestCase
):
...
...
python/paddle/nn/functional/common.py
浏览文件 @
55f73ba5
...
...
@@ -1116,7 +1116,7 @@ def dropout(x,
dtype
=
x
.
dtype
keep_prob
=
1
-
p
if
training
:
if
p
==
1.
:
if
in_dynamic_mode
()
and
p
==
1.
:
return
paddle
.
scale
(
x
,
scale
=
0.
)
scale_input
=
paddle
.
scale
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录