Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
55f73ba5
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看板
未验证
提交
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):
...
@@ -1112,16 +1112,18 @@ class TestDropoutBackward(unittest.TestCase):
class
TestDropOutWithProbTensor
(
unittest
.
TestCase
):
class
TestDropOutWithProbTensor
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
shapes
=
[[
10
,
10
],
[
10
,
10
,
10
],
[
10
,
10
,
10
,
10
]]
self
.
init_info
()
self
.
inputs
=
[
self
.
input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
np
.
random
.
random
(
shape
).
astype
(
"float32"
)
for
shape
in
shapes
]
self
.
place
=
paddle
.
CUDAPlace
(
self
.
place
=
paddle
.
CUDAPlace
(
0
)
if
paddle
.
is_compiled_with_cuda
()
else
paddle
.
CPUPlace
()
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
):
def
api_case
(
self
,
x
):
p
=
paddle
.
assign
([
0.5
])
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
return
out
def
run_static
(
self
,
x
):
def
run_static
(
self
,
x
):
...
@@ -1131,6 +1133,8 @@ class TestDropOutWithProbTensor(unittest.TestCase):
...
@@ -1131,6 +1133,8 @@ class TestDropOutWithProbTensor(unittest.TestCase):
with
program_guard
(
main_program
):
with
program_guard
(
main_program
):
input
=
paddle
.
static
.
data
(
shape
=
x
.
shape
,
name
=
'x'
,
dtype
=
'float32'
)
input
=
paddle
.
static
.
data
(
shape
=
x
.
shape
,
name
=
'x'
,
dtype
=
'float32'
)
out
=
self
.
api_case
(
input
)
out
=
self
.
api_case
(
input
)
sgd
=
paddle
.
optimizer
.
SGD
(
learning_rate
=
0.1
)
sgd
.
minimize
(
paddle
.
mean
(
out
))
exe
=
paddle
.
static
.
Executor
(
self
.
place
)
exe
=
paddle
.
static
.
Executor
(
self
.
place
)
res
=
exe
.
run
(
feed
=
{
'x'
:
x
},
fetch_list
=
[
out
])
res
=
exe
.
run
(
feed
=
{
'x'
:
x
},
fetch_list
=
[
out
])
...
@@ -1144,12 +1148,25 @@ class TestDropOutWithProbTensor(unittest.TestCase):
...
@@ -1144,12 +1148,25 @@ class TestDropOutWithProbTensor(unittest.TestCase):
return
out
return
out
def
test_p_tensor
(
self
):
def
test_p_tensor
(
self
):
for
x
in
self
.
inputs
:
static_res
=
self
.
run_static
(
self
.
input
)
static_res
=
self
.
run_static
(
x
)
dygraph_res
=
self
.
run_dygraph
(
self
.
input
)
dygraph_res
=
self
.
run_dygraph
(
x
)
np
.
testing
.
assert_array_equal
(
static_res
,
dygraph_res
)
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
):
class
TestRandomValue
(
unittest
.
TestCase
):
def
test_fixed_random_number
(
self
):
def
test_fixed_random_number
(
self
):
...
...
python/paddle/nn/functional/common.py
浏览文件 @
55f73ba5
...
@@ -1116,7 +1116,7 @@ def dropout(x,
...
@@ -1116,7 +1116,7 @@ def dropout(x,
dtype
=
x
.
dtype
dtype
=
x
.
dtype
keep_prob
=
1
-
p
keep_prob
=
1
-
p
if
training
:
if
training
:
if
p
==
1.
:
if
in_dynamic_mode
()
and
p
==
1.
:
return
paddle
.
scale
(
x
,
scale
=
0.
)
return
paddle
.
scale
(
x
,
scale
=
0.
)
scale_input
=
paddle
.
scale
(
scale_input
=
paddle
.
scale
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录