提交 5b569617 authored 作者: Frederic's avatar Frederic

Fix shape check in Conv2d

上级 7a78f453
...@@ -964,7 +964,7 @@ class ConvOp(OpenMPOp): ...@@ -964,7 +964,7 @@ class ConvOp(OpenMPOp):
return ['<numpy/noprefix.h>', '<iostream>', '<sstream>'] return ['<numpy/noprefix.h>', '<iostream>', '<sstream>']
def c_code_cache_version(self): def c_code_cache_version(self):
return (12, self.openmp, blas.blas_header_version()) return (13, self.openmp, blas.blas_header_version())
def c_support_code(self): def c_support_code(self):
return """ return """
...@@ -1158,21 +1158,21 @@ if(dim_zz[1] != %(self_outshp1)s!=0){ ...@@ -1158,21 +1158,21 @@ if(dim_zz[1] != %(self_outshp1)s!=0){
} }
// Check the size of the filter (sometimes constant in the graph) // Check the size of the filter (sometimes constant in the graph)
if(kerns_dim[1] %% %(self_imshp0)s!=0){ if(kerns_dim[1] != %(self_imshp0)s!=0){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the filter stack size (%%ld) at run time is different than at" "the filter stack size (%%ld) at run time is different than at"
" build time (%%ld) for the ConvOp.", " build time (%%ld) for the ConvOp.",
(long)kerns_dim[1], (long)%(self_imshp0)s); (long)kerns_dim[1], (long)%(self_imshp0)s);
%(fail)s; %(fail)s;
} }
if(kerns_dim[2] %% %(self_kshp0)s!=0){ if(kerns_dim[2] != %(self_kshp0)s!=0){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the number of rows in the filter (%%ld) at run time is different" "the number of rows in the filter (%%ld) at run time is different"
" than at build time (%%ld) for the ConvOp.", " than at build time (%%ld) for the ConvOp.",
(long)kerns_dim[2], (long)%(self_kshp0)s); (long)kerns_dim[2], (long)%(self_kshp0)s);
%(fail)s; %(fail)s;
} }
if(kerns_dim[3] %% %(self_kshp1)s!=0){ if(kerns_dim[3] != %(self_kshp1)s!=0){
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"the number of columns in the filter (%%ld) at run time is" "the number of columns in the filter (%%ld) at run time is"
" different than at build time (%%ld) for the ConvOp.", " different than at build time (%%ld) for the ConvOp.",
...@@ -1194,7 +1194,15 @@ if(kerns_dim[3] %% %(self_kshp1)s!=0){ ...@@ -1194,7 +1194,15 @@ if(kerns_dim[3] %% %(self_kshp1)s!=0){
dim_zz[1] = (int)ceil((dim_im[1]-dim_ker1+1)/float(%(self_dy)s)); dim_zz[1] = (int)ceil((dim_im[1]-dim_ker1+1)/float(%(self_dy)s));
} }
""" % d """ % d
d["assert_size"] = "" d["assert_size"] = """
// Check the stack size of the filter and images are equals
if(kerns_dim[1] != img2d_dim[1]){
PyErr_Format(PyExc_ValueError,
"the filter stack size (%%ld) and image stack size (%%ld) differ",
(long)kerns_dim[1], (long)img2d_dim[1]);
%(fail)s;
}
""" % sub
if self.kshp_logical_top_aligned: if self.kshp_logical_top_aligned:
d["self_kshp_logical_offset_r"] = 0 d["self_kshp_logical_offset_r"] = 0
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论