Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
59a17284
提交
59a17284
authored
11月 26, 2016
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Brute-force test for inconsistent conv shapes.
上级
0e40d582
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
301 行增加
和
101 行删除
+301
-101
test_abstractconv.py
theano/gpuarray/tests/test_abstractconv.py
+79
-28
test_abstractconv.py
theano/sandbox/cuda/tests/test_abstractconv.py
+79
-30
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+143
-43
没有找到文件。
theano/gpuarray/tests/test_abstractconv.py
浏览文件 @
59a17284
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
import
numpy
import
numpy
...
@@ -49,17 +50,30 @@ class TestDnnConv2d(test_abstract_conv.BaseTestConv2d):
...
@@ -49,17 +50,30 @@ class TestDnnConv2d(test_abstract_conv.BaseTestConv2d):
provide_shape
=
provide_shape
,
border_mode
=
b
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
)
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)
,
expect_error
=
False
):
if
not
dnn_available
(
test_ctx_name
):
if
not
dnn_available
(
test_ctx_name
):
raise
SkipTest
(
dnn_available
.
msg
)
raise
SkipTest
(
dnn_available
.
msg
)
if
fd
!=
(
1
,
1
):
if
fd
!=
(
1
,
1
):
raise
SkipTest
(
"Doesn't have CUDNN implementation"
)
raise
SkipTest
(
"Doesn't have CUDNN implementation"
)
mode
=
mode_with_gpu
mode
=
mode_with_gpu
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
if
not
expect_error
:
verify_grad
=
True
,
mode
=
mode
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
output_shape
=
o
,
subsample
=
s
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
)
verify_grad
=
True
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
filter_dilation
=
fd
)
else
:
assert_raises
((
RuntimeError
,
ValueError
),
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestDnnConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
class
TestDnnConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
...
@@ -94,17 +108,30 @@ class TestDnnConv3d(test_abstract_conv.BaseTestConv3d):
...
@@ -94,17 +108,30 @@ class TestDnnConv3d(test_abstract_conv.BaseTestConv3d):
provide_shape
=
provide_shape
,
border_mode
=
b
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
)
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)
,
expect_error
=
False
):
if
not
dnn_available
(
test_ctx_name
):
if
not
dnn_available
(
test_ctx_name
):
raise
SkipTest
(
dnn_available
.
msg
)
raise
SkipTest
(
dnn_available
.
msg
)
if
fd
!=
(
1
,
1
,
1
):
if
fd
!=
(
1
,
1
,
1
):
raise
SkipTest
(
"Doesn't have CUDNN implementation"
)
raise
SkipTest
(
"Doesn't have CUDNN implementation"
)
mode
=
mode_with_gpu
mode
=
mode_with_gpu
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
if
not
expect_error
:
verify_grad
=
True
,
mode
=
mode
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
output_shape
=
o
,
subsample
=
s
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
)
verify_grad
=
True
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
filter_dilation
=
fd
)
else
:
assert_raises
((
RuntimeError
,
ValueError
),
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestCorrMMConv2d
(
test_abstract_conv
.
BaseTestConv2d
):
class
TestCorrMMConv2d
(
test_abstract_conv
.
BaseTestConv2d
):
...
@@ -139,15 +166,27 @@ class TestCorrMMConv2d(test_abstract_conv.BaseTestConv2d):
...
@@ -139,15 +166,27 @@ class TestCorrMMConv2d(test_abstract_conv.BaseTestConv2d):
target_op
=
GpuCorrMM_gradInputs
,
target_op
=
GpuCorrMM_gradInputs
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)
,
expect_error
=
False
):
mode
=
self
.
mode
mode
=
self
.
mode
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
verify_grad
=
True
,
mode
=
mode
,
output_shape
=
o
,
subsample
=
s
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
verify_grad
=
True
,
mode
=
mode
,
filter_flip
=
flip
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
target_op
=
GpuCorrMM_gradInputs
,
filter_flip
=
flip
,
filter_dilation
=
fd
)
target_op
=
GpuCorrMM_gradInputs
,
filter_dilation
=
fd
)
else
:
assert_raises
(
ValueError
,
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuCorrMM_gradInputs
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestCorrMMConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
class
TestCorrMMConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
...
@@ -182,15 +221,27 @@ class TestCorrMMConv3d(test_abstract_conv.BaseTestConv3d):
...
@@ -182,15 +221,27 @@ class TestCorrMMConv3d(test_abstract_conv.BaseTestConv3d):
target_op
=
GpuCorr3dMM_gradInputs
,
target_op
=
GpuCorr3dMM_gradInputs
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)
,
expect_error
=
False
):
mode
=
self
.
mode
mode
=
self
.
mode
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
verify_grad
=
True
,
mode
=
mode
,
output_shape
=
o
,
subsample
=
s
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
verify_grad
=
True
,
mode
=
mode
,
filter_flip
=
flip
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
target_op
=
GpuCorr3dMM_gradInputs
,
filter_flip
=
flip
,
filter_dilation
=
fd
)
target_op
=
GpuCorr3dMM_gradInputs
,
filter_dilation
=
fd
)
else
:
assert_raises
(
ValueError
,
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuCorr3dMM_gradInputs
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestDnnConvTypes
(
test_abstract_conv
.
TestConvTypes
):
class
TestDnnConvTypes
(
test_abstract_conv
.
TestConvTypes
):
...
...
theano/sandbox/cuda/tests/test_abstractconv.py
浏览文件 @
59a17284
...
@@ -13,6 +13,7 @@ from theano.sandbox.cuda.blas import (
...
@@ -13,6 +13,7 @@ from theano.sandbox.cuda.blas import (
GpuCorrMM
,
GpuCorrMM_gradWeights
,
GpuCorrMM_gradInputs
,
GpuCorrMM
,
GpuCorrMM_gradWeights
,
GpuCorrMM_gradInputs
,
GpuCorr3dMM
,
GpuCorr3dMM_gradWeights
,
GpuCorr3dMM_gradInputs
)
GpuCorr3dMM
,
GpuCorr3dMM_gradWeights
,
GpuCorr3dMM_gradInputs
)
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
import
theano.sandbox.cuda
as
cuda
import
theano.sandbox.cuda
as
cuda
if
not
cuda
.
cuda_available
:
if
not
cuda
.
cuda_available
:
...
@@ -57,18 +58,30 @@ class TestDnnConv2d(test_abstract_conv.BaseTestConv2d):
...
@@ -57,18 +58,30 @@ class TestDnnConv2d(test_abstract_conv.BaseTestConv2d):
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)
,
expect_error
=
False
):
if
fd
!=
(
1
,
1
):
if
fd
!=
(
1
,
1
):
raise
SkipTest
(
"No dilation implementation for cuDNN ConvOp."
)
raise
SkipTest
(
"No dilation implementation for cuDNN ConvOp."
)
if
not
dnn_available
():
if
not
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
mode
=
mode_with_gpu
mode
=
mode_with_gpu
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
if
not
expect_error
:
verify_grad
=
True
,
mode
=
mode
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
output_shape
=
o
,
subsample
=
s
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
verify_grad
=
True
,
mode
=
mode
,
filter_dilation
=
fd
)
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
filter_dilation
=
fd
)
else
:
assert_raises
((
RuntimeError
,
ValueError
),
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestDnnConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
class
TestDnnConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
...
@@ -104,18 +117,30 @@ class TestDnnConv3d(test_abstract_conv.BaseTestConv3d):
...
@@ -104,18 +117,30 @@ class TestDnnConv3d(test_abstract_conv.BaseTestConv3d):
filter_flip
=
flip
,
target_op
=
GpuDnnConv3dGradI
,
filter_flip
=
flip
,
target_op
=
GpuDnnConv3dGradI
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)
,
expect_error
=
False
):
if
fd
!=
(
1
,
1
,
1
):
if
fd
!=
(
1
,
1
,
1
):
raise
SkipTest
(
"No dilation implementation for cuDNN ConvOp."
)
raise
SkipTest
(
"No dilation implementation for cuDNN ConvOp."
)
if
not
dnn_available
():
if
not
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
mode
=
mode_with_gpu
mode
=
mode_with_gpu
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
if
not
expect_error
:
verify_grad
=
True
,
mode
=
mode
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
output_shape
=
o
,
subsample
=
s
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
verify_grad
=
True
,
mode
=
mode
,
filter_dilation
=
fd
)
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
filter_dilation
=
fd
)
else
:
assert_raises
((
RuntimeError
,
ValueError
),
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuDnnConvGradI
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestCorrMMConv2d
(
test_abstract_conv
.
BaseTestConv2d
):
class
TestCorrMMConv2d
(
test_abstract_conv
.
BaseTestConv2d
):
...
@@ -150,15 +175,27 @@ class TestCorrMMConv2d(test_abstract_conv.BaseTestConv2d):
...
@@ -150,15 +175,27 @@ class TestCorrMMConv2d(test_abstract_conv.BaseTestConv2d):
target_op
=
GpuCorrMM_gradInputs
,
target_op
=
GpuCorrMM_gradInputs
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)
,
expect_error
=
False
):
mode
=
self
.
mode
mode
=
self
.
mode
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
verify_grad
=
True
,
mode
=
mode
,
output_shape
=
o
,
subsample
=
s
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
verify_grad
=
True
,
mode
=
mode
,
filter_flip
=
flip
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
target_op
=
GpuCorrMM_gradInputs
,
filter_flip
=
flip
,
filter_dilation
=
fd
)
target_op
=
GpuCorrMM_gradInputs
,
filter_dilation
=
fd
)
else
:
assert_raises
(
ValueError
,
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuCorrMM_gradInputs
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestCorrMMConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
class
TestCorrMMConv3d
(
test_abstract_conv
.
BaseTestConv3d
):
...
@@ -193,15 +230,27 @@ class TestCorrMMConv3d(test_abstract_conv.BaseTestConv3d):
...
@@ -193,15 +230,27 @@ class TestCorrMMConv3d(test_abstract_conv.BaseTestConv3d):
target_op
=
GpuCorr3dMM_gradInputs
,
target_op
=
GpuCorr3dMM_gradInputs
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)
,
expect_error
=
False
):
mode
=
self
.
mode
mode
=
self
.
mode
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
verify_grad
=
True
,
mode
=
mode
,
output_shape
=
o
,
subsample
=
s
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
verify_grad
=
True
,
mode
=
mode
,
filter_flip
=
flip
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
target_op
=
GpuCorr3dMM_gradInputs
,
filter_flip
=
flip
,
filter_dilation
=
fd
)
target_op
=
GpuCorr3dMM_gradInputs
,
filter_dilation
=
fd
)
else
:
assert_raises
(
ValueError
,
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
mode
=
mode
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
GpuCorr3dMM_gradInputs
,
ref
=
None
,
filter_dilation
=
fd
)
class
TestDnnConvTypes
(
test_abstract_conv
.
TestConvTypes
):
class
TestDnnConvTypes
(
test_abstract_conv
.
TestConvTypes
):
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
59a17284
...
@@ -392,11 +392,16 @@ class BaseTestConv(object):
...
@@ -392,11 +392,16 @@ class BaseTestConv(object):
imshp
=
imshp
,
kshp
=
kshp
,
imshp
=
imshp
,
kshp
=
kshp
,
filter_dilation
=
filter_dilation
)
filter_dilation
=
filter_dilation
)
c
=
c
(
filters
,
output
,
inputs_shape
[
2
:])
c
=
c
(
filters
,
output
,
inputs_shape
[
2
:])
c_ref
=
ref
(
filters
,
output
,
inputs_shape
,
border_mode
=
border_mode
,
subsample
=
subsample
,
conv_mode
=
conv_mode
,
filter_dilation
=
filter_dilation
)
f
=
theano
.
function
([],
c
,
mode
=
mode
)
f
=
theano
.
function
([],
c
,
mode
=
mode
)
f_ref
=
theano
.
function
([],
c_ref
,
mode
=
'FAST_RUN'
)
# ref is set to None for the inconsistent-shape tests.
# The reference function also raises an exception, which would
# mask the exception generated by the target implementation.
if
ref
is
not
None
:
c_ref
=
ref
(
filters
,
output
,
inputs_shape
,
border_mode
=
border_mode
,
subsample
=
subsample
,
conv_mode
=
conv_mode
,
filter_dilation
=
filter_dilation
)
f_ref
=
theano
.
function
([],
c_ref
,
mode
=
'FAST_RUN'
)
if
target_op
is
not
None
:
if
target_op
is
not
None
:
assert
any
([
isinstance
(
n
.
op
,
target_op
)
for
n
assert
any
([
isinstance
(
n
.
op
,
target_op
)
for
n
...
@@ -404,9 +409,11 @@ class BaseTestConv(object):
...
@@ -404,9 +409,11 @@ class BaseTestConv(object):
if
check_trace
:
if
check_trace
:
assert_true
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
assert_true
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
res_ref
=
numpy
.
array
(
f_ref
())
res
=
numpy
.
array
(
f
())
res
=
numpy
.
array
(
f
())
utt
.
assert_allclose
(
res_ref
,
res
)
if
ref
is
not
None
:
res_ref
=
numpy
.
array
(
f_ref
())
utt
.
assert_allclose
(
res_ref
,
res
)
def
abstract_conv_gradinputs
(
filters_val
,
output_val
):
def
abstract_conv_gradinputs
(
filters_val
,
output_val
):
conv_op
=
gradInputs_fn
(
border_mode
=
border_mode
,
conv_op
=
gradInputs_fn
(
border_mode
=
border_mode
,
...
@@ -482,6 +489,33 @@ class BaseTestConv2d(BaseTestConv):
...
@@ -482,6 +489,33 @@ class BaseTestConv2d(BaseTestConv):
provide_shape
,
provide_shape
,
self
.
default_filters_dilations
)
self
.
default_filters_dilations
)
def
test_gradinput_impossible_output_shapes
(
self
):
for
i
in
range
(
1
,
20
):
for
k
in
range
(
1
,
10
):
for
border_mode
in
(
'valid'
,
'half'
,
'full'
,
(
0
,
2
)):
for
s
in
(
1
,
2
,
3
):
for
d
in
(
1
,
2
,
3
):
image_shape
=
(
1
,
1
,
i
,
i
)
kernel_shape
=
(
1
,
1
,
k
,
k
)
# compute the output that these inputs and parameters would produce
computed_shape
=
get_conv_output_shape
(
image_shape
,
kernel_shape
,
border_mode
,
(
s
,
s
),
(
d
,
d
))
# outputs that are too large or too small should be rejected
for
o
in
(
-
3
,
-
2
,
-
1
,
1
,
2
,
3
):
output_shape
=
(
1
,
1
,
computed_shape
[
2
]
+
o
,
computed_shape
[
3
]
+
o
)
yield
(
self
.
tcase_gi
,
image_shape
,
kernel_shape
,
output_shape
,
(
s
,
s
),
border_mode
,
True
,
True
,
(
d
,
d
),
True
)
def
run_fwd
(
self
,
inputs_shape
,
filters_shape
,
def
run_fwd
(
self
,
inputs_shape
,
filters_shape
,
conv_fn
=
conv
.
conv2d
,
conv_op
=
conv
.
AbstractConv2d
,
conv_fn
=
conv
.
conv2d
,
conv_op
=
conv
.
AbstractConv2d
,
ref
=
conv2d_corr
,
**
kwargs
):
ref
=
conv2d_corr
,
**
kwargs
):
...
@@ -541,16 +575,25 @@ class TestCorrConv2d(BaseTestConv2d):
...
@@ -541,16 +575,25 @@ class TestCorrConv2d(BaseTestConv2d):
filter_flip
=
flip
,
target_op
=
CorrMM_gradInputs
,
filter_flip
=
flip
,
target_op
=
CorrMM_gradInputs
,
check_trace
=
True
,
filter_dilation
=
fd
)
check_trace
=
True
,
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)
,
expect_error
=
False
):
# This tests can run even when theano.config.blas.ldflags is empty.
# This tests can run even when theano.config.blas.ldflags is empty.
if
(
not
theano
.
config
.
cxx
or
if
(
not
theano
.
config
.
cxx
or
theano
.
config
.
mode
==
"FAST_COMPILE"
):
theano
.
config
.
mode
==
"FAST_COMPILE"
):
raise
SkipTest
(
"Need blas to test conv2d"
)
raise
SkipTest
(
"Need blas to test conv2d"
)
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
filter_flip
=
flip
,
target_op
=
CorrMM_gradInputs
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
check_trace
=
True
,
filter_dilation
=
fd
)
filter_flip
=
flip
,
target_op
=
CorrMM_gradInputs
,
check_trace
=
True
,
filter_dilation
=
fd
)
else
:
assert_raises
(
ValueError
,
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
CorrMM_gradInputs
,
ref
=
None
,
check_trace
=
True
,
filter_dilation
=
fd
)
class
TestAbstractConvNoOptim
(
BaseTestConv2d
):
class
TestAbstractConvNoOptim
(
BaseTestConv2d
):
...
@@ -591,14 +634,24 @@ class TestAbstractConvNoOptim(BaseTestConv2d):
...
@@ -591,14 +634,24 @@ class TestAbstractConvNoOptim(BaseTestConv2d):
check_trace
=
True
,
filter_dilation
=
fd
,
check_trace
=
True
,
filter_dilation
=
fd
,
mode
=
mode
)
mode
=
mode
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)
,
expect_error
=
False
):
mode
=
theano
.
Mode
(
optimizer
=
None
)
mode
=
theano
.
Mode
(
optimizer
=
None
)
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
filter_flip
=
flip
,
target_op
=
None
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
check_trace
=
True
,
filter_dilation
=
fd
,
filter_flip
=
flip
,
target_op
=
None
,
mode
=
mode
)
check_trace
=
True
,
filter_dilation
=
fd
,
mode
=
mode
)
else
:
assert_raises
(
ValueError
,
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
None
,
check_trace
=
True
,
filter_dilation
=
fd
,
ref
=
None
,
mode
=
mode
)
class
TestCpuConv2d
(
BaseTestConv2d
):
class
TestCpuConv2d
(
BaseTestConv2d
):
...
@@ -715,7 +768,7 @@ class TestCpuConv2d(BaseTestConv2d):
...
@@ -715,7 +768,7 @@ class TestCpuConv2d(BaseTestConv2d):
check_trace
=
True
,
check_trace
=
True
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
)
,
expect_error
=
False
):
if
fd
!=
(
1
,
1
):
if
fd
!=
(
1
,
1
):
raise
SkipTest
(
"No dilation implementation for basic cpu ConvOp."
)
raise
SkipTest
(
"No dilation implementation for basic cpu ConvOp."
)
mode
=
self
.
mode
mode
=
self
.
mode
...
@@ -729,14 +782,19 @@ class TestCpuConv2d(BaseTestConv2d):
...
@@ -729,14 +782,19 @@ class TestCpuConv2d(BaseTestConv2d):
if
((
s
[
0
]
not
in
(
1
,
2
))
or
(
s
[
1
]
not
in
(
1
,
2
)))
and
(
b
==
'full'
):
if
((
s
[
0
]
not
in
(
1
,
2
))
or
(
s
[
1
]
not
in
(
1
,
2
)))
and
(
b
==
'full'
):
return
return
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
verify_grad
=
False
,
mode
=
mode
,
output_shape
=
o
,
subsample
=
s
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
verify_grad
=
False
,
mode
=
mode
,
filter_flip
=
flip
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
target_op
=
(
ConvOp
,
ConvTransp3D
),
filter_flip
=
flip
,
check_trace
=
True
,
target_op
=
(
ConvOp
,
ConvTransp3D
),
filter_dilation
=
fd
)
check_trace
=
True
,
filter_dilation
=
fd
)
else
:
# we do not check for inconsistent shapes,
# because this older implementation does not check that
raise
SkipTest
(
'Inconsistent shapes are not tested for old cpu ConvOp.'
)
class
BaseTestConv3d
(
BaseTestConv
):
class
BaseTestConv3d
(
BaseTestConv
):
...
@@ -781,6 +839,34 @@ class BaseTestConv3d(BaseTestConv):
...
@@ -781,6 +839,34 @@ class BaseTestConv3d(BaseTestConv):
provide_shape
,
provide_shape
,
self
.
default_filters_dilations
)
self
.
default_filters_dilations
)
def
test_gradinput_impossible_output_shapes
(
self
):
for
i
in
range
(
1
,
20
):
for
k
in
range
(
1
,
10
):
for
border_mode
in
(
'valid'
,
'half'
,
'full'
,
(
0
,
2
,
1
)):
for
s
in
(
1
,
2
,
3
):
for
d
in
(
1
,
2
,
3
):
image_shape
=
(
1
,
1
,
i
,
i
,
i
)
kernel_shape
=
(
1
,
1
,
k
,
k
,
k
)
# compute the output that these inputs and parameters would produce
computed_shape
=
get_conv_output_shape
(
image_shape
,
kernel_shape
,
border_mode
,
(
s
,
s
,
s
),
(
d
,
d
,
d
))
# outputs that are too large or too small should be rejected
for
o
in
(
-
3
,
-
2
,
-
1
,
1
,
2
,
3
):
output_shape
=
(
1
,
1
,
computed_shape
[
2
]
+
o
,
computed_shape
[
3
]
+
o
,
computed_shape
[
4
]
+
o
)
yield
(
self
.
tcase_gi
,
image_shape
,
kernel_shape
,
output_shape
,
(
s
,
s
,
s
),
border_mode
,
True
,
True
,
(
d
,
d
,
d
),
True
)
def
run_fwd
(
self
,
inputs_shape
,
filters_shape
,
def
run_fwd
(
self
,
inputs_shape
,
filters_shape
,
conv_fn
=
conv
.
conv3d
,
conv_op
=
conv
.
AbstractConv3d
,
conv_fn
=
conv
.
conv3d
,
conv_op
=
conv
.
AbstractConv3d
,
ref
=
conv3d_corr
,
**
kwargs
):
ref
=
conv3d_corr
,
**
kwargs
):
...
@@ -840,16 +926,25 @@ class TestCorrConv3d(BaseTestConv3d):
...
@@ -840,16 +926,25 @@ class TestCorrConv3d(BaseTestConv3d):
filter_flip
=
flip
,
target_op
=
Corr3dMM_gradInputs
,
filter_flip
=
flip
,
target_op
=
Corr3dMM_gradInputs
,
check_trace
=
True
,
filter_dilation
=
fd
)
check_trace
=
True
,
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)
,
expect_error
=
False
):
# This test can run even when theano.config.blas.ldflags is empty.
# This test can run even when theano.config.blas.ldflags is empty.
if
(
not
theano
.
config
.
cxx
or
if
(
not
theano
.
config
.
cxx
or
theano
.
config
.
mode
==
"FAST_COMPILE"
):
theano
.
config
.
mode
==
"FAST_COMPILE"
):
raise
SkipTest
(
"Need blas to test conv3d"
)
raise
SkipTest
(
"Need blas to test conv3d"
)
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
True
,
filter_flip
=
flip
,
target_op
=
Corr3dMM_gradInputs
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
check_trace
=
True
,
filter_dilation
=
fd
)
filter_flip
=
flip
,
target_op
=
Corr3dMM_gradInputs
,
check_trace
=
True
,
filter_dilation
=
fd
)
else
:
assert_raises
(
ValueError
,
self
.
run_gradinput
,
inputs_shape
=
i
,
filters_shape
=
f
,
output_shape
=
o
,
subsample
=
s
,
verify_grad
=
False
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
target_op
=
Corr3dMM_gradInputs
,
ref
=
None
,
check_trace
=
True
,
filter_dilation
=
fd
)
class
TestCpuConv3d
(
BaseTestConv3d
):
class
TestCpuConv3d
(
BaseTestConv3d
):
...
@@ -952,7 +1047,7 @@ class TestCpuConv3d(BaseTestConv3d):
...
@@ -952,7 +1047,7 @@ class TestCpuConv3d(BaseTestConv3d):
check_trace
=
True
,
check_trace
=
True
,
filter_dilation
=
fd
)
filter_dilation
=
fd
)
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)):
def
tcase_gi
(
self
,
i
,
f
,
o
,
s
,
b
,
flip
,
provide_shape
,
fd
=
(
1
,
1
,
1
)
,
expect_error
=
False
):
if
fd
!=
(
1
,
1
,
1
):
if
fd
!=
(
1
,
1
,
1
):
raise
SkipTest
(
"No dilation implementation for basic cpu Conv3D."
)
raise
SkipTest
(
"No dilation implementation for basic cpu Conv3D."
)
mode
=
self
.
mode
mode
=
self
.
mode
...
@@ -960,14 +1055,19 @@ class TestCpuConv3d(BaseTestConv3d):
...
@@ -960,14 +1055,19 @@ class TestCpuConv3d(BaseTestConv3d):
if
b
not
in
((
0
,
0
,
0
),
'valid'
):
if
b
not
in
((
0
,
0
,
0
),
'valid'
):
return
return
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
if
not
expect_error
:
output_shape
=
o
,
subsample
=
s
,
self
.
run_gradinput
(
inputs_shape
=
i
,
filters_shape
=
f
,
verify_grad
=
False
,
mode
=
mode
,
output_shape
=
o
,
subsample
=
s
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
verify_grad
=
False
,
mode
=
mode
,
filter_flip
=
flip
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
target_op
=
ConvTransp3D
,
filter_flip
=
flip
,
check_trace
=
True
,
target_op
=
ConvTransp3D
,
filter_dilation
=
fd
)
check_trace
=
True
,
filter_dilation
=
fd
)
else
:
# we do not check for inconsistent shapes,
# because this older implementation does not check that
raise
SkipTest
(
'Inconsistent shapes are not tested for old cpu Conv3D.'
)
def
test_constant_shapes
():
def
test_constant_shapes
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论