Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0db7bc73
提交
0db7bc73
authored
6月 23, 2017
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Force batchnorm grad grad experiments to run in float64.
上级
ecd9be60
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
12 行删除
+14
-12
bn.py
theano/tensor/nnet/bn.py
+1
-1
test_bn.py
theano/tensor/nnet/tests/test_bn.py
+13
-11
没有找到文件。
theano/tensor/nnet/bn.py
浏览文件 @
0db7bc73
...
...
@@ -612,7 +612,7 @@ class AbstractBatchNormTrainGrad(Op):
g_wrt_x_invstd
=
0
if
not
isinstance
(
ddinputs
.
type
,
theano
.
gradient
.
DisconnectedType
):
ccc
=
(
ddinputs
*
scale
)
-
T
.
mean
(
ddinputs
*
scale
,
axis
=
self
.
axes
,
keepdims
=
True
)
ccc
=
scale
*
(
ddinputs
-
T
.
mean
(
ddinputs
,
axis
=
self
.
axes
,
keepdims
=
True
)
)
ddd
=
(
x_invstd
**
3
)
*
(
ccc
*
T
.
mean
(
dy
*
x_diff
,
axis
=
self
.
axes
,
keepdims
=
True
)
+
dy
*
T
.
mean
(
ccc
*
x_diff
,
axis
=
self
.
axes
,
keepdims
=
True
))
...
...
theano/tensor/nnet/tests/test_bn.py
浏览文件 @
0db7bc73
...
...
@@ -242,9 +242,9 @@ def test_batch_normalization_train():
utt
.
assert_allclose
(
outputs
[
11
],
outputs
[
11
+
3
],
rtol
=
2e-4
,
atol
=
1e-4
)
# dscale
utt
.
assert_allclose
(
outputs
[
12
],
outputs
[
12
+
3
])
# dbias
# compare second-order gradients
utt
.
assert_allclose
(
outputs
[
16
],
outputs
[
16
+
3
])
# ddx
utt
.
assert_allclose
(
outputs
[
16
],
outputs
[
16
+
3
]
,
atol
=
1e-4
)
# ddx
utt
.
assert_allclose
(
outputs
[
17
],
outputs
[
17
+
3
])
# ddy
utt
.
assert_allclose
(
outputs
[
18
],
outputs
[
18
+
3
])
# ddscale
utt
.
assert_allclose
(
outputs
[
18
],
outputs
[
18
+
3
]
,
rtol
=
3e-4
,
atol
=
1e-4
)
# ddscale
def
test_batch_normalization_train_grad_grad
():
...
...
@@ -252,7 +252,8 @@ def test_batch_normalization_train_grad_grad():
for
axes
in
(
'per-activation'
,
'spatial'
,
(
1
,
2
,
3
,
4
)):
for
vartype
in
(
T
.
tensor5
,
T
.
tensor4
,
T
.
tensor3
,
T
.
matrix
,
T
.
vector
):
x
,
dy
,
scale
,
x_mean
,
x_invstd
=
(
vartype
(
n
)
# run these experiments with float64 for sufficient numerical stability
x
,
dy
,
scale
,
x_mean
,
x_invstd
=
(
vartype
(
n
,
dtype
=
'float64'
)
for
n
in
(
'x'
,
'dy'
,
'scale'
,
'x_mean'
,
'x_invstd'
))
ndim
=
x
.
ndim
...
...
@@ -281,17 +282,18 @@ def test_batch_normalization_train_grad_grad():
return
g_bias
# run
for
data_shape
in
((
7
,
9
,
3
,
4
,
5
),
(
4
,
3
,
1
,
1
,
1
),
(
2
,
3
,
5
,
5
,
5
)):
for
data_shape
in
((
4
,
3
,
3
,
3
,
3
),
(
4
,
3
,
1
,
1
,
1
),
(
2
,
3
,
5
,
3
,
2
)):
data_shape
=
data_shape
[:
ndim
]
param_shape
=
tuple
(
1
if
d
in
axes
else
s
for
d
,
s
in
enumerate
(
data_shape
))
x_val
=
4
+
4
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
theano
.
config
.
floatX
)
dy_val
=
-
1
+
3
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
theano
.
config
.
floatX
)
scale_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
theano
.
config
.
floatX
)
x_mean_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
theano
.
config
.
floatX
)
x_invstd_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
theano
.
config
.
floatX
)
utt
.
verify_grad
(
bn_grad_wrt_inputs_f
,
[
x_val
,
dy_val
,
scale_val
,
x_mean_val
,
x_invstd_val
],
eps
=
1e-6
,
abs_tol
=
2e-4
)
# force float64 for sufficient numerical stability
x_val
=
4
+
3
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
'float64'
)
dy_val
=
-
1
+
2
*
np
.
random
.
randn
(
*
data_shape
)
.
astype
(
'float64'
)
scale_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
'float64'
)
x_mean_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
'float64'
)
x_invstd_val
=
np
.
random
.
randn
(
*
param_shape
)
.
astype
(
'float64'
)
utt
.
verify_grad
(
bn_grad_wrt_inputs_f
,
[
x_val
,
dy_val
,
scale_val
,
x_mean_val
,
x_invstd_val
])
utt
.
verify_grad
(
bn_grad_wrt_scale_f
,
[
x_val
,
dy_val
,
scale_val
,
x_mean_val
,
x_invstd_val
])
utt
.
verify_grad
(
bn_grad_wrt_bias_f
,
[
x_val
,
dy_val
,
scale_val
,
x_mean_val
,
x_invstd_val
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论