提交 92b57e1f authored 作者: Nicolas Ballas's avatar Nicolas Ballas

check border_mode in the perform methods

上级 bb964aaf
...@@ -506,6 +506,13 @@ class AbstractConv2d(BaseAbstractConv2d): ...@@ -506,6 +506,13 @@ class AbstractConv2d(BaseAbstractConv2d):
o, = out_ o, = out_
mode = self.border_mode mode = self.border_mode
if not ((isinstance(mode, tuple) and min(mode) >= 0) or
mode in ('valid', 'full', 'half')):
raise ValueError(
'invalid border_mode {}, which must be either '
'"valid", "full", "half", an integer or a pair of'
' integers'.format(mode))
if mode == "full": if mode == "full":
mode = (kern.shape[2] - 1, kern.shape[3] - 1) mode = (kern.shape[2] - 1, kern.shape[3] - 1)
elif mode == "half": elif mode == "half":
...@@ -626,6 +633,13 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d): ...@@ -626,6 +633,13 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
o, = out_ o, = out_
mode = self.border_mode mode = self.border_mode
if not ((isinstance(mode, tuple) and min(mode) >= 0) or
mode in ('valid', 'full', 'half')):
raise ValueError(
'invalid border_mode {}, which must be either '
'"valid", "full", "half", an integer or a pair of'
' integers'.format(mode))
if mode == "full": if mode == "full":
mode = (shape[0] - 1, shape[1] - 1) mode = (shape[0] - 1, shape[1] - 1)
elif mode == "half": elif mode == "half":
...@@ -749,8 +763,14 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d): ...@@ -749,8 +763,14 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
o, = out_ o, = out_
mode = self.border_mode mode = self.border_mode
pad_h, pad_w = 0, 0 if not ((isinstance(mode, tuple) and min(mode) >= 0) or
mode in ('valid', 'full', 'half')):
raise ValueError(
'invalid border_mode {}, which must be either '
'"valid", "full", "half", an integer or a pair of'
' integers'.format(mode))
pad_h, pad_w = 0, 0
if mode == "full": if mode == "full":
pad_h, pad_w = (kern.shape[2] - 1, kern.shape[3] - 1) pad_h, pad_w = (kern.shape[2] - 1, kern.shape[3] - 1)
elif mode == "half": elif mode == "half":
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论