Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e103e7fb
提交
e103e7fb
authored
10月 19, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace theano.tensor alias T with tt in tests.tensor.nnet
上级
daacd069
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
112 行增加
和
108 行删除
+112
-108
speed_test_conv.py
tests/tensor/nnet/speed_test_conv.py
+7
-7
test_bn.py
tests/tensor/nnet/test_bn.py
+44
-42
test_conv.py
tests/tensor/nnet/test_conv.py
+17
-19
test_corr.py
tests/tensor/nnet/test_corr.py
+20
-20
test_corr3d.py
tests/tensor/nnet/test_corr3d.py
+22
-18
test_ctc.py
tests/tensor/nnet/test_ctc.py
+2
-2
test_neighbours.py
tests/tensor/nnet/test_neighbours.py
+0
-0
test_nnet.py
tests/tensor/nnet/test_nnet.py
+0
-0
test_sigm.py
tests/tensor/nnet/test_sigm.py
+0
-0
没有找到文件。
tests/tensor/nnet/speed_test_conv.py
浏览文件 @
e103e7fb
...
@@ -2,7 +2,7 @@ import time
...
@@ -2,7 +2,7 @@ import time
import
numpy
as
N
import
numpy
as
N
import
theano.tensor
as
T
import
theano.tensor
as
tt
from
theano
import
function
,
Mode
from
theano
import
function
,
Mode
from
theano.tensor.nnet.conv
import
ConvOp
from
theano.tensor.nnet.conv
import
ConvOp
...
@@ -39,7 +39,7 @@ def flip(kern, kshp):
...
@@ -39,7 +39,7 @@ def flip(kern, kshp):
global_rng
=
N
.
random
.
RandomState
(
3423489
)
global_rng
=
N
.
random
.
RandomState
(
3423489
)
dmatrix4
=
T
.
TensorType
(
"float64"
,
(
False
,
False
,
False
,
False
))
dmatrix4
=
tt
.
TensorType
(
"float64"
,
(
False
,
False
,
False
,
False
))
def
exec_multilayer_conv_nnet_old
(
def
exec_multilayer_conv_nnet_old
(
...
@@ -51,7 +51,7 @@ def exec_multilayer_conv_nnet_old(
...
@@ -51,7 +51,7 @@ def exec_multilayer_conv_nnet_old(
nkerns
,
nkerns
,
unroll_batch
=
0
,
unroll_batch
=
0
,
unroll_kern
=
0
,
unroll_kern
=
0
,
img
=
T
.
dmatrix
(),
img
=
tt
.
dmatrix
(),
validate
=
True
,
validate
=
True
,
conv_op_py
=
False
,
conv_op_py
=
False
,
do_print
=
True
,
do_print
=
True
,
...
@@ -64,7 +64,7 @@ def exec_multilayer_conv_nnet_old(
...
@@ -64,7 +64,7 @@ def exec_multilayer_conv_nnet_old(
# build actual input images
# build actual input images
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
a
=
T
.
dmatrix
()
a
=
tt
.
dmatrix
()
kerns
=
[
a
for
i
in
nkerns
]
kerns
=
[
a
for
i
in
nkerns
]
inputs4
=
dmatrix4
()
inputs4
=
dmatrix4
()
kerns4
=
dmatrix4
()
kerns4
=
dmatrix4
()
...
@@ -180,7 +180,7 @@ def exec_multilayer_conv_nnet(
...
@@ -180,7 +180,7 @@ def exec_multilayer_conv_nnet(
nkerns
,
nkerns
,
unroll_batch
=
0
,
unroll_batch
=
0
,
unroll_kern
=
0
,
unroll_kern
=
0
,
img
=
T
.
dmatrix
(),
img
=
tt
.
dmatrix
(),
do_print
=
True
,
do_print
=
True
,
repeat
=
1
,
repeat
=
1
,
unroll_patch
=
False
,
unroll_patch
=
False
,
...
@@ -191,7 +191,7 @@ def exec_multilayer_conv_nnet(
...
@@ -191,7 +191,7 @@ def exec_multilayer_conv_nnet(
# build actual input images
# build actual input images
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
a
=
T
.
dmatrix
()
a
=
tt
.
dmatrix
()
kerns
=
[
a
for
i
in
nkerns
]
kerns
=
[
a
for
i
in
nkerns
]
inputs4
=
dmatrix4
()
inputs4
=
dmatrix4
()
kerns4
=
dmatrix4
()
kerns4
=
dmatrix4
()
...
@@ -277,7 +277,7 @@ def speed_multilayer_conv():
...
@@ -277,7 +277,7 @@ def speed_multilayer_conv():
]
# (1,1)]#(2,2) bugged
]
# (1,1)]#(2,2) bugged
convmodes
=
[
"valid"
,
"full"
]
convmodes
=
[
"valid"
,
"full"
]
# do_convolve2 = False
# do_convolve2 = False
a
=
T
.
dmatrix
()
a
=
tt
.
dmatrix
()
kerns
=
[
a
for
i
in
nkerns
]
kerns
=
[
a
for
i
in
nkerns
]
assert
len
(
kshps
)
==
len
(
nkerns
)
==
len
(
kerns
)
assert
len
(
kshps
)
==
len
(
nkerns
)
==
len
(
kerns
)
...
...
tests/tensor/nnet/test_bn.py
浏览文件 @
e103e7fb
...
@@ -3,7 +3,7 @@ import pytest
...
@@ -3,7 +3,7 @@ import pytest
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
tt
from
collections
import
OrderedDict
from
collections
import
OrderedDict
...
@@ -29,11 +29,11 @@ def test_BNComposite():
...
@@ -29,11 +29,11 @@ def test_BNComposite():
M
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
M
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
x
=
t
heano
.
tensor
.
matrix
(
"x"
)
x
=
t
t
.
matrix
(
"x"
)
b
=
t
heano
.
tensor
.
vector
(
"b"
)
b
=
t
t
.
vector
(
"b"
)
g
=
t
heano
.
tensor
.
vector
(
"g"
)
g
=
t
t
.
vector
(
"g"
)
m
=
t
heano
.
tensor
.
vector
(
"m"
)
m
=
t
t
.
vector
(
"m"
)
v
=
t
heano
.
tensor
.
vector
(
"v"
)
v
=
t
t
.
vector
(
"v"
)
x
.
tag
.
test_value
=
np
.
random
.
rand
(
2
,
2
)
.
astype
(
theano
.
config
.
floatX
)
x
.
tag
.
test_value
=
np
.
random
.
rand
(
2
,
2
)
.
astype
(
theano
.
config
.
floatX
)
b
.
tag
.
test_value
=
np
.
random
.
rand
(
2
)
.
astype
(
theano
.
config
.
floatX
)
b
.
tag
.
test_value
=
np
.
random
.
rand
(
2
)
.
astype
(
theano
.
config
.
floatX
)
...
@@ -65,11 +65,11 @@ def test_batch_normalization():
...
@@ -65,11 +65,11 @@ def test_batch_normalization():
M
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
M
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
20
])
.
astype
(
"float32"
)
x
=
t
heano
.
tensor
.
matrix
(
"x"
)
x
=
t
t
.
matrix
(
"x"
)
b
=
t
heano
.
tensor
.
vector
(
"b"
)
b
=
t
t
.
vector
(
"b"
)
g
=
t
heano
.
tensor
.
vector
(
"g"
)
g
=
t
t
.
vector
(
"g"
)
m
=
t
heano
.
tensor
.
vector
(
"m"
)
m
=
t
t
.
vector
(
"m"
)
v
=
t
heano
.
tensor
.
vector
(
"v"
)
v
=
t
t
.
vector
(
"v"
)
bn_ref_op
=
bn_ref
(
x
,
g
,
b
,
m
,
v
)
bn_ref_op
=
bn_ref
(
x
,
g
,
b
,
m
,
v
)
f_ref
=
theano
.
function
([
x
,
g
,
b
,
m
,
v
],
[
bn_ref_op
])
f_ref
=
theano
.
function
([
x
,
g
,
b
,
m
,
v
],
[
bn_ref_op
])
...
@@ -123,11 +123,11 @@ def test_bn_feature_maps():
...
@@ -123,11 +123,11 @@ def test_bn_feature_maps():
M
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
M
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
V
=
1
+
np
.
random
.
random
([
3
])
.
astype
(
"float32"
)
x
=
t
heano
.
tensor
.
tensor4
(
"x"
)
x
=
t
t
.
tensor4
(
"x"
)
b
=
t
heano
.
tensor
.
vector
(
"b"
)
b
=
t
t
.
vector
(
"b"
)
g
=
t
heano
.
tensor
.
vector
(
"g"
)
g
=
t
t
.
vector
(
"g"
)
m
=
t
heano
.
tensor
.
vector
(
"m"
)
m
=
t
t
.
vector
(
"m"
)
v
=
t
heano
.
tensor
.
vector
(
"v"
)
v
=
t
t
.
vector
(
"v"
)
bn_ref_op
=
bn_ref
(
bn_ref_op
=
bn_ref
(
x
,
x
,
...
@@ -170,7 +170,7 @@ def test_batch_normalization_train():
...
@@ -170,7 +170,7 @@ def test_batch_normalization_train():
utt
.
seed_rng
()
utt
.
seed_rng
()
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
vartype
in
(
T
.
tensor5
,
T
.
tensor3
,
T
.
vector
):
for
vartype
in
(
tt
.
tensor5
,
tt
.
tensor3
,
tt
.
vector
):
x
,
scale
,
bias
,
running_mean
,
running_var
=
(
x
,
scale
,
bias
,
running_mean
,
running_var
=
(
vartype
(
n
)
vartype
(
n
)
for
n
in
(
"x"
,
"scale"
,
"bias"
,
"running_mean"
,
"running_var"
)
for
n
in
(
"x"
,
"scale"
,
"bias"
,
"running_mean"
,
"running_var"
)
...
@@ -211,11 +211,11 @@ def test_batch_normalization_train():
...
@@ -211,11 +211,11 @@ def test_batch_normalization_train():
axes2
=
axes
axes2
=
axes
x_mean2
=
x
.
mean
(
axis
=
axes2
,
keepdims
=
True
)
x_mean2
=
x
.
mean
(
axis
=
axes2
,
keepdims
=
True
)
x_var2
=
x
.
var
(
axis
=
axes2
,
keepdims
=
True
)
x_var2
=
x
.
var
(
axis
=
axes2
,
keepdims
=
True
)
x_invstd2
=
T
.
inv
(
T
.
sqrt
(
x_var2
+
eps
))
x_invstd2
=
tt
.
inv
(
tt
.
sqrt
(
x_var2
+
eps
))
scale2
=
T
.
addbroadcast
(
scale
,
*
axes2
)
scale2
=
tt
.
addbroadcast
(
scale
,
*
axes2
)
bias2
=
T
.
addbroadcast
(
bias
,
*
axes2
)
bias2
=
tt
.
addbroadcast
(
bias
,
*
axes2
)
out2
=
(
x
-
x_mean2
)
*
(
scale2
*
x_invstd2
)
+
bias2
out2
=
(
x
-
x_mean2
)
*
(
scale2
*
x_invstd2
)
+
bias2
m
=
T
.
cast
(
T
.
prod
(
x
.
shape
)
/
T
.
prod
(
scale
.
shape
),
theano
.
config
.
floatX
)
m
=
tt
.
cast
(
tt
.
prod
(
x
.
shape
)
/
tt
.
prod
(
scale
.
shape
),
theano
.
config
.
floatX
)
out_running_mean2
=
(
out_running_mean2
=
(
running_mean
*
(
1
-
running_average_factor
)
running_mean
*
(
1
-
running_average_factor
)
+
x_mean2
*
running_average_factor
+
x_mean2
*
running_average_factor
...
@@ -226,14 +226,14 @@ def test_batch_normalization_train():
...
@@ -226,14 +226,14 @@ def test_batch_normalization_train():
)
)
# backward pass
# backward pass
dy
=
vartype
(
"dy"
)
dy
=
vartype
(
"dy"
)
grads
=
T
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out
:
dy
})
grads
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out
:
dy
})
# reference backward pass
# reference backward pass
grads2
=
T
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out2
:
dy
})
grads2
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out2
:
dy
})
# second-order backward pass
# second-order backward pass
dx
=
vartype
(
"dinputs"
)
dx
=
vartype
(
"dinputs"
)
dscale
=
vartype
(
"dscale"
)
dscale
=
vartype
(
"dscale"
)
dbias
=
vartype
(
"dbias"
)
dbias
=
vartype
(
"dbias"
)
grad_grads
=
T
.
grad
(
grad_grads
=
tt
.
grad
(
None
,
None
,
wrt
=
[
x
,
dy
,
scale
],
wrt
=
[
x
,
dy
,
scale
],
known_grads
=
OrderedDict
(
known_grads
=
OrderedDict
(
...
@@ -252,7 +252,7 @@ def test_batch_normalization_train():
...
@@ -252,7 +252,7 @@ def test_batch_normalization_train():
return_disconnected
=
"zero"
,
return_disconnected
=
"zero"
,
)
)
# reference second-order backward pass
# reference second-order backward pass
grad_grads2
=
T
.
grad
(
grad_grads2
=
tt
.
grad
(
None
,
None
,
wrt
=
[
x
,
dy
,
scale
],
wrt
=
[
x
,
dy
,
scale
],
known_grads
=
OrderedDict
(
known_grads
=
OrderedDict
(
...
@@ -354,7 +354,7 @@ def test_batch_normalization_train_grad_grad():
...
@@ -354,7 +354,7 @@ def test_batch_normalization_train_grad_grad():
utt
.
seed_rng
()
utt
.
seed_rng
()
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
vartype
in
(
T
.
tensor5
,
T
.
tensor4
,
T
.
tensor3
,
T
.
matrix
,
T
.
vector
):
for
vartype
in
(
tt
.
tensor5
,
tt
.
tensor4
,
tt
.
tensor3
,
tt
.
matrix
,
tt
.
vector
):
# run these experiments with float64 for sufficient numerical stability
# run these experiments with float64 for sufficient numerical stability
x
,
dy
,
scale
,
x_mean
,
x_invstd
=
(
x
,
dy
,
scale
,
x_mean
,
x_invstd
=
(
vartype
(
n
,
dtype
=
"float64"
)
vartype
(
n
,
dtype
=
"float64"
)
...
@@ -425,10 +425,10 @@ def test_batch_normalization_train_without_running_averages():
...
@@ -425,10 +425,10 @@ def test_batch_normalization_train_without_running_averages():
utt
.
seed_rng
()
utt
.
seed_rng
()
x
,
scale
,
bias
,
dy
=
(
x
,
scale
,
bias
,
dy
=
(
T
.
tensor4
(
"x"
),
tt
.
tensor4
(
"x"
),
T
.
tensor4
(
"scale"
),
tt
.
tensor4
(
"scale"
),
T
.
tensor4
(
"bias"
),
tt
.
tensor4
(
"bias"
),
T
.
tensor4
(
"dy"
),
tt
.
tensor4
(
"dy"
),
)
)
data_shape
=
(
5
,
10
,
30
,
25
)
data_shape
=
(
5
,
10
,
30
,
25
)
param_shape
=
(
1
,
10
,
30
,
25
)
param_shape
=
(
1
,
10
,
30
,
25
)
...
@@ -438,7 +438,7 @@ def test_batch_normalization_train_without_running_averages():
...
@@ -438,7 +438,7 @@ def test_batch_normalization_train_without_running_averages():
x
,
scale
,
bias
,
"per-activation"
x
,
scale
,
bias
,
"per-activation"
)
)
# backward pass
# backward pass
grads
=
T
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out
:
dy
})
grads
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
],
known_grads
=
{
out
:
dy
})
# compile
# compile
f
=
theano
.
function
([
x
,
scale
,
bias
,
dy
],
[
out
,
x_mean
,
x_invstd
]
+
grads
)
f
=
theano
.
function
([
x
,
scale
,
bias
,
dy
],
[
out
,
x_mean
,
x_invstd
]
+
grads
)
# check if the abstract Ops have been replaced
# check if the abstract Ops have been replaced
...
@@ -465,7 +465,7 @@ def test_batch_normalization_train_without_running_averages():
...
@@ -465,7 +465,7 @@ def test_batch_normalization_train_without_running_averages():
def
test_batch_normalization_train_broadcast
():
def
test_batch_normalization_train_broadcast
():
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
vartype
in
(
T
.
tensor5
,
T
.
tensor4
,
T
.
tensor3
,
T
.
matrix
,
T
.
vector
):
for
vartype
in
(
tt
.
tensor5
,
tt
.
tensor4
,
tt
.
tensor3
,
tt
.
matrix
,
tt
.
vector
):
x
=
vartype
(
"x"
)
x
=
vartype
(
"x"
)
ndim
=
x
.
ndim
ndim
=
x
.
ndim
eps
=
5e-3
# some non-standard value to test if it's used
eps
=
5e-3
# some non-standard value to test if it's used
...
@@ -492,7 +492,7 @@ def test_batch_normalization_train_broadcast():
...
@@ -492,7 +492,7 @@ def test_batch_normalization_train_broadcast():
params_dimshuffle
[
axis
]
=
i
params_dimshuffle
[
axis
]
=
i
# construct non-broadcasted parameter variables
# construct non-broadcasted parameter variables
param_type
=
T
.
TensorType
(
x
.
dtype
,
(
False
,)
*
len
(
non_bc_axes
))
param_type
=
tt
.
TensorType
(
x
.
dtype
,
(
False
,)
*
len
(
non_bc_axes
))
scale
,
bias
,
running_mean
,
running_var
=
(
scale
,
bias
,
running_mean
,
running_var
=
(
param_type
(
n
)
for
n
in
(
"scale"
,
"bias"
,
"running_mean"
,
"running_var"
)
param_type
(
n
)
for
n
in
(
"scale"
,
"bias"
,
"running_mean"
,
"running_var"
)
)
)
...
@@ -545,7 +545,7 @@ def test_batch_normalization_train_broadcast():
...
@@ -545,7 +545,7 @@ def test_batch_normalization_train_broadcast():
# compile to compute all differences
# compile to compute all differences
f
=
theano
.
function
(
f
=
theano
.
function
(
[
x
,
scale
,
bias
,
running_mean
,
running_var
],
T
.
sum
(
sum
(
results
))
[
x
,
scale
,
bias
,
running_mean
,
running_var
],
tt
.
sum
(
sum
(
results
))
)
)
# the paired ops are exactly the same, so the optimizer should have
# the paired ops are exactly the same, so the optimizer should have
...
@@ -570,7 +570,7 @@ def test_batch_normalization_train_broadcast():
...
@@ -570,7 +570,7 @@ def test_batch_normalization_train_broadcast():
@pytest.mark.slow
@pytest.mark.slow
def
test_batch_normalization_test
():
def
test_batch_normalization_test
():
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
axes
in
(
"per-activation"
,
"spatial"
,
(
1
,
2
,
3
,
4
)):
for
vartype
in
(
T
.
tensor5
,
T
.
tensor3
,
T
.
vector
):
for
vartype
in
(
tt
.
tensor5
,
tt
.
tensor3
,
tt
.
vector
):
x
,
scale
,
bias
,
mean
,
var
=
(
x
,
scale
,
bias
,
mean
,
var
=
(
vartype
(
n
)
for
n
in
(
"x"
,
"scale"
,
"bias"
,
"mean"
,
"var"
)
vartype
(
n
)
for
n
in
(
"x"
,
"scale"
,
"bias"
,
"mean"
,
"var"
)
)
)
...
@@ -593,14 +593,16 @@ def test_batch_normalization_test():
...
@@ -593,14 +593,16 @@ def test_batch_normalization_test():
else
:
else
:
axes2
=
axes
axes2
=
axes
scale2
,
bias2
,
mean2
,
var2
=
(
scale2
,
bias2
,
mean2
,
var2
=
(
T
.
addbroadcast
(
t
,
*
axes2
)
for
t
in
(
scale
,
bias
,
mean
,
var
)
tt
.
addbroadcast
(
t
,
*
axes2
)
for
t
in
(
scale
,
bias
,
mean
,
var
)
)
)
out2
=
(
x
-
mean2
)
*
(
scale2
/
T
.
sqrt
(
var2
+
eps
))
+
bias2
out2
=
(
x
-
mean2
)
*
(
scale2
/
tt
.
sqrt
(
var2
+
eps
))
+
bias2
# backward pass
# backward pass
dy
=
vartype
(
"dy"
)
dy
=
vartype
(
"dy"
)
grads
=
T
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
,
mean
,
var
],
known_grads
=
{
out
:
dy
})
grads
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
,
mean
,
var
],
known_grads
=
{
out
:
dy
}
)
# reference backward pass
# reference backward pass
grads2
=
T
.
grad
(
grads2
=
tt
.
grad
(
None
,
wrt
=
[
x
,
scale
,
bias
,
mean
,
var
],
known_grads
=
{
out2
:
dy
}
None
,
wrt
=
[
x
,
scale
,
bias
,
mean
,
var
],
known_grads
=
{
out2
:
dy
}
)
)
# compile
# compile
...
@@ -649,7 +651,7 @@ def test_batch_normalization_test():
...
@@ -649,7 +651,7 @@ def test_batch_normalization_test():
def
test_batch_normalization_broadcastable
():
def
test_batch_normalization_broadcastable
():
# check if the broadcastable pattern is preserved by the optimizations
# check if the broadcastable pattern is preserved by the optimizations
x
,
dy
,
scale
,
bias
,
mean
,
var
=
(
x
,
dy
,
scale
,
bias
,
mean
,
var
=
(
T
.
scalar
(
n
)
.
dimshuffle
([
"x"
]
*
5
)
tt
.
scalar
(
n
)
.
dimshuffle
([
"x"
]
*
5
)
for
n
in
(
"x"
,
"dy"
,
"scale"
,
"bias"
,
"mean"
,
"var"
)
for
n
in
(
"x"
,
"dy"
,
"scale"
,
"bias"
,
"mean"
,
"var"
)
)
)
...
@@ -659,8 +661,8 @@ def test_batch_normalization_broadcastable():
...
@@ -659,8 +661,8 @@ def test_batch_normalization_broadcastable():
)
)
out_test
=
bn
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
"spatial"
)
out_test
=
bn
.
batch_normalization_test
(
x
,
scale
,
bias
,
mean
,
var
,
"spatial"
)
# backward pass
# backward pass
grads_train
=
T
.
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
=
T
.
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
})
# compile
# compile
f
=
theano
.
function
(
f
=
theano
.
function
(
[
x
,
scale
,
bias
,
mean
,
var
,
dy
],
[
x
,
scale
,
bias
,
mean
,
var
,
dy
],
...
...
tests/tensor/nnet/test_conv.py
浏览文件 @
e103e7fb
...
@@ -5,9 +5,9 @@ import pytest
...
@@ -5,9 +5,9 @@ import pytest
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
tt
from
theano.tensor.nnet
import
conv
from
theano.tensor.nnet
import
conv
,
conv2d
from
theano.tensor.basic
import
_allclose
,
NotScalarConstantError
from
theano.tensor.basic
import
_allclose
,
NotScalarConstantError
from
tests
import
unittest_tools
as
utt
from
tests
import
unittest_tools
as
utt
...
@@ -28,9 +28,9 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -28,9 +28,9 @@ class TestConv2D(utt.InferShapeTester):
conv2d
=
staticmethod
(
conv
.
conv2d
)
conv2d
=
staticmethod
(
conv
.
conv2d
)
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
input
=
T
.
tensor4
(
"input"
,
dtype
=
self
.
dtype
)
self
.
input
=
tt
.
tensor4
(
"input"
,
dtype
=
self
.
dtype
)
self
.
input
.
name
=
"default_V"
self
.
input
.
name
=
"default_V"
self
.
filters
=
T
.
tensor4
(
"filters"
,
dtype
=
self
.
dtype
)
self
.
filters
=
tt
.
tensor4
(
"filters"
,
dtype
=
self
.
dtype
)
self
.
filters
.
name
=
"default_filters"
self
.
filters
.
name
=
"default_filters"
super
()
.
setup_method
()
super
()
.
setup_method
()
...
@@ -64,12 +64,12 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -64,12 +64,12 @@ class TestConv2D(utt.InferShapeTester):
"""
"""
if
N_image_shape
is
None
:
if
N_image_shape
is
None
:
N_image_shape
=
[
N_image_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
tt
.
get_scalar_constant_value
(
tt
.
as_tensor_variable
(
x
))
for
x
in
image_shape
for
x
in
image_shape
]
]
if
N_filter_shape
is
None
:
if
N_filter_shape
is
None
:
N_filter_shape
=
[
N_filter_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
tt
.
get_scalar_constant_value
(
tt
.
as_tensor_variable
(
x
))
for
x
in
filter_shape
for
x
in
filter_shape
]
]
...
@@ -391,7 +391,7 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -391,7 +391,7 @@ class TestConv2D(utt.InferShapeTester):
def
test_shape_Constant_tensor
(
self
):
def
test_shape_Constant_tensor
(
self
):
# Tests convolution where the {image,filter}_shape is a Constant tensor.
# Tests convolution where the {image,filter}_shape is a Constant tensor.
as_t
=
T
.
as_tensor_variable
as_t
=
tt
.
as_tensor_variable
self
.
validate
((
as_t
(
3
),
as_t
(
2
),
as_t
(
7
),
as_t
(
5
)),
(
5
,
2
,
2
,
3
),
"valid"
)
self
.
validate
((
as_t
(
3
),
as_t
(
2
),
as_t
(
7
),
as_t
(
5
)),
(
5
,
2
,
2
,
3
),
"valid"
)
self
.
validate
(
as_t
([
3
,
2
,
7
,
5
]),
(
5
,
2
,
2
,
3
),
"valid"
)
self
.
validate
(
as_t
([
3
,
2
,
7
,
5
]),
(
5
,
2
,
2
,
3
),
"valid"
)
self
.
validate
(
as_t
((
3
,
2
,
7
,
5
)),
(
5
,
2
,
2
,
3
),
"valid"
)
self
.
validate
(
as_t
((
3
,
2
,
7
,
5
)),
(
5
,
2
,
2
,
3
),
"valid"
)
...
@@ -563,11 +563,11 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -563,11 +563,11 @@ class TestConv2D(utt.InferShapeTester):
# Make sure errors are raised when image and kernel are not 4D tensors
# Make sure errors are raised when image and kernel are not 4D tensors
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
T
.
dmatrix
())
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
tt
.
dmatrix
())
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
filters
=
T
.
dvector
())
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
filters
=
tt
.
dvector
())
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
T
.
dtensor3
())
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
tt
.
dtensor3
())
def
test_gcc_crash
(
self
):
def
test_gcc_crash
(
self
):
# gcc 4.3.0 20080428 (Red Hat 4.3.0-8)
# gcc 4.3.0 20080428 (Red Hat 4.3.0-8)
...
@@ -629,8 +629,8 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -629,8 +629,8 @@ class TestConv2D(utt.InferShapeTester):
r
=
np
.
asarray
(
np
.
random
.
rand
(
*
shape
),
dtype
=
"float64"
)
r
=
np
.
asarray
(
np
.
random
.
rand
(
*
shape
),
dtype
=
"float64"
)
return
r
*
2
-
1
return
r
*
2
-
1
adtens
=
T
.
dtensor4
()
adtens
=
tt
.
dtensor4
()
bdtens
=
T
.
dtensor4
()
bdtens
=
tt
.
dtensor4
()
aivec_val
=
[
4
,
5
,
6
,
3
]
aivec_val
=
[
4
,
5
,
6
,
3
]
bivec_val
=
[
7
,
5
,
3
,
2
]
bivec_val
=
[
7
,
5
,
3
,
2
]
adtens_val
=
rand
(
*
aivec_val
)
adtens_val
=
rand
(
*
aivec_val
)
...
@@ -737,20 +737,18 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -737,20 +737,18 @@ class TestConv2D(utt.InferShapeTester):
# code from that ticket.
# code from that ticket.
def
test_broadcast_grad
():
def
test_broadcast_grad
():
# rng = numpy.random.RandomState(utt.fetch_seed())
# rng = numpy.random.RandomState(utt.fetch_seed())
x1
=
T
.
tensor4
(
"x"
)
x1
=
tt
.
tensor4
(
"x"
)
# x1_data = rng.randn(1, 1, 300, 300)
# x1_data = rng.randn(1, 1, 300, 300)
sigma
=
T
.
scalar
(
"sigma"
)
sigma
=
tt
.
scalar
(
"sigma"
)
# sigma_data = 20
# sigma_data = 20
window_radius
=
3
window_radius
=
3
filter_1d
=
T
.
arange
(
-
window_radius
,
window_radius
+
1
)
filter_1d
=
tt
.
arange
(
-
window_radius
,
window_radius
+
1
)
filter_1d
=
filter_1d
.
astype
(
theano
.
config
.
floatX
)
filter_1d
=
filter_1d
.
astype
(
theano
.
config
.
floatX
)
filter_1d
=
T
.
exp
(
-
0.5
*
filter_1d
**
2
/
sigma
**
2
)
filter_1d
=
tt
.
exp
(
-
0.5
*
filter_1d
**
2
/
sigma
**
2
)
filter_1d
=
filter_1d
/
filter_1d
.
sum
()
filter_1d
=
filter_1d
/
filter_1d
.
sum
()
filter_W
=
filter_1d
.
dimshuffle
([
"x"
,
"x"
,
0
,
"x"
])
filter_W
=
filter_1d
.
dimshuffle
([
"x"
,
"x"
,
0
,
"x"
])
y
=
theano
.
tensor
.
nnet
.
conv2d
(
y
=
conv2d
(
x1
,
filter_W
,
border_mode
=
"full"
,
filter_shape
=
[
1
,
1
,
None
,
None
])
x1
,
filter_W
,
border_mode
=
"full"
,
filter_shape
=
[
1
,
1
,
None
,
None
]
)
theano
.
grad
(
y
.
sum
(),
sigma
)
theano
.
grad
(
y
.
sum
(),
sigma
)
tests/tensor/nnet/test_corr.py
浏览文件 @
e103e7fb
import
pytest
import
pytest
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
tt
from
six
import
integer_types
from
six
import
integer_types
from
theano.tensor.nnet
import
corr
,
conv
from
theano.tensor.nnet
import
corr
,
conv
...
@@ -29,9 +29,9 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -29,9 +29,9 @@ class TestCorr2D(utt.InferShapeTester):
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
input
=
T
.
tensor4
(
"input"
,
dtype
=
self
.
dtype
)
self
.
input
=
tt
.
tensor4
(
"input"
,
dtype
=
self
.
dtype
)
self
.
input
.
name
=
"default_V"
self
.
input
.
name
=
"default_V"
self
.
filters
=
T
.
tensor4
(
"filters"
,
dtype
=
self
.
dtype
)
self
.
filters
=
tt
.
tensor4
(
"filters"
,
dtype
=
self
.
dtype
)
self
.
filters
.
name
=
"default_filters"
self
.
filters
.
name
=
"default_filters"
# This tests can run even when theano.config.blas.ldflags is empty.
# This tests can run even when theano.config.blas.ldflags is empty.
super
()
.
setup_method
()
super
()
.
setup_method
()
...
@@ -55,10 +55,10 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -55,10 +55,10 @@ class TestCorr2D(utt.InferShapeTester):
if
not
theano
.
config
.
cxx
:
if
not
theano
.
config
.
cxx
:
pytest
.
skip
(
"Need cxx to test conv2d"
)
pytest
.
skip
(
"Need cxx to test conv2d"
)
N_image_shape
=
[
N_image_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
for
x
in
image_shape
tt
.
get_scalar_constant_value
(
tt
.
as_tensor_variable
(
x
))
for
x
in
image_shape
]
]
N_filter_shape
=
[
N_filter_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
for
x
in
filter_shape
tt
.
get_scalar_constant_value
(
tt
.
as_tensor_variable
(
x
))
for
x
in
filter_shape
]
]
if
input
is
None
:
if
input
is
None
:
...
@@ -255,7 +255,7 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -255,7 +255,7 @@ class TestCorr2D(utt.InferShapeTester):
def
test_shape_Constant_tensor
(
self
):
def
test_shape_Constant_tensor
(
self
):
# Tests correlation where the {image,filter}_shape is a Constant tensor.
# Tests correlation where the {image,filter}_shape is a Constant tensor.
as_t
=
T
.
as_tensor_variable
as_t
=
tt
.
as_tensor_variable
border_modes
=
[
"valid"
,
"full"
,
"half"
,
(
1
,
1
),
(
2
,
1
),
(
1
,
2
),
(
3
,
3
),
1
]
border_modes
=
[
"valid"
,
"full"
,
"half"
,
(
1
,
1
),
(
2
,
1
),
(
1
,
2
),
(
3
,
3
),
1
]
for
border_mode
in
border_modes
:
for
border_mode
in
border_modes
:
...
@@ -290,11 +290,11 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -290,11 +290,11 @@ class TestCorr2D(utt.InferShapeTester):
# Make sure errors are raised when image and kernel are not 4D tensors
# Make sure errors are raised when image and kernel are not 4D tensors
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
T
.
dmatrix
())
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
tt
.
dmatrix
())
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
filters
=
T
.
dvector
())
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
filters
=
tt
.
dvector
())
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
T
.
dtensor3
())
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
"valid"
,
input
=
tt
.
dtensor3
())
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"Need cxx for this test"
)
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"Need cxx for this test"
)
def
test_dtype_upcast
(
self
):
def
test_dtype_upcast
(
self
):
...
@@ -313,8 +313,8 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -313,8 +313,8 @@ class TestCorr2D(utt.InferShapeTester):
for
a_dtype
in
dtypes
:
for
a_dtype
in
dtypes
:
for
b_dtype
in
dtypes
:
for
b_dtype
in
dtypes
:
c_dtype
=
theano
.
scalar
.
upcast
(
a_dtype
,
b_dtype
)
c_dtype
=
theano
.
scalar
.
upcast
(
a_dtype
,
b_dtype
)
a_tens
=
T
.
tensor4
(
dtype
=
a_dtype
)
a_tens
=
tt
.
tensor4
(
dtype
=
a_dtype
)
b_tens
=
T
.
tensor4
(
dtype
=
b_dtype
)
b_tens
=
tt
.
tensor4
(
dtype
=
b_dtype
)
a_tens_val
=
rand
(
a_shape
,
dtype
=
a_dtype
)
a_tens_val
=
rand
(
a_shape
,
dtype
=
a_dtype
)
b_tens_val
=
rand
(
b_shape
,
dtype
=
b_dtype
)
b_tens_val
=
rand
(
b_shape
,
dtype
=
b_dtype
)
...
@@ -334,8 +334,8 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -334,8 +334,8 @@ class TestCorr2D(utt.InferShapeTester):
corrMM
=
corr
.
CorrMM
corrMM
=
corr
.
CorrMM
adtens
=
T
.
dtensor4
()
adtens
=
tt
.
dtensor4
()
bdtens
=
T
.
dtensor4
()
bdtens
=
tt
.
dtensor4
()
aivec_vals
=
[
aivec_vals
=
[
[
4
,
5
,
6
,
3
],
[
4
,
5
,
6
,
3
],
[
6
,
2
,
8
,
3
],
[
6
,
2
,
8
,
3
],
...
@@ -385,8 +385,8 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -385,8 +385,8 @@ class TestCorr2D(utt.InferShapeTester):
corrMM
=
corr
.
CorrMM
corrMM
=
corr
.
CorrMM
gradW
=
corr
.
CorrMM_gradWeights
gradW
=
corr
.
CorrMM_gradWeights
adtens
=
T
.
dtensor4
()
adtens
=
tt
.
dtensor4
()
bdtens
=
T
.
dtensor4
()
bdtens
=
tt
.
dtensor4
()
aivec_vals
=
[
aivec_vals
=
[
[
1
,
5
,
6
,
3
],
[
1
,
5
,
6
,
3
],
[
8
,
2
,
7
,
3
],
[
8
,
2
,
7
,
3
],
...
@@ -441,8 +441,8 @@ class TestCorr2D(utt.InferShapeTester):
...
@@ -441,8 +441,8 @@ class TestCorr2D(utt.InferShapeTester):
corrMM
=
corr
.
CorrMM
corrMM
=
corr
.
CorrMM
gradI
=
corr
.
CorrMM_gradInputs
gradI
=
corr
.
CorrMM_gradInputs
adtens
=
T
.
dtensor4
()
adtens
=
tt
.
dtensor4
()
bdtens
=
T
.
dtensor4
()
bdtens
=
tt
.
dtensor4
()
aivec_vals
=
[
aivec_vals
=
[
[
1
,
5
,
6
,
3
],
[
1
,
5
,
6
,
3
],
[
8
,
2
,
7
,
3
],
[
8
,
2
,
7
,
3
],
...
@@ -510,8 +510,8 @@ class TestGroupCorr2d(TestGroupedConvNoOptim):
...
@@ -510,8 +510,8 @@ class TestGroupCorr2d(TestGroupedConvNoOptim):
groups
=
3
groups
=
3
bottom
=
np
.
random
.
rand
(
3
,
6
,
5
,
5
)
.
astype
(
theano
.
config
.
floatX
)
bottom
=
np
.
random
.
rand
(
3
,
6
,
5
,
5
)
.
astype
(
theano
.
config
.
floatX
)
kern
=
np
.
random
.
rand
(
9
,
2
,
3
,
3
)
.
astype
(
theano
.
config
.
floatX
)
kern
=
np
.
random
.
rand
(
9
,
2
,
3
,
3
)
.
astype
(
theano
.
config
.
floatX
)
bottom_sym
=
T
.
tensor4
(
"bottom"
)
bottom_sym
=
tt
.
tensor4
(
"bottom"
)
kern_sym
=
T
.
tensor4
(
"kern"
)
kern_sym
=
tt
.
tensor4
(
"kern"
)
# grouped convolution graph
# grouped convolution graph
conv_group
=
self
.
conv
(
num_groups
=
groups
)(
bottom_sym
,
kern_sym
)
conv_group
=
self
.
conv
(
num_groups
=
groups
)(
bottom_sym
,
kern_sym
)
...
@@ -527,7 +527,7 @@ class TestGroupCorr2d(TestGroupedConvNoOptim):
...
@@ -527,7 +527,7 @@ class TestGroupCorr2d(TestGroupedConvNoOptim):
)
)
for
i
in
range
(
groups
)
for
i
in
range
(
groups
)
]
]
concatenated_output
=
T
.
concatenate
(
split_conv_output
,
axis
=
1
)
concatenated_output
=
tt
.
concatenate
(
split_conv_output
,
axis
=
1
)
conv_func
=
theano
.
function
(
conv_func
=
theano
.
function
(
[
bottom_sym
,
kern_sym
],
concatenated_output
,
mode
=
self
.
mode
[
bottom_sym
,
kern_sym
],
concatenated_output
,
mode
=
self
.
mode
)
)
...
...
tests/tensor/nnet/test_corr3d.py
浏览文件 @
e103e7fb
import
pytest
import
pytest
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
tt
from
six
import
integer_types
from
six
import
integer_types
...
@@ -23,9 +23,9 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -23,9 +23,9 @@ class TestCorr3D(utt.InferShapeTester):
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
def
setup_method
(
self
):
def
setup_method
(
self
):
self
.
input
=
T
.
tensor5
(
"input"
,
dtype
=
self
.
dtype
)
self
.
input
=
tt
.
tensor5
(
"input"
,
dtype
=
self
.
dtype
)
self
.
input
.
name
=
"default_V"
self
.
input
.
name
=
"default_V"
self
.
filters
=
T
.
tensor5
(
"filters"
,
dtype
=
self
.
dtype
)
self
.
filters
=
tt
.
tensor5
(
"filters"
,
dtype
=
self
.
dtype
)
self
.
filters
.
name
=
"default_filters"
self
.
filters
.
name
=
"default_filters"
# This tests can run even when theano.config.blas.ldflags is empty.
# This tests can run even when theano.config.blas.ldflags is empty.
super
()
.
setup_method
()
super
()
.
setup_method
()
...
@@ -50,10 +50,10 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -50,10 +50,10 @@ class TestCorr3D(utt.InferShapeTester):
pytest
.
skip
(
"Need cxx for this test"
)
pytest
.
skip
(
"Need cxx for this test"
)
N_image_shape
=
[
N_image_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
for
x
in
image_shape
tt
.
get_scalar_constant_value
(
tt
.
as_tensor_variable
(
x
))
for
x
in
image_shape
]
]
N_filter_shape
=
[
N_filter_shape
=
[
T
.
get_scalar_constant_value
(
T
.
as_tensor_variable
(
x
))
for
x
in
filter_shape
tt
.
get_scalar_constant_value
(
tt
.
as_tensor_variable
(
x
))
for
x
in
filter_shape
]
]
if
input
is
None
:
if
input
is
None
:
...
@@ -296,7 +296,7 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -296,7 +296,7 @@ class TestCorr3D(utt.InferShapeTester):
)
)
def
test_shape_Constant_tensor
(
self
,
border_mode
):
def
test_shape_Constant_tensor
(
self
,
border_mode
):
# Tests correlation where the {image,filter}_shape is a Constant tensor
# Tests correlation where the {image,filter}_shape is a Constant tensor
as_t
=
T
.
as_tensor_variable
as_t
=
tt
.
as_tensor_variable
self
.
validate
(
self
.
validate
(
(
as_t
(
3
),
as_t
(
2
),
as_t
(
7
),
as_t
(
5
),
as_t
(
5
)),
(
5
,
2
,
2
,
3
,
3
),
border_mode
(
as_t
(
3
),
as_t
(
2
),
as_t
(
7
),
as_t
(
5
),
as_t
(
5
)),
(
5
,
2
,
2
,
3
,
3
),
border_mode
)
)
...
@@ -327,13 +327,17 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -327,13 +327,17 @@ class TestCorr3D(utt.InferShapeTester):
def
test_wrong_input
(
self
):
def
test_wrong_input
(
self
):
# Make sure errors are raised when image and kernel are not 5D tensors
# Make sure errors are raised when image and kernel are not 5D tensors
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
T
.
dmatrix
())
self
.
validate
((
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
tt
.
dmatrix
())
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
T
.
vector
())
self
.
validate
((
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
tt
.
vector
())
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
T
.
dtensor3
())
self
.
validate
(
(
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
tt
.
dtensor3
()
)
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
self
.
validate
((
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
T
.
dtensor4
())
self
.
validate
(
(
3
,
2
,
8
,
8
,
8
),
(
4
,
2
,
5
,
5
,
5
),
"valid"
,
input
=
tt
.
dtensor4
()
)
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"Need cxx for this test"
)
@pytest.mark.skipif
(
not
theano
.
config
.
cxx
,
reason
=
"Need cxx for this test"
)
def
test_dtype_upcast
(
self
):
def
test_dtype_upcast
(
self
):
...
@@ -352,8 +356,8 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -352,8 +356,8 @@ class TestCorr3D(utt.InferShapeTester):
for
a_dtype
in
dtypes
:
for
a_dtype
in
dtypes
:
for
b_dtype
in
dtypes
:
for
b_dtype
in
dtypes
:
c_dtype
=
theano
.
scalar
.
upcast
(
a_dtype
,
b_dtype
)
c_dtype
=
theano
.
scalar
.
upcast
(
a_dtype
,
b_dtype
)
a_tens
=
T
.
tensor5
(
dtype
=
a_dtype
)
a_tens
=
tt
.
tensor5
(
dtype
=
a_dtype
)
b_tens
=
T
.
tensor5
(
dtype
=
b_dtype
)
b_tens
=
tt
.
tensor5
(
dtype
=
b_dtype
)
a_tens_val
=
rand
(
a_shape
,
dtype
=
a_dtype
)
a_tens_val
=
rand
(
a_shape
,
dtype
=
a_dtype
)
b_tens_val
=
rand
(
b_shape
,
dtype
=
b_dtype
)
b_tens_val
=
rand
(
b_shape
,
dtype
=
b_dtype
)
...
@@ -373,8 +377,8 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -373,8 +377,8 @@ class TestCorr3D(utt.InferShapeTester):
corr3dMM
=
corr3d
.
Corr3dMM
corr3dMM
=
corr3d
.
Corr3dMM
adtens
=
T
.
dtensor5
()
adtens
=
tt
.
dtensor5
()
bdtens
=
T
.
dtensor5
()
bdtens
=
tt
.
dtensor5
()
aivec_vals
=
[
aivec_vals
=
[
[
4
,
5
,
6
,
3
,
3
],
[
4
,
5
,
6
,
3
,
3
],
[
6
,
2
,
8
,
3
,
3
],
[
6
,
2
,
8
,
3
,
3
],
...
@@ -422,8 +426,8 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -422,8 +426,8 @@ class TestCorr3D(utt.InferShapeTester):
corr3dMM
=
corr3d
.
Corr3dMM
corr3dMM
=
corr3d
.
Corr3dMM
gradW
=
corr3d
.
Corr3dMMGradWeights
gradW
=
corr3d
.
Corr3dMMGradWeights
adtens
=
T
.
dtensor5
()
adtens
=
tt
.
dtensor5
()
bdtens
=
T
.
dtensor5
()
bdtens
=
tt
.
dtensor5
()
aivec_vals
=
[
aivec_vals
=
[
[
1
,
5
,
6
,
3
,
3
],
[
1
,
5
,
6
,
3
,
3
],
[
8
,
2
,
7
,
3
,
3
],
[
8
,
2
,
7
,
3
,
3
],
...
@@ -482,8 +486,8 @@ class TestCorr3D(utt.InferShapeTester):
...
@@ -482,8 +486,8 @@ class TestCorr3D(utt.InferShapeTester):
corr3dMM
=
corr3d
.
Corr3dMM
corr3dMM
=
corr3d
.
Corr3dMM
gradI
=
corr3d
.
Corr3dMMGradInputs
gradI
=
corr3d
.
Corr3dMMGradInputs
adtens
=
T
.
dtensor5
()
adtens
=
tt
.
dtensor5
()
bdtens
=
T
.
dtensor5
()
bdtens
=
tt
.
dtensor5
()
aivec_vals
=
[
aivec_vals
=
[
[
1
,
5
,
6
,
3
,
3
],
[
1
,
5
,
6
,
3
,
3
],
[
8
,
2
,
7
,
3
,
3
],
[
8
,
2
,
7
,
3
,
3
],
...
...
tests/tensor/nnet/test_ctc.py
浏览文件 @
e103e7fb
import
pytest
import
pytest
import
numpy
as
np
import
numpy
as
np
import
theano
import
theano
import
theano.tensor
as
T
import
theano.tensor
as
tt
from
theano.tensor.nnet.ctc
import
(
from
theano.tensor.nnet.ctc
import
(
ctc_available
,
ctc_available
,
...
@@ -128,7 +128,7 @@ class TestCTC:
...
@@ -128,7 +128,7 @@ class TestCTC:
t_cost
=
ctc
(
t_activations
,
t_labels
,
t_activation_times
)
t_cost
=
ctc
(
t_activations
,
t_labels
,
t_activation_times
)
# Symbolic gradient of CTC cost
# Symbolic gradient of CTC cost
t_grad
=
T
.
grad
(
T
.
mean
(
t_cost
),
t_activations
)
t_grad
=
tt
.
grad
(
tt
.
mean
(
t_cost
),
t_activations
)
# Compile symbolic functions
# Compile symbolic functions
train
=
theano
.
function
([],
[
t_cost
,
t_grad
])
train
=
theano
.
function
([],
[
t_cost
,
t_grad
])
...
...
tests/tensor/nnet/test_neighbours.py
浏览文件 @
e103e7fb
差异被折叠。
点击展开。
tests/tensor/nnet/test_nnet.py
浏览文件 @
e103e7fb
差异被折叠。
点击展开。
tests/tensor/nnet/test_sigm.py
浏览文件 @
e103e7fb
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论