Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9db32cee
提交
9db32cee
authored
10月 12, 2016
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace Conv3D references in tests with Corr3dMM.
上级
146ef971
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
59 行增加
和
253 行删除
+59
-253
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+9
-67
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+9
-66
test_gemmcorr3d.py
theano/sandbox/cuda/tests/test_gemmcorr3d.py
+30
-111
test_gradient.py
theano/tests/test_gradient.py
+11
-9
没有找到文件。
theano/gpuarray/tests/test_dnn.py
浏览文件 @
9db32cee
...
...
@@ -832,7 +832,6 @@ def test_conv3d_fwd():
inputs
=
theano
.
shared
(
inputs_val
)
filters
=
theano
.
shared
(
filters_val
)
bias
=
theano
.
shared
(
numpy
.
zeros
(
filters_shape
[
0
])
.
astype
(
'float32'
))
# Compile a theano function for the cuDNN implementation
conv
=
dnn
.
dnn_conv3d
(
img
=
inputs
,
kerns
=
filters
,
...
...
@@ -847,33 +846,11 @@ def test_conv3d_fwd():
else
:
flipped_filters
=
filters
# If border mode is anything but 'valid', the reference implementation
# should operate on padded inputs
if
border_mode
==
'valid'
:
padded_inputs
=
inputs
else
:
if
border_mode
==
'full'
:
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
elif
border_mode
==
'half'
:
pad_per_dim
=
[
filters_shape
[
i
]
//
2
for
i
in
range
(
2
,
5
)]
else
:
if
isinstance
(
border_mode
,
int
):
pad_per_dim
=
[
border_mode
]
*
3
else
:
pad_per_dim
=
border_mode
pad_before_after
=
([(
0
,
0
),
(
0
,
0
)]
+
[(
p
,
p
)
for
p
in
pad_per_dim
])
padded_inputs_val
=
numpy
.
pad
(
inputs_val
,
pad_before_after
,
'constant'
)
padded_inputs
=
theano
.
shared
(
padded_inputs_val
)
# Compile a theano function for the reference implementation
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
f_ref
=
theano
.
function
([],
conv_ref
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
),
mode
=
"FAST_RUN"
)
conv_ref
=
theano
.
tensor
.
nnet
.
corr3d
.
Corr3dMM
(
border_mode
=
border_mode
,
subsample
=
subsample
)(
inputs
,
flipped_filters
)
f_ref
=
theano
.
function
([],
conv_ref
,
mode
=
"FAST_RUN"
)
# Compare the results of the two implementations
res_ref
=
f_ref
()
...
...
@@ -899,7 +876,6 @@ def test_conv3d_bwd():
inputs
=
theano
.
shared
(
inputs_val
)
filters
=
theano
.
shared
(
filters_val
)
bias
=
theano
.
shared
(
numpy
.
zeros
(
filters_shape
[
0
])
.
astype
(
'float32'
))
# Compile a theano function for the cuDNN implementation
conv
=
dnn
.
dnn_conv3d
(
img
=
inputs
,
kerns
=
filters
,
...
...
@@ -917,47 +893,13 @@ def test_conv3d_bwd():
else
:
flipped_filters
=
filters
# If border mode is anything but 'valid', the reference implementation
# should operate on padded inputs
if
border_mode
==
'valid'
:
padded_inputs
=
inputs
else
:
if
border_mode
==
'full'
:
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
elif
border_mode
==
'half'
:
pad_per_dim
=
[
filters_shape
[
i
]
//
2
for
i
in
range
(
2
,
5
)]
else
:
if
isinstance
(
border_mode
,
int
):
pad_per_dim
=
[
border_mode
]
*
3
else
:
pad_per_dim
=
border_mode
pad_before_after
=
([(
0
,
0
),
(
0
,
0
)]
+
[(
p
,
p
)
for
p
in
pad_per_dim
])
padded_inputs_val
=
numpy
.
pad
(
inputs_val
,
pad_before_after
,
'constant'
)
padded_inputs
=
theano
.
shared
(
padded_inputs_val
)
# Compile a theano function for the reference implementation
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
(
grad_padded_i_ref
,
conv_ref
=
theano
.
tensor
.
nnet
.
corr3d
.
Corr3dMM
(
border_mode
=
border_mode
,
subsample
=
subsample
)(
inputs
,
flipped_filters
)
(
grad_i_ref
,
grad_w_ref
)
=
theano
.
tensor
.
grad
(
conv_ref
.
sum
(),
[
padded_inputs
,
filters
])
# Recover grad_i_ref from grad_padded_i_ref
if
border_mode
==
'valid'
:
grad_i_ref
=
grad_padded_i_ref
else
:
shp
=
grad_padded_i_ref
.
shape
grad_i_ref
=
grad_padded_i_ref
[
:,
:,
pad_per_dim
[
0
]:
shp
[
2
]
-
pad_per_dim
[
0
],
pad_per_dim
[
1
]:
shp
[
3
]
-
pad_per_dim
[
1
],
pad_per_dim
[
2
]:
shp
[
4
]
-
pad_per_dim
[
2
]]
[
inputs
,
filters
])
f_ref
=
theano
.
function
([],
[
grad_i_ref
,
grad_w_ref
],
mode
=
"FAST_RUN"
)
# Compare the results of the two implementations
...
...
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
9db32cee
...
...
@@ -1551,7 +1551,6 @@ def test_conv3d_fwd():
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
bias
=
shared
(
numpy
.
zeros
(
filters_shape
[
0
])
.
astype
(
'float32'
))
# Compile a theano function for the cuDNN implementation
conv
=
dnn
.
dnn_conv3d
(
img
=
inputs
,
kerns
=
filters
,
...
...
@@ -1566,33 +1565,11 @@ def test_conv3d_fwd():
else
:
flipped_filters
=
filters
# If border mode is anything but 'valid', the reference implementation
# should operate on padded inputs
if
border_mode
==
'valid'
:
padded_inputs
=
inputs
else
:
if
border_mode
==
'full'
:
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
elif
border_mode
==
'half'
:
pad_per_dim
=
[
filters_shape
[
i
]
//
2
for
i
in
range
(
2
,
5
)]
else
:
if
isinstance
(
border_mode
,
int
):
pad_per_dim
=
[
border_mode
]
*
3
else
:
pad_per_dim
=
border_mode
pad_before_after
=
([(
0
,
0
),
(
0
,
0
)]
+
[(
p
,
p
)
for
p
in
pad_per_dim
])
padded_inputs_val
=
numpy
.
pad
(
inputs_val
,
pad_before_after
,
'constant'
)
padded_inputs
=
shared
(
padded_inputs_val
)
# Compile a theano function for the reference implementation
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
f_ref
=
theano
.
function
([],
conv_ref
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
),
mode
=
"FAST_RUN"
)
conv_ref
=
theano
.
tensor
.
nnet
.
corr3d
.
Corr3dMM
(
border_mode
=
border_mode
,
subsample
=
subsample
)(
inputs
,
flipped_filters
)
f_ref
=
theano
.
function
([],
conv_ref
,
mode
=
"FAST_RUN"
)
# Compare the results of the two implementations
res_ref
=
f_ref
()
...
...
@@ -1618,7 +1595,6 @@ def test_conv3d_bwd():
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
bias
=
shared
(
numpy
.
zeros
(
filters_shape
[
0
])
.
astype
(
'float32'
))
# Compile a theano function for the cuDNN implementation
conv
=
dnn
.
dnn_conv3d
(
img
=
inputs
,
kerns
=
filters
,
...
...
@@ -1636,46 +1612,13 @@ def test_conv3d_bwd():
else
:
flipped_filters
=
filters
# If border mode is anything but 'valid', the reference implementation
# should operate on padded inputs
if
border_mode
==
'valid'
:
padded_inputs
=
inputs
else
:
if
border_mode
==
'full'
:
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
elif
border_mode
==
'half'
:
pad_per_dim
=
[
filters_shape
[
i
]
//
2
for
i
in
range
(
2
,
5
)]
else
:
if
isinstance
(
border_mode
,
int
):
pad_per_dim
=
[
border_mode
]
*
3
else
:
pad_per_dim
=
border_mode
pad_before_after
=
([(
0
,
0
),
(
0
,
0
)]
+
[(
p
,
p
)
for
p
in
pad_per_dim
])
padded_inputs_val
=
numpy
.
pad
(
inputs_val
,
pad_before_after
,
'constant'
)
padded_inputs
=
shared
(
padded_inputs_val
)
# Compile a theano function for the reference implementation
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
(
grad_padded_i_ref
,
conv_ref
=
theano
.
tensor
.
nnet
.
corr3d
.
Corr3dMM
(
border_mode
=
border_mode
,
subsample
=
subsample
)(
inputs
,
flipped_filters
)
(
grad_i_ref
,
grad_w_ref
)
=
theano
.
tensor
.
grad
(
conv_ref
.
sum
(),
[
padded_inputs
,
filters
])
# Recover grad_i_ref from grad_padded_i_ref
if
border_mode
==
'valid'
:
grad_i_ref
=
grad_padded_i_ref
else
:
shp
=
grad_padded_i_ref
.
shape
grad_i_ref
=
grad_padded_i_ref
[
:,
:,
pad_per_dim
[
0
]:
shp
[
2
]
-
pad_per_dim
[
0
],
pad_per_dim
[
1
]:
shp
[
3
]
-
pad_per_dim
[
1
],
pad_per_dim
[
2
]:
shp
[
4
]
-
pad_per_dim
[
2
]]
[
inputs
,
filters
])
f_ref
=
theano
.
function
([],
[
grad_i_ref
,
grad_w_ref
],
mode
=
"FAST_RUN"
)
...
...
theano/sandbox/cuda/tests/test_gemmcorr3d.py
浏览文件 @
9db32cee
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
numpy
from
six.moves
import
xrange
try
:
from
scipy
import
ndimage
except
ImportError
:
ndimage
=
None
import
theano
from
theano.tests
import
unittest_tools
as
utt
# Skip tests if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
from
theano.tensor.nnet.corr3d
import
Corr3dMM
,
Corr3dMM_gradWeights
,
Corr3dMM_gradInputs
from
theano.sandbox.cuda
import
float32_shared_constructor
as
shared
from
theano.sandbox.cuda.blas
import
(
GpuCorr3dMM
,
GpuCorr3dMM_gradWeights
,
GpuCorr3dMM_gradInputs
)
...
...
@@ -29,72 +25,6 @@ else:
# python reference implementation of a 3D convolution
# see also: theano.tensor.nnet.tests.test_conv3d2d
# expects: (batch, 0, channels, 1, 2)
def
pyconv3d
(
signals
,
filters
,
border_mode
=
'valid'
,
dilation
=
(
1
,
1
,
1
)):
Ns
,
Ts
,
C
,
Hs
,
Ws
=
signals
.
shape
Nf
,
Tf
,
C
,
Hf
,
Wf
=
filters
.
shape
Tdil
,
Hdil
,
Wdil
=
dilation
Tfdil
=
(
Tf
-
1
)
*
Tdil
+
1
Hfdil
=
(
Hf
-
1
)
*
Hdil
+
1
Wfdil
=
(
Wf
-
1
)
*
Wdil
+
1
# if border_mode is not 'valid', the signals need zero-padding
if
border_mode
==
'full'
:
Tpad
=
Tfdil
-
1
Hpad
=
Hfdil
-
1
Wpad
=
Wfdil
-
1
elif
border_mode
==
'half'
:
Tpad
=
Tfdil
//
2
Hpad
=
Hfdil
//
2
Wpad
=
Wfdil
//
2
elif
isinstance
(
border_mode
,
tuple
):
Tpad
,
Hpad
,
Wpad
=
map
(
int
,
border_mode
)
else
:
Tpad
=
0
Hpad
=
0
Wpad
=
0
if
Tpad
>
0
or
Hpad
>
0
or
Wpad
>
0
:
# zero-pad signals
signals_padded
=
numpy
.
zeros
((
Ns
,
Ts
+
2
*
Tpad
,
C
,
Hs
+
2
*
Hpad
,
Ws
+
2
*
Wpad
),
'float32'
)
signals_padded
[:,
Tpad
:(
Ts
+
Tpad
),
:,
Hpad
:(
Hs
+
Hpad
),
Wpad
:(
Ws
+
Wpad
)]
=
signals
Ns
,
Ts
,
C
,
Hs
,
Ws
=
signals_padded
.
shape
signals
=
signals_padded
Tfdil2
=
Tfdil
//
2
Hfdil2
=
Hfdil
//
2
Wfdil2
=
Wfdil
//
2
dilated_filters
=
numpy
.
zeros
((
Nf
,
Tfdil
,
C
,
Hfdil
,
Wfdil
),
dtype
=
filters
.
dtype
)
dilated_filters
[:,
::
Tdil
,
:,
::
Hdil
,
::
Wdil
]
=
filters
# perform valid convolution on the padded signals
rval
=
numpy
.
zeros
((
Ns
,
Ts
-
Tfdil
+
1
,
Nf
,
Hs
-
Hfdil
+
1
,
Ws
-
Wfdil
+
1
))
for
ns
in
xrange
(
Ns
):
for
nf
in
xrange
(
Nf
):
for
c
in
xrange
(
C
):
s_i
=
signals
[
ns
,
:,
c
,
:,
:]
f_i
=
dilated_filters
[
nf
,
:,
c
,
:,
:]
r_i
=
rval
[
ns
,
:,
nf
,
:,
:]
# scipy.signal.convolve performs valid convolution,
# but is quite slow. scipy.ndimage.convolve is faster
# only supports 'same' convolution.
# origin must be -1 for even filters, 0 for odd filters
o_i
=
ndimage
.
convolve
(
s_i
,
f_i
,
mode
=
'constant'
,
cval
=
1
,
origin
=
(
f_i
.
shape
[
0
]
%
2
-
1
,
f_i
.
shape
[
1
]
%
2
-
1
,
f_i
.
shape
[
2
]
%
2
-
1
))
# crop to get the result of 'valid' convolution
o_i
=
o_i
[
Tfdil2
:(
r_i
.
shape
[
0
]
+
Tfdil2
),
Hfdil2
:(
r_i
.
shape
[
1
]
+
Hfdil2
),
Wfdil2
:(
r_i
.
shape
[
2
]
+
Wfdil2
)]
# the result should be equal to 'valid' convolution
# utt.assert_allclose(o_i, signal.convolve(s_i, f_i, mode='valid'))
r_i
+=
o_i
return
rval
class
TestCorr3DMM
(
unittest
.
TestCase
):
def
run_conv_valid
(
self
,
inputs_shape
,
filters_shape
,
...
...
@@ -107,26 +37,14 @@ class TestCorr3DMM(unittest.TestCase):
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
bias
=
shared
(
numpy
.
zeros
(
filters_shape
[
0
])
.
astype
(
'float32'
))
if
filter_dilation
==
(
1
,
1
,
1
)
and
border_mode
in
(
'valid'
,
(
0
,
0
,
0
)):
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
inputs
,
W
=
filters
,
b
=
bias
,
d
=
subsample
)
f_ref
=
theano
.
function
([],
conv_ref
)
res_ref
=
f_ref
()
elif
subsample
==
(
1
,
1
,
1
):
if
ndimage
is
None
:
raise
SkipTest
(
'This test needs SciPy.'
)
# input = b012c
# pyconv3d wants = b0c12 = (0, 1, 4, 2, 3)
# pyconv3d outputs = b0c12 = (0, 1, 3, 4, 2)
res_ref
=
pyconv3d
(
signals
=
inputs_val
.
transpose
(
0
,
1
,
4
,
2
,
3
),
filters
=
filters_val
.
transpose
(
0
,
1
,
4
,
2
,
3
)[:,
::
-
1
,
:,
::
-
1
,
::
-
1
],
dilation
=
filter_dilation
,
border_mode
=
border_mode
)
.
transpose
(
0
,
1
,
3
,
4
,
2
)
else
:
raise
SkipTest
(
'No reference implementation that combines '
'border_mode and subsampling.'
)
conv_ref
=
Corr3dMM
(
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
subsample
=
subsample
)(
inputs
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
),
filters
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
conv_ref
=
conv_ref
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
f_ref
=
theano
.
function
([],
conv_ref
,
mode
=
'FAST_RUN'
)
conv
=
GpuCorr3dMM
(
border_mode
=
border_mode
,
filter_dilation
=
filter_dilation
,
...
...
@@ -134,9 +52,9 @@ class TestCorr3DMM(unittest.TestCase):
inputs
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
),
filters
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
conv
=
conv
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
f
=
theano
.
function
([],
conv
,
mode
=
mode_with_gpu
)
res_ref
=
f_ref
()
res
=
f
()
utt
.
assert_allclose
(
res_ref
,
res
)
...
...
@@ -220,19 +138,20 @@ class TestCorr3DMM(unittest.TestCase):
inputs
=
shared
(
inputs_val
)
dCdH
=
shared
(
dCdH_val
)
conv
=
theano
.
tensor
.
nnet
.
convGrad3D
(
V
=
inputs
,
dCdH
=
dCdH
,
WShape
=
filters_shape
,
d
=
subsample
)
img
=
gpu_contiguous
(
inputs
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
topgrad
=
gpu_contiguous
(
dCdH
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
if
(
subsample
==
(
1
,
1
,
1
)):
conv_gemm
=
GpuCorr3dMM_gradWeights
(
subsample
=
subsample
)(
img
,
topgrad
)
conv_ref
=
Corr3dMM_gradWeights
(
subsample
=
subsample
)(
img
,
topgrad
)
conv_gemm
=
GpuCorr3dMM_gradWeights
(
subsample
=
subsample
)(
img
,
topgrad
)
else
:
conv_ref
=
GpuCorr3dMM_gradWeights
(
subsample
=
subsample
)(
img
,
topgrad
,
shape
=
filters_shape
[
1
:
4
])
conv_gemm
=
GpuCorr3dMM_gradWeights
(
subsample
=
subsample
)(
img
,
topgrad
,
shape
=
filters_shape
[
1
:
4
])
conv_gemm
=
conv_gemm
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
f_ref
=
theano
.
function
([],
conv
)
f_ref
=
theano
.
function
([],
conv
_ref
)
f
=
theano
.
function
([],
conv_gemm
,
mode
=
mode_with_gpu
)
res_ref
=
f_ref
()
...
...
@@ -265,31 +184,31 @@ class TestCorr3DMM(unittest.TestCase):
inputs
=
shared
(
inputs_val
)
filters
=
shared
(
filters_val
)
bias
=
shared
(
numpy
.
zeros
(
filters_shape
[
4
])
.
astype
(
'float32'
))
conv
=
theano
.
tensor
.
nnet
.
convTransp3D
(
W
=
filters
,
b
=
bias
,
d
=
subsample
,
H
=
inputs
)
f_ref
=
theano
.
function
([],
conv
)
res_ref
=
f_ref
()
# Get bottom shape using convTransp3D
bottom_
shape
=
res_ref
.
shape
bottom_
val
=
numpy
.
random
.
random
(
bottom_shape
)
.
astype
(
'float32'
)
bottom
=
shared
(
bottom_val
)
bottom_height
=
(
inputs_shape
[
1
]
-
1
)
*
subsample
[
0
]
+
filters_shape
[
1
]
bottom_
width
=
(
inputs_shape
[
2
]
-
1
)
*
subsample
[
1
]
+
filters_shape
[
2
]
bottom_
depth
=
(
inputs_shape
[
3
]
-
1
)
*
subsample
[
2
]
+
filters_shape
[
3
]
bottom
_shape
=
theano
.
shared
(
numpy
.
array
([
bottom_height
,
bottom_width
,
bottom_depth
])
)
weight
=
gpu_contiguous
(
filters
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
top
=
gpu_contiguous
(
inputs
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
if
(
subsample
==
(
1
,
1
,
1
)):
conv_ref
=
Corr3dMM_gradInputs
(
subsample
=
subsample
)(
kern
=
weight
,
topgrad
=
top
)
conv_gemm
=
GpuCorr3dMM_gradInputs
(
subsample
=
subsample
)(
kern
=
weight
,
topgrad
=
top
)
else
:
conv_ref
=
Corr3dMM_gradInputs
(
subsample
=
subsample
)(
kern
=
weight
,
topgrad
=
top
,
shape
=
bottom_shape
)
conv_gemm
=
GpuCorr3dMM_gradInputs
(
subsample
=
subsample
)(
kern
=
weight
,
topgrad
=
top
,
shape
=
bottom
.
shape
[
1
:
4
])
conv_gemm
=
conv_gemm
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
shape
=
bottom_shape
)
f_ref
=
theano
.
function
([],
conv_ref
)
f
=
theano
.
function
([],
conv_gemm
,
mode
=
mode_with_gpu
)
res_ref
=
f_ref
()
res
=
f
()
utt
.
assert_allclose
(
res_ref
,
res
)
...
...
theano/tests/test_gradient.py
浏览文件 @
9db32cee
...
...
@@ -14,7 +14,6 @@ from theano.compat import izip
from
theano.tests
import
unittest_tools
as
utt
from
theano
import
gradient
from
theano.tensor.nnet.Conv3D
import
conv3D
from
theano
import
config
from
theano.gof.null_type
import
NullType
...
...
@@ -187,16 +186,19 @@ class test_grad(unittest.TestCase):
def
test_undefined_grad_grad
(
self
):
# tests that undefined grads are caught in the grad method
V
=
theano
.
tensor
.
TensorType
(
dtype
=
config
.
floatX
,
broadcastable
=
(
False
,
False
,
False
,
False
,
False
))()
W
=
theano
.
tensor
.
TensorType
(
dtype
=
config
.
floatX
,
broadcastable
=
(
False
,
False
,
False
,
False
,
False
))()
b
=
theano
.
tensor
.
vector
()
d
=
theano
.
tensor
.
ivector
()
class
DummyOp
(
gof
.
Op
):
__props__
=
()
Z
=
conv3D
(
V
,
W
,
b
,
d
)
def
make_node
(
self
,
x
):
return
gof
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
self
.
assertRaises
(
TypeError
,
theano
.
gradient
.
grad
,
Z
.
sum
(),
d
)
def
grad
(
self
,
inputs
,
output_grads
):
return
[
theano
.
gradient
.
grad_undefined
(
self
,
0
,
inputs
[
0
])]
a
=
theano
.
tensor
.
scalar
()
b
=
DummyOp
()(
a
)
self
.
assertRaises
(
TypeError
,
theano
.
gradient
.
grad
,
b
,
a
)
def
test_grad_name
(
self
):
A
=
theano
.
tensor
.
matrix
(
'A'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论