Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a22086b0
提交
a22086b0
authored
10月 14, 2011
作者:
Frederic
提交者:
David Warde-Farley
10月 15, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add check that shape gived to ConvOp are the one reveiced in input.
上级
bbd9e02f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
130 行增加
和
28 行删除
+130
-28
conv.py
theano/tensor/nnet/conv.py
+78
-25
test_conv.py
theano/tensor/nnet/tests/test_conv.py
+52
-3
没有找到文件。
theano/tensor/nnet/conv.py
浏览文件 @
a22086b0
...
...
@@ -858,7 +858,7 @@ class ConvOp(Op):
return
[
'<numpy/noprefix.h>'
,
'<iostream>'
,
'<sstream>'
]
def
c_code_cache_version
(
self
):
return
(
4
)
return
(
5
)
def
c_support_code
(
self
):
return
"""
...
...
@@ -942,6 +942,76 @@ using namespace std;
d
[
"all_shape"
]
=
"1"
d
[
"dim_zz_const"
]
=
"const"
d
[
"dim_zz_affect"
]
=
""
d
[
"assert_size"
]
=
"""
// Check the batch size and the number of kernel (sometimes constant in the graph)
if(img2d_dim[0] !=
%(self_bsize)
s!=0){
PyErr_Format(PyExc_ValueError,
"the batch size in the image(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)img2d_dim[0], (long)
%(self_bsize)
s);
%(fail)
s;
}
if(kerns_dim[0] !=
%(self_nkern)
s!=0){
PyErr_Format(PyExc_ValueError,
"the number of kernel in the filter(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)kerns_dim[0], (long)
%(self_nkern)
s);
%(fail)
s;
}
// Check the size of the image (sometimes constant in the graph)
if(img2d_dim[1] !=
%(self_imshp0)
s){
PyErr_Format(PyExc_ValueError,
"the stack size in the image(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)img2d_dim[1], (long)
%(self_imshp0)
s);
%(fail)
s;
}
if(img2d_dim[2] !=
%(self_imshp1)
s){
PyErr_Format(PyExc_ValueError,
"the number of row in the image(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)img2d_dim[2], (long)
%(self_imshp1)
s);
%(fail)
s;
}
if(img2d_dim[3] !=
%(self_imshp2)
s){
PyErr_Format(PyExc_ValueError,
"the number of col in the image(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)img2d_dim[3], (long)
%(self_imshp2)
s);
%(fail)
s;
}
// Check the size of the output (sometimes constant in the graph)
if(dim_zz[0] !=
%(self_outshp0)
s!=0){
PyErr_Format(PyExc_ValueError,
"the precomputed number of row in the output(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)dim_zz[0], (long)
%(self_outshp0)
s);
%(fail)
s;
}
if(dim_zz[1] !=
%(self_outshp1)
s!=0){
PyErr_Format(PyExc_ValueError,
"the precomputed number of col in the output(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)dim_zz[1], (long)
%(self_outshp1)
s);
%(fail)
s;
}
// Check the size of the filter (sometimes constant in the graph)
if(kerns_dim[1]
%% %(self_imshp0)
s!=0){
PyErr_Format(PyExc_ValueError,
"the stack size in the filter(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)kerns_dim[1], (long)
%(self_imshp0)
s);
%(fail)
s;
}
if(kerns_dim[2]
%% %(self_kshp0)
s!=0){
PyErr_Format(PyExc_ValueError,
"the number of row in the filter(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)kerns_dim[2], (long)
%(self_kshp0)
s);
%(fail)
s;
}
if(kerns_dim[3]
%% %(self_kshp1)
s!=0){
PyErr_Format(PyExc_ValueError,
"the number of columns in the filter(
%%
ld) at run time is different then at build time(
%%
ld) for the ConvOp.",
(long)kerns_dim[3], (long)
%(self_kshp1)
s);
%(fail)
s;
}
"""
%
(
locals
())
else
:
d
[
"self_bsize"
]
=
"
%(img2d)
s->dimensions[0]"
%
d
d
[
"self_nkern"
]
=
"
%(filtersflipped)
s->dimensions[0]"
%
d
...
...
@@ -964,6 +1034,7 @@ using namespace std;
dim_zz[1] = (int)ceil((dim_im[1]-dim_ker1+1)/float(
%(self_dy)
s));
}
"""
%
d
d
[
"assert_size"
]
=
""
if
self
.
kshp_logical_top_aligned
:
d
[
"self_kshp_logical_offset_r"
]
=
0
...
...
@@ -1072,6 +1143,8 @@ if(%(filtersflipped)s->nd==3){
%(fail)
s;
}
%(assert_size)
s
img2d = PyArray_Newshape(
%(img2d)
s,&img2d_shape, PyArray_CORDER);
img2d_arr = (PyArrayObject*)img2d;
if ((img2d_arr->strides[3] != (npy_intp)sizeof(
%(type)
s))
...
...
@@ -1355,6 +1428,8 @@ if ((!%(z)s)
PyArray_FILLWBYTE((PyObject*)
%(z)
s,0);
}
%(assert_size)
s
int Os[2];
Os[0] = dim_im[0]-dim_ker0+1;
Os[1] = dim_im[1]-dim_ker1+1;
...
...
@@ -1555,18 +1630,7 @@ if(%(filtersflipped)s->nd==3){
%(fail)
s;
}
if(img2d_dim[0]
%% %(self_bsize)
s!=0){
PyErr_Format(PyExc_ValueError,
"the batch size of the image(
%%
ld) must be a multiple of the bsize value at ConvOp construction(
%%
ld).",
(long)img2d_dim[0],(long)
%(self_bsize)
s);
%(fail)
s;
}
if(kerns_dim[0]
%% %(self_nkern)
s!=0){
PyErr_Format(PyExc_ValueError,
"the number of kernel(
%%
ld) must be a multiple of the nkern value at ConvOp construction(
%%
ld).",
(long)kerns_dim[0], (long)
%(self_nkern)
s);
%(fail)
s;
}
%(assert_size)
s
img2d = PyArray_Newshape(
%(img2d)
s,&img2d_shape, PyArray_CORDER);
img2d_arr = (PyArrayObject*)img2d;
...
...
@@ -1799,18 +1863,7 @@ if(%(filtersflipped)s->nd==3){
%(fail)
s;
}
if(img2d_dim[0] !=
%(self_bsize)
s){
PyErr_Format(PyExc_ValueError,
"the batch size of the image(
%%
ld) must be a multiple of the bsize value at ConvOp construction(
%%
ld).",
(long)img2d_dim[0],(long)
%(self_bsize)
s);
%(fail)
s;
}
if(kerns_dim[0] !=
%(self_nkern)
s){
PyErr_Format(PyExc_ValueError,
"the number of kernel(
%%
ld) must be a multiple of the nkern value at ConvOp construction(
%%
ld).",
(long)kerns_dim[0], (long)
%(self_nkern)
s);
%(fail)
s;
}
%(assert_size)
s
img2d = PyArray_Newshape(
%(img2d)
s,&img2d_shape, PyArray_CORDER);
img2d_arr = (PyArrayObject*)img2d;
...
...
theano/tensor/nnet/tests/test_conv.py
浏览文件 @
a22086b0
...
...
@@ -220,9 +220,58 @@ class TestConv2D(unittest.TestCase):
"""
Tests scenario where filter_shape[1] != input_shape[1]
"""
def
f
():
self
.
validate
((
3
,
2
,
8
,
8
),
(
4
,
3
,
5
,
5
),
'valid'
)
self
.
assertRaises
(
AssertionError
,
f
)
self
.
assertRaises
(
AssertionError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
3
,
5
,
5
),
'valid'
)
def
test_invalid_input_shape
(
self
):
"""
Tests that when the shape gived at build time is not the same as
run time we raise an error
"""
for
unroll_batch
in
[
None
,
1
,
3
]:
for
unroll_kern
in
[
None
,
2
,
4
]:
for
unroll_patch
in
[
None
,
True
,
False
]:
for
mode
in
[
'valid'
,
'full'
]:
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_image_shape
=
(
2
,
2
,
8
,
8
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_image_shape
=
(
3
,
1
,
8
,
8
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_image_shape
=
(
3
,
2
,
7
,
8
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_image_shape
=
(
3
,
2
,
8
,
7
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_filter_shape
=
(
3
,
2
,
5
,
5
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_filter_shape
=
(
4
,
1
,
5
,
5
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_filter_shape
=
(
4
,
2
,
6
,
5
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
self
.
assertRaises
(
ValueError
,
self
.
validate
,
(
3
,
2
,
8
,
8
),
(
4
,
2
,
5
,
5
),
mode
,
N_filter_shape
=
(
4
,
2
,
5
,
6
),
unroll_batch
=
unroll_batch
,
unroll_kern
=
unroll_kern
,
unroll_patch
=
unroll_patch
)
def
test_missing_info
(
self
):
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论