Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
121ec69a
提交
121ec69a
authored
3月 04, 2016
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finish, clean-up, and test
上级
0d4e482d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
66 行增加
和
10 行删除
+66
-10
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+15
-10
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+51
-0
没有找到文件。
theano/tensor/nnet/abstract_conv.py
浏览文件 @
121ec69a
...
...
@@ -4,6 +4,7 @@ Abstract conv interface
import
logging
from
six
import
reraise
import
sys
import
theano
...
...
@@ -414,26 +415,30 @@ class BaseAbstractConv2d(Op):
'"valid", "full", "half", an integer or a pair of'
' integers'
.
format
(
border_mode
))
self
.
imshp
=
tuple
(
imshp
)
if
imshp
else
None
self
.
imshp
=
tuple
(
imshp
)
if
imshp
else
(
None
,)
*
4
for
imshp_i
in
self
.
imshp
:
if
imshp_i
is
not
None
:
# Components of imshp should be constant or ints
try
:
get_scalar_constant_value
(
imshp_i
)
get_scalar_constant_value
(
imshp_i
,
only_process_constants
=
True
)
except
NotScalarConstantError
:
_logger
.
error
(
"imshp should be None or "
"a tuple of constant int values"
)
raise
self
.
kshp
=
tuple
(
kshp
)
if
kshp
else
None
reraise
(
ValueError
,
ValueError
(
"imshp should be None or a tuple of "
"constant int values"
),
sys
.
exc_info
()[
2
])
self
.
kshp
=
tuple
(
kshp
)
if
kshp
else
(
None
,)
*
4
for
kshp_i
in
self
.
kshp
:
if
kshp_i
is
not
None
:
# Components of kshp should be constant or ints
try
:
get_scalar_constant_value
(
kshp_i
)
get_scalar_constant_value
(
kshp_i
,
only_process_constants
=
True
)
except
NotScalarConstantError
:
_logger
.
error
(
"kshp should be None or "
"a tuple of constant int values"
)
raise
reraise
(
ValueError
,
ValueError
(
"kshp should be None or a tuple of "
"constant int values"
),
sys
.
exc_info
()[
2
])
self
.
border_mode
=
border_mode
self
.
filter_flip
=
filter_flip
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
121ec69a
...
...
@@ -2,12 +2,16 @@ import numpy
import
unittest
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
import
theano
from
theano
import
tensor
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.nnet
import
corr
,
abstract_conv
as
conv
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d_gradInputs
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d_gradWeights
from
theano.tensor.nnet.conv
import
ConvOp
from
theano.tensor.nnet.corr
import
(
CorrMM
,
CorrMM_gradWeights
,
CorrMM_gradInputs
)
...
...
@@ -384,6 +388,53 @@ class TestCpuConv2d(BaseTestConv2d):
filter_flip
=
flip
)
def
test_constant_shapes
():
# Check that the `imshp` and `kshp` parameters of the AbstractConv Ops
# are rejected if not constant or None
dummy_t4
=
tensor
.
ftensor4
()
alloc_dummy_t4
=
tensor
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
)
dummy_shape
=
tensor
.
lvector
()
dummy_one_shape
=
tensor
.
ones
(
4
,
dtype
=
'int64'
)
constant_vec_shape
=
tensor
.
constant
([
3
,
5
,
7
,
11
])
tuple_shape
=
(
3
,
5
,
7
,
11
)
list_shape
=
list
(
tuple_shape
)
constant_list_shape
=
[
tensor
.
constant
(
i
,
dtype
=
'int64'
)
for
i
in
tuple_shape
]
constant_tuple_shape
=
tuple
(
constant_list_shape
)
bad_shapes
=
(
dummy_shape
,
dummy_one_shape
,
dummy_t4
.
shape
,
alloc_dummy_t4
.
shape
,
constant_vec_shape
,
)
good_shapes
=
(
constant_list_shape
,
constant_tuple_shape
,
tuple_shape
,
list_shape
)
ops_to_test
=
(
AbstractConv2d
,
AbstractConv2d_gradInputs
,
AbstractConv2d_gradWeights
)
for
op
in
ops_to_test
:
for
shp
in
bad_shapes
:
assert_raises
(
ValueError
,
op
,
imshp
=
shp
)
assert_raises
(
ValueError
,
op
,
kshp
=
shp
)
for
shp
in
good_shapes
:
op
(
imshp
=
shp
)
op
(
kshp
=
shp
)
class
TestConvTypes
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
input
=
tensor
.
ftensor4
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论