Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
afeixing77
Paddle
提交
f9e2a279
P
Paddle
项目概览
afeixing77
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f9e2a279
编写于
4月 10, 2020
作者:
S
silingtong123
提交者:
GitHub
4月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
error message of SpectralNorm OP enhancement (#23516)
上级
076dcdfd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
45 addition
and
0 deletion
+45
-0
python/paddle/fluid/dygraph/nn.py
python/paddle/fluid/dygraph/nn.py
+2
-0
python/paddle/fluid/tests/unittests/test_spectral_norm_op.py
python/paddle/fluid/tests/unittests/test_spectral_norm_op.py
+43
-0
未找到文件。
python/paddle/fluid/dygraph/nn.py
浏览文件 @
f9e2a279
...
...
@@ -2989,6 +2989,8 @@ class SpectralNorm(layers.Layer):
self
.
weight_v
.
stop_gradient
=
True
def
forward
(
self
,
weight
):
check_variable_and_dtype
(
weight
,
"weight"
,
[
'float32'
,
'float64'
],
'SpectralNorm'
)
inputs
=
{
'Weight'
:
weight
,
'U'
:
self
.
weight_u
,
'V'
:
self
.
weight_v
}
out
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
self
.
_helper
.
append_op
(
...
...
python/paddle/fluid/tests/unittests/test_spectral_norm_op.py
浏览文件 @
f9e2a279
...
...
@@ -16,9 +16,11 @@ from __future__ import division
import
unittest
import
numpy
as
np
import
paddle.fluid
as
fluid
from
op_test
import
OpTest
,
skip_check_grad_ci
from
paddle.fluid
import
core
from
paddle.fluid.framework
import
program_guard
,
Program
def
spectral_norm
(
weight
,
u
,
v
,
dim
,
power_iters
,
eps
):
...
...
@@ -125,5 +127,46 @@ class TestSpectralNormOp2(TestSpectralNormOp):
self
.
eps
=
1e-12
class
TestSpectralNormOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
def
test_Variable
():
weight_1
=
np
.
random
.
random
((
2
,
4
)).
astype
(
"float32"
)
fluid
.
layers
.
spectral_norm
(
weight_1
,
dim
=
1
,
power_iters
=
2
)
# the weight type of spectral_norm must be Variable
self
.
assertRaises
(
TypeError
,
test_Variable
)
def
test_weight_dtype
():
weight_2
=
np
.
random
.
random
((
2
,
4
)).
astype
(
"int32"
)
fluid
.
layers
.
spectral_norm
(
weight_2
,
dim
=
1
,
power_iters
=
2
)
# the data type of type must be float32 or float64
self
.
assertRaises
(
TypeError
,
test_weight_dtype
)
class
TestDygraphSpectralNormOpError
(
unittest
.
TestCase
):
def
test_errors
(
self
):
with
program_guard
(
Program
(),
Program
()):
shape
=
(
2
,
4
,
3
,
3
)
spectralNorm
=
fluid
.
dygraph
.
nn
.
SpectralNorm
(
shape
,
dim
=
1
,
power_iters
=
2
)
def
test_Variable
():
weight_1
=
np
.
random
.
random
((
2
,
4
)).
astype
(
"float32"
)
spectralNorm
(
weight_1
)
# the weight type of SpectralNorm must be Variable
self
.
assertRaises
(
TypeError
,
test_Variable
)
def
test_weight_dtype
():
weight_2
=
np
.
random
.
random
((
2
,
4
)).
astype
(
"int32"
)
spectralNorm
(
weight_2
)
# the data type of type must be float32 or float64
self
.
assertRaises
(
TypeError
,
test_weight_dtype
)
if
__name__
==
"__main__"
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录