Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8a23fb1c
提交
8a23fb1c
authored
1月 26, 2021
作者:
Brandon T. Willard
提交者:
Thomas Wiecki
1月 27, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename theano.tensor.nnet.bn to theano.tensor.nnet.batchnorm
上级
e0e5b3b8
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
84 行增加
和
72 行删除
+84
-72
test_dnn.py
tests/gpuarray/test_dnn.py
+35
-29
test_batchnorm.py
tests/tensor/nnet/test_batchnorm.py
+38
-32
opt.py
theano/gpuarray/opt.py
+10
-10
__init__.py
theano/tensor/nnet/__init__.py
+1
-1
batchnorm.py
theano/tensor/nnet/batchnorm.py
+0
-0
没有找到文件。
tests/gpuarray/test_dnn.py
浏览文件 @
8a23fb1c
...
@@ -48,7 +48,7 @@ from theano.tensor.nnet import (
...
@@ -48,7 +48,7 @@ from theano.tensor.nnet import (
LogSoftmax
,
LogSoftmax
,
Softmax
,
Softmax
,
SoftmaxGrad
,
SoftmaxGrad
,
b
n
,
b
atchnorm
,
conv2d
,
conv2d
,
softmax
,
softmax
,
softmax_op
,
softmax_op
,
...
@@ -1869,7 +1869,7 @@ def test_dnn_batchnorm_train():
...
@@ -1869,7 +1869,7 @@ def test_dnn_batchnorm_train():
x_invstd_abstract
,
x_invstd_abstract
,
out_running_mean_abstract
,
out_running_mean_abstract
,
out_running_var_abstract
,
out_running_var_abstract
,
)
=
b
n
.
batch_normalization_train
(
)
=
b
atchnorm
.
batch_normalization_train
(
x
,
x
,
scale
,
scale
,
bias
,
bias
,
...
@@ -1966,9 +1966,9 @@ def test_dnn_batchnorm_train():
...
@@ -1966,9 +1966,9 @@ def test_dnn_batchnorm_train():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
...
@@ -2044,9 +2044,11 @@ def test_dnn_batchnorm_train_without_running_averages():
...
@@ -2044,9 +2044,11 @@ def test_dnn_batchnorm_train_without_running_averages():
out_gpu
,
x_mean_gpu
,
x_invstd_gpu
=
dnn
.
dnn_batch_normalization_train
(
out_gpu
,
x_mean_gpu
,
x_invstd_gpu
=
dnn
.
dnn_batch_normalization_train
(
x
,
scale
,
bias
,
"per-activation"
x
,
scale
,
bias
,
"per-activation"
)
)
out_abstract
,
x_mean_abstract
,
x_invstd_abstract
=
bn
.
batch_normalization_train
(
(
x
,
scale
,
bias
,
"per-activation"
out_abstract
,
)
x_mean_abstract
,
x_invstd_abstract
,
)
=
batchnorm
.
batch_normalization_train
(
x
,
scale
,
bias
,
"per-activation"
)
# backward pass
# backward pass
grads_gpu
=
theano
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_gpu
:
dy
})
grads_gpu
=
theano
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_gpu
:
dy
})
grads_abstract
=
theano
.
grad
(
grads_abstract
=
theano
.
grad
(
...
@@ -2081,9 +2083,9 @@ def test_dnn_batchnorm_train_without_running_averages():
...
@@ -2081,9 +2083,9 @@ def test_dnn_batchnorm_train_without_running_averages():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
...
@@ -2113,9 +2115,11 @@ def test_without_dnn_batchnorm_train_without_running_averages():
...
@@ -2113,9 +2115,11 @@ def test_without_dnn_batchnorm_train_without_running_averages():
param_shape
=
(
1
,
10
,
30
,
25
)
param_shape
=
(
1
,
10
,
30
,
25
)
# forward pass
# forward pass
out_abstract
,
x_mean_abstract
,
x_invstd_abstract
=
bn
.
batch_normalization_train
(
(
x
,
scale
,
bias
,
"per-activation"
out_abstract
,
)
x_mean_abstract
,
x_invstd_abstract
,
)
=
batchnorm
.
batch_normalization_train
(
x
,
scale
,
bias
,
"per-activation"
)
# backward pass
# backward pass
grads_abstract
=
theano
.
grad
(
grads_abstract
=
theano
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_abstract
:
dy
}
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_abstract
:
dy
}
...
@@ -2144,9 +2148,9 @@ def test_without_dnn_batchnorm_train_without_running_averages():
...
@@ -2144,9 +2148,9 @@ def test_without_dnn_batchnorm_train_without_running_averages():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
...
@@ -2243,7 +2247,7 @@ def test_batchnorm_inference():
...
@@ -2243,7 +2247,7 @@ def test_batchnorm_inference():
x
,
scale
,
bias
,
mean
,
var
,
mode
,
eps
x
,
scale
,
bias
,
mean
,
var
,
mode
,
eps
)
)
# forward pass, abstract interface
# forward pass, abstract interface
out_abstract
=
b
n
.
batch_normalization_test
(
out_abstract
=
b
atchnorm
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
mode
,
eps
x
,
scale
,
bias
,
mean
,
var
,
mode
,
eps
)
)
# reference forward pass
# reference forward pass
...
@@ -2293,9 +2297,9 @@ def test_batchnorm_inference():
...
@@ -2293,9 +2297,9 @@ def test_batchnorm_inference():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
for
n
in
f_abstract
.
maker
.
fgraph
.
toposort
()
...
@@ -2389,10 +2393,12 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
...
@@ -2389,10 +2393,12 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
invalid_axes_lists
=
(
tuple
(
range
(
1
,
ndim
)),)
invalid_axes_lists
=
(
tuple
(
range
(
1
,
ndim
)),)
for
axes
in
valid_axes_lists
+
invalid_axes_lists
:
for
axes
in
valid_axes_lists
+
invalid_axes_lists
:
# forward pass, abstract interface
# forward pass, abstract interface
out_train
,
x_mean
,
x_invstd
=
b
n
.
batch_normalization_train
(
out_train
,
x_mean
,
x_invstd
=
b
atchnorm
.
batch_normalization_train
(
x
,
scale
,
bias
,
axes
x
,
scale
,
bias
,
axes
)
)
out_test
=
bn
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
axes
)
out_test
=
batchnorm
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
axes
)
# backward pass
# backward pass
dy
=
vartype
(
"dy"
)
dy
=
vartype
(
"dy"
)
grads_train
=
theano
.
grad
(
grads_train
=
theano
.
grad
(
...
@@ -2433,9 +2439,9 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
...
@@ -2433,9 +2439,9 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
for
n
in
f
.
maker
.
fgraph
.
toposort
()
...
@@ -2450,9 +2456,9 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
...
@@ -2450,9 +2456,9 @@ def test_dnn_batchnorm_valid_and_invalid_axes():
(
(
dnn
.
GpuDnnBatchNorm
,
dnn
.
GpuDnnBatchNorm
,
dnn
.
GpuDnnBatchNormGrad
,
dnn
.
GpuDnnBatchNormGrad
,
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
for
n
in
f
.
maker
.
fgraph
.
toposort
()
...
...
tests/tensor/nnet/test_b
n
.py
→
tests/tensor/nnet/test_b
atchnorm
.py
浏览文件 @
8a23fb1c
...
@@ -8,7 +8,7 @@ import theano.tensor as tt
...
@@ -8,7 +8,7 @@ import theano.tensor as tt
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
from
theano.configdefaults
import
config
from
theano.configdefaults
import
config
from
theano.tensor.math
import
sum
as
tt_sum
from
theano.tensor.math
import
sum
as
tt_sum
from
theano.tensor.nnet
import
b
n
from
theano.tensor.nnet
import
b
atchnorm
from
theano.tensor.type
import
(
from
theano.tensor.type
import
(
TensorType
,
TensorType
,
matrix
,
matrix
,
...
@@ -51,7 +51,7 @@ def test_BNComposite():
...
@@ -51,7 +51,7 @@ def test_BNComposite():
f_ref
=
theano
.
function
([
x
,
b
,
g
,
m
,
v
],
[
bn_ref_op
])
f_ref
=
theano
.
function
([
x
,
b
,
g
,
m
,
v
],
[
bn_ref_op
])
res_ref
=
f_ref
(
X
,
G
,
B
,
M
,
V
)
res_ref
=
f_ref
(
X
,
G
,
B
,
M
,
V
)
for
mode
in
[
"low_mem"
,
"high_mem"
]:
for
mode
in
[
"low_mem"
,
"high_mem"
]:
bn_op
=
b
n
.
batch_normalization
(
x
,
g
,
b
,
m
,
v
,
mode
=
mode
)
bn_op
=
b
atchnorm
.
batch_normalization
(
x
,
g
,
b
,
m
,
v
,
mode
=
mode
)
f
=
theano
.
function
([
x
,
b
,
g
,
m
,
v
],
[
bn_op
])
f
=
theano
.
function
([
x
,
b
,
g
,
m
,
v
],
[
bn_op
])
res
=
f
(
X
,
G
,
B
,
M
,
V
)
res
=
f
(
X
,
G
,
B
,
M
,
V
)
utt
.
assert_allclose
(
res_ref
,
res
)
utt
.
assert_allclose
(
res_ref
,
res
)
...
@@ -79,13 +79,15 @@ def test_batch_normalization():
...
@@ -79,13 +79,15 @@ def test_batch_normalization():
f_ref
=
theano
.
function
([
x
,
g
,
b
,
m
,
v
],
[
bn_ref_op
])
f_ref
=
theano
.
function
([
x
,
g
,
b
,
m
,
v
],
[
bn_ref_op
])
res_ref
=
f_ref
(
X
,
G
,
B
,
M
,
V
)
res_ref
=
f_ref
(
X
,
G
,
B
,
M
,
V
)
for
mode
in
[
"low_mem"
,
"high_mem"
]:
for
mode
in
[
"low_mem"
,
"high_mem"
]:
bn_op
=
b
n
.
batch_normalization
(
x
,
g
,
b
,
m
,
v
,
mode
=
mode
)
bn_op
=
b
atchnorm
.
batch_normalization
(
x
,
g
,
b
,
m
,
v
,
mode
=
mode
)
f
=
theano
.
function
([
x
,
g
,
b
,
m
,
v
],
[
bn_op
])
f
=
theano
.
function
([
x
,
g
,
b
,
m
,
v
],
[
bn_op
])
res
=
f
(
X
,
G
,
B
,
M
,
V
)
res
=
f
(
X
,
G
,
B
,
M
,
V
)
utt
.
assert_allclose
(
res_ref
,
res
)
utt
.
assert_allclose
(
res_ref
,
res
)
def
bn_f
(
inputs
,
gamma
,
beta
,
mean
,
std
):
def
bn_f
(
inputs
,
gamma
,
beta
,
mean
,
std
):
return
bn
.
batch_normalization
(
inputs
,
gamma
,
beta
,
mean
,
std
,
mode
=
mode
)
return
batchnorm
.
batch_normalization
(
inputs
,
gamma
,
beta
,
mean
,
std
,
mode
=
mode
)
utt
.
verify_grad
(
bn_f
,
[
X
,
G
,
B
,
M
,
V
])
utt
.
verify_grad
(
bn_f
,
[
X
,
G
,
B
,
M
,
V
])
...
@@ -95,7 +97,7 @@ def test_batch_normalization():
...
@@ -95,7 +97,7 @@ def test_batch_normalization():
f_ref
=
theano
.
function
([
x
,
b
,
g
],
[
bn_ref_op
])
f_ref
=
theano
.
function
([
x
,
b
,
g
],
[
bn_ref_op
])
res_ref
=
f_ref
(
X
,
G
,
B
)
res_ref
=
f_ref
(
X
,
G
,
B
)
for
mode
in
[
"low_mem"
,
"high_mem"
]:
for
mode
in
[
"low_mem"
,
"high_mem"
]:
bn_op
=
b
n
.
batch_normalization
(
bn_op
=
b
atchnorm
.
batch_normalization
(
x
,
x
,
g
,
g
,
b
,
b
,
...
@@ -108,7 +110,9 @@ def test_batch_normalization():
...
@@ -108,7 +110,9 @@ def test_batch_normalization():
utt
.
assert_allclose
(
res_ref
,
res
)
utt
.
assert_allclose
(
res_ref
,
res
)
def
bn_f
(
inputs
,
gamma
,
beta
,
mean
,
std
):
def
bn_f
(
inputs
,
gamma
,
beta
,
mean
,
std
):
return
bn
.
batch_normalization
(
inputs
,
gamma
,
beta
,
mean
,
std
,
mode
=
mode
)
return
batchnorm
.
batch_normalization
(
inputs
,
gamma
,
beta
,
mean
,
std
,
mode
=
mode
)
utt
.
verify_grad
(
utt
.
verify_grad
(
bn_f
,
[
X
,
G
,
B
,
X
.
mean
(
axis
=
0
)[
np
.
newaxis
],
X
.
std
(
axis
=
0
)[
np
.
newaxis
]]
bn_f
,
[
X
,
G
,
B
,
X
.
mean
(
axis
=
0
)[
np
.
newaxis
],
X
.
std
(
axis
=
0
)[
np
.
newaxis
]]
...
@@ -144,7 +148,7 @@ def test_bn_feature_maps():
...
@@ -144,7 +148,7 @@ def test_bn_feature_maps():
res_ref
=
f_ref
(
X
,
G
,
B
,
M
,
V
)
res_ref
=
f_ref
(
X
,
G
,
B
,
M
,
V
)
for
mode
in
[
"low_mem"
,
"high_mem"
]:
for
mode
in
[
"low_mem"
,
"high_mem"
]:
bn_op
=
b
n
.
batch_normalization
(
bn_op
=
b
atchnorm
.
batch_normalization
(
x
,
x
,
g
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
g
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
b
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
b
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
...
@@ -157,7 +161,7 @@ def test_bn_feature_maps():
...
@@ -157,7 +161,7 @@ def test_bn_feature_maps():
utt
.
assert_allclose
(
res_ref
,
res
)
utt
.
assert_allclose
(
res_ref
,
res
)
def
conv_bn
(
inputs
,
gamma
,
beta
,
mean
,
std
):
def
conv_bn
(
inputs
,
gamma
,
beta
,
mean
,
std
):
return
b
n
.
batch_normalization
(
return
b
atchnorm
.
batch_normalization
(
inputs
,
inputs
,
gamma
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
gamma
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
beta
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
beta
.
dimshuffle
(
"x"
,
0
,
"x"
,
"x"
),
...
@@ -196,7 +200,7 @@ def test_batch_normalization_train():
...
@@ -196,7 +200,7 @@ def test_batch_normalization_train():
x_invstd
,
x_invstd
,
out_running_mean
,
out_running_mean
,
out_running_var
,
out_running_var
,
)
=
b
n
.
batch_normalization_train
(
)
=
b
atchnorm
.
batch_normalization_train
(
x
,
x
,
scale
,
scale
,
bias
,
bias
,
...
@@ -300,9 +304,9 @@ def test_batch_normalization_train():
...
@@ -300,9 +304,9 @@ def test_batch_normalization_train():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
for
n
in
f
.
maker
.
fgraph
.
toposort
()
...
@@ -378,19 +382,19 @@ def test_batch_normalization_train_grad_grad():
...
@@ -378,19 +382,19 @@ def test_batch_normalization_train_grad_grad():
continue
continue
def
bn_grad_wrt_inputs_f
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
):
def
bn_grad_wrt_inputs_f
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
):
g_inputs
,
g_scale
,
g_bias
=
b
n
.
AbstractBatchNormTrainGrad
(
axes
)(
g_inputs
,
g_scale
,
g_bias
=
b
atchnorm
.
AbstractBatchNormTrainGrad
(
axes
)(
x
,
dy
,
scale
,
x_mean
,
x_invstd
x
,
dy
,
scale
,
x_mean
,
x_invstd
)
)
return
g_inputs
return
g_inputs
def
bn_grad_wrt_scale_f
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
):
def
bn_grad_wrt_scale_f
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
):
g_inputs
,
g_scale
,
g_bias
=
b
n
.
AbstractBatchNormTrainGrad
(
axes
)(
g_inputs
,
g_scale
,
g_bias
=
b
atchnorm
.
AbstractBatchNormTrainGrad
(
axes
)(
x
,
dy
,
scale
,
x_mean
,
x_invstd
x
,
dy
,
scale
,
x_mean
,
x_invstd
)
)
return
g_scale
return
g_scale
def
bn_grad_wrt_bias_f
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
):
def
bn_grad_wrt_bias_f
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
):
g_inputs
,
g_scale
,
g_bias
=
b
n
.
AbstractBatchNormTrainGrad
(
axes
)(
g_inputs
,
g_scale
,
g_bias
=
b
atchnorm
.
AbstractBatchNormTrainGrad
(
axes
)(
x
,
dy
,
scale
,
x_mean
,
x_invstd
x
,
dy
,
scale
,
x_mean
,
x_invstd
)
)
return
g_bias
return
g_bias
...
@@ -438,7 +442,7 @@ def test_batch_normalization_train_without_running_averages():
...
@@ -438,7 +442,7 @@ def test_batch_normalization_train_without_running_averages():
param_shape
=
(
1
,
10
,
30
,
25
)
param_shape
=
(
1
,
10
,
30
,
25
)
# forward pass
# forward pass
out
,
x_mean
,
x_invstd
=
b
n
.
batch_normalization_train
(
out
,
x_mean
,
x_invstd
=
b
atchnorm
.
batch_normalization_train
(
x
,
scale
,
bias
,
"per-activation"
x
,
scale
,
bias
,
"per-activation"
)
)
# backward pass
# backward pass
...
@@ -451,9 +455,9 @@ def test_batch_normalization_train_without_running_averages():
...
@@ -451,9 +455,9 @@ def test_batch_normalization_train_without_running_averages():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
for
n
in
f
.
maker
.
fgraph
.
toposort
()
...
@@ -508,7 +512,7 @@ def test_batch_normalization_train_broadcast():
...
@@ -508,7 +512,7 @@ def test_batch_normalization_train_broadcast():
running_var_bc
=
running_var
.
dimshuffle
(
params_dimshuffle
)
running_var_bc
=
running_var
.
dimshuffle
(
params_dimshuffle
)
# batch_normalization_train with original, non-broadcasted variables
# batch_normalization_train with original, non-broadcasted variables
train_non_bc
=
b
n
.
batch_normalization_train
(
train_non_bc
=
b
atchnorm
.
batch_normalization_train
(
x
,
x
,
scale
,
scale
,
bias
,
bias
,
...
@@ -519,7 +523,7 @@ def test_batch_normalization_train_broadcast():
...
@@ -519,7 +523,7 @@ def test_batch_normalization_train_broadcast():
running_var
,
running_var
,
)
)
# batch_normalization_train with broadcasted variables
# batch_normalization_train with broadcasted variables
train_bc
=
b
n
.
batch_normalization_train
(
train_bc
=
b
atchnorm
.
batch_normalization_train
(
x
,
x
,
scale_bc
,
scale_bc
,
bias_bc
,
bias_bc
,
...
@@ -534,11 +538,11 @@ def test_batch_normalization_train_broadcast():
...
@@ -534,11 +538,11 @@ def test_batch_normalization_train_broadcast():
)
)
# batch_normalization_test with original, non-broadcasted variables
# batch_normalization_test with original, non-broadcasted variables
test_non_bc
=
b
n
.
batch_normalization_test
(
test_non_bc
=
b
atchnorm
.
batch_normalization_test
(
x
,
scale
,
bias
,
running_mean
,
running_var
,
axes
,
eps
x
,
scale
,
bias
,
running_mean
,
running_var
,
axes
,
eps
)
)
# batch_normalization_test with broadcasted variables
# batch_normalization_test with broadcasted variables
test_bc
=
b
n
.
batch_normalization_test
(
test_bc
=
b
atchnorm
.
batch_normalization_test
(
x
,
scale_bc
,
bias_bc
,
running_mean_bc
,
running_var_bc
,
axes
,
eps
x
,
scale_bc
,
bias_bc
,
running_mean_bc
,
running_var_bc
,
axes
,
eps
)
)
...
@@ -588,7 +592,9 @@ def test_batch_normalization_test():
...
@@ -588,7 +592,9 @@ def test_batch_normalization_test():
continue
continue
# forward pass
# forward pass
out
=
bn
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
axes
,
eps
)
out
=
batchnorm
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
axes
,
eps
)
# reference forward pass
# reference forward pass
if
axes
==
"per-activation"
:
if
axes
==
"per-activation"
:
axes2
=
(
0
,)
axes2
=
(
0
,)
...
@@ -619,9 +625,9 @@ def test_batch_normalization_test():
...
@@ -619,9 +625,9 @@ def test_batch_normalization_test():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
for
n
in
f
.
maker
.
fgraph
.
toposort
()
...
@@ -660,10 +666,10 @@ def test_batch_normalization_broadcastable():
...
@@ -660,10 +666,10 @@ def test_batch_normalization_broadcastable():
)
)
# forward pass
# forward pass
out_train
,
x_mean
,
x_invstd
=
b
n
.
batch_normalization_train
(
out_train
,
x_mean
,
x_invstd
=
b
atchnorm
.
batch_normalization_train
(
x
,
scale
,
bias
,
"spatial"
x
,
scale
,
bias
,
"spatial"
)
)
out_test
=
b
n
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
"spatial"
)
out_test
=
b
atchnorm
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
"spatial"
)
# backward pass
# backward pass
grads_train
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_train
:
dy
})
grads_train
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_train
:
dy
})
grads_test
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_test
:
dy
})
grads_test
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out_test
:
dy
})
...
@@ -677,9 +683,9 @@ def test_batch_normalization_broadcastable():
...
@@ -677,9 +683,9 @@ def test_batch_normalization_broadcastable():
isinstance
(
isinstance
(
n
.
op
,
n
.
op
,
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
),
),
)
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()
for
n
in
f
.
maker
.
fgraph
.
toposort
()
...
...
theano/gpuarray/opt.py
浏览文件 @
8a23fb1c
...
@@ -179,7 +179,7 @@ from theano.tensor.basic import (
...
@@ -179,7 +179,7 @@ from theano.tensor.basic import (
Tri
,
Tri
,
)
)
from
theano.tensor.math
import
MaxAndArgmax
from
theano.tensor.math
import
MaxAndArgmax
from
theano.tensor.nnet
import
b
n
,
conv3d2d
from
theano.tensor.nnet
import
b
atchnorm
,
conv3d2d
from
theano.tensor.nnet.abstract_conv
import
(
from
theano.tensor.nnet.abstract_conv
import
(
AbstractConv2d
,
AbstractConv2d
,
AbstractConv2d_gradInputs
,
AbstractConv2d_gradInputs
,
...
@@ -3122,9 +3122,9 @@ register_opt("fast_compile")(abstract_batch_norm_groupopt)
...
@@ -3122,9 +3122,9 @@ register_opt("fast_compile")(abstract_batch_norm_groupopt)
register_opt
(
"fast_compile"
,
name
=
"abstract_batch_norm_db"
)(
abstract_batch_norm_db
)
register_opt
(
"fast_compile"
,
name
=
"abstract_batch_norm_db"
)(
abstract_batch_norm_db
)
register_opt2
(
register_opt2
(
[
[
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
],
],
"fast_compile"
,
"fast_compile"
,
name
=
"abstract_batch_norm_db2"
,
name
=
"abstract_batch_norm_db2"
,
...
@@ -3132,19 +3132,19 @@ register_opt2(
...
@@ -3132,19 +3132,19 @@ register_opt2(
for
op
,
fct
,
cpu
in
[
for
op
,
fct
,
cpu
in
[
(
(
b
n
.
AbstractBatchNormTrain
,
b
atchnorm
.
AbstractBatchNormTrain
,
local_abstract_batch_norm_train_cudnn
,
local_abstract_batch_norm_train_cudnn
,
b
n
.
local_abstract_batch_norm_train
,
b
atchnorm
.
local_abstract_batch_norm_train
,
),
),
(
(
b
n
.
AbstractBatchNormTrainGrad
,
b
atchnorm
.
AbstractBatchNormTrainGrad
,
local_abstract_batch_norm_train_grad_cudnn
,
local_abstract_batch_norm_train_grad_cudnn
,
b
n
.
local_abstract_batch_norm_train_grad
,
b
atchnorm
.
local_abstract_batch_norm_train_grad
,
),
),
(
(
b
n
.
AbstractBatchNormInference
,
b
atchnorm
.
AbstractBatchNormInference
,
local_abstract_batch_norm_inference_cudnn
,
local_abstract_batch_norm_inference_cudnn
,
b
n
.
local_abstract_batch_norm_inference
,
b
atchnorm
.
local_abstract_batch_norm_inference
,
),
),
]:
]:
lifter
=
op_lifter
([
op
])(
fct
)
lifter
=
op_lifter
([
op
])(
fct
)
...
...
theano/tensor/nnet/__init__.py
浏览文件 @
8a23fb1c
...
@@ -40,7 +40,7 @@ from theano.tensor.nnet.basic import (
...
@@ -40,7 +40,7 @@ from theano.tensor.nnet.basic import (
softmax_with_bias
,
softmax_with_bias
,
softsign
,
softsign
,
)
)
from
theano.tensor.nnet.b
n
import
batch_normalization
from
theano.tensor.nnet.b
atchnorm
import
batch_normalization
from
theano.tensor.nnet.sigm
import
(
from
theano.tensor.nnet.sigm
import
(
hard_sigmoid
,
hard_sigmoid
,
scalar_sigmoid
,
scalar_sigmoid
,
...
...
theano/tensor/nnet/b
n
.py
→
theano/tensor/nnet/b
atchnorm
.py
浏览文件 @
8a23fb1c
File moved
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论