提交 4e25e6c1 authored 作者: Vikram's avatar Vikram

Errors fixed

上级 caccc5f8
...@@ -123,22 +123,29 @@ def get_conv_shape_1axis(image_shape, kernel_shape, border_mode, ...@@ -123,22 +123,29 @@ def get_conv_shape_1axis(image_shape, kernel_shape, border_mode,
# Implicit dilated kernel shape # Implicit dilated kernel shape
dil_kernel_shape = (kernel_shape - 1) * dilation + 1 dil_kernel_shape = (kernel_shape - 1) * dilation + 1
if border_mode == "half": if border_mode == "half":
pad = dil_kernel_shape // 2 pad_l = pad_r = dil_kernel_shape // 2
elif border_mode == "full": elif border_mode == "full":
pad = dil_kernel_shape - 1 pad_l = pad_r = dil_kernel_shape - 1
elif border_mode == "valid": elif border_mode == "valid":
pad = 0 pad_l = pad_r = 0
else: else:
pad = border_mode if isinstance(border_mode, tuple):
if pad < 0: pad_l, pad_r = border_mode
else:
pad_l = pad_r = border_mode
if pad_l < 0 or pad_r < 0:
raise ValueError("border_mode must be >= 0") raise ValueError("border_mode must be >= 0")
# In case of symbolic shape, we want to build the smallest graph # In case of symbolic shape, we want to build the smallest graph
# (image_shape + 2 * pad - dil_kernel_shape) // subsample + 1 # (image_shape + 2 * pad - dil_kernel_shape) // subsample + 1
if pad == 0: if pad_l == 0 and pad_r == 0:
out_shp = (image_shape - dil_kernel_shape) out_shp = (image_shape - dil_kernel_shape)
elif pad_l == 0:
out_shp = (image_shape + pad_l - dil_kernel_shape)
elif pad_r == 0:
out_shp = (image_shape + pad_r - dil_kernel_shape)
else: else:
out_shp = (image_shape + 2 * pad - dil_kernel_shape) out_shp = (image_shape + pad_l + pad_r - dil_kernel_shape)
if subsample != 1: if subsample != 1:
out_shp = out_shp // subsample out_shp = out_shp // subsample
out_shp = out_shp + 1 out_shp = out_shp + 1
...@@ -252,9 +259,16 @@ def get_conv_gradweights_shape_1axis(image_shape, top_shape, border_mode, ...@@ -252,9 +259,16 @@ def get_conv_gradweights_shape_1axis(image_shape, top_shape, border_mode,
elif border_mode == "valid": elif border_mode == "valid":
kernel_shape = image_shape - top_shape kernel_shape = image_shape - top_shape
else: else:
if isinstance(border_mode, integer_types):
if border_mode < 0: if border_mode < 0:
raise ValueError("border_mode must be >= 0") raise ValueError("border_mode must be >= 0")
kernel_shape = (image_shape + 2 * border_mode - top_shape) pad_l = pad_r = border_mode
elif isinstance(border_mode, tuple):
if min(border_mode) < 0:
raise ValueError("border_mode must be >= 0")
pad_l, pad_r = border_mode
kernel_shape = (image_shape + pad_l + pad_r - top_shape)
if dilation > 1: if dilation > 1:
kernel_shape = kernel_shape / dilation kernel_shape = kernel_shape / dilation
...@@ -363,23 +377,30 @@ def get_conv_gradinputs_shape_1axis(kernel_shape, top_shape, border_mode, ...@@ -363,23 +377,30 @@ def get_conv_gradinputs_shape_1axis(kernel_shape, top_shape, border_mode,
# Implicit dilated kernel shape # Implicit dilated kernel shape
dil_kernel_shape = (kernel_shape - 1) * dilation + 1 dil_kernel_shape = (kernel_shape - 1) * dilation + 1
if border_mode == "half": if border_mode == "half":
pad = dil_kernel_shape // 2 pad_l = pad_r = dil_kernel_shape // 2
elif border_mode == "full": elif border_mode == "full":
pad = dil_kernel_shape - 1 pad_l = pad_r = dil_kernel_shape - 1
elif border_mode == "valid": elif border_mode == "valid":
pad = 0 pad_l = pad_r = 0
else:
if isinstance(border_mode, tuple):
pad_l, pad_r = border_mode
else: else:
pad = border_mode pad_l = pad_r = border_mode
if pad < 0: if pad_l < 0 or pad_r < 0:
raise ValueError("border_mode must be >= 0") raise ValueError("border_mode must be >= 0")
# In case of symbolic shape, we want to build the smallest graph # In case of symbolic shape, we want to build the smallest graph
# image_shape = (top_shape - 1) * s - 2 * pad + dil_kernel_shape + a # image_shape = (top_shape - 1) * s - 2 * pad + dil_kernel_shape + a
# where 0 <= a < subsample, but we have checked that subsample == 1 # where 0 <= a < subsample, but we have checked that subsample == 1
if pad == 0: if pad_l == 0 and pad_r == 0:
image_shape = (top_shape + dil_kernel_shape - 1) image_shape = (top_shape + dil_kernel_shape - 1)
elif pad_l == 0:
image_shape = (top_shape - pad_l + dil_kernel_shape - 1)
elif pad_r == 0:
image_shape = (top_shape - pad_r + dil_kernel_shape - 1)
else: else:
image_shape = (top_shape - 2 * pad + dil_kernel_shape - 1) image_shape = (top_shape - pad_l - pad_r + dil_kernel_shape - 1)
return image_shape return image_shape
...@@ -1762,7 +1783,7 @@ class BaseAbstractConv(Op): ...@@ -1762,7 +1783,7 @@ class BaseAbstractConv(Op):
'invalid border_mode {} which must be a ' 'invalid border_mode {} which must be a '
'tuple of length {}'.format(border_mode, convdim)) 'tuple of length {}'.format(border_mode, convdim))
for mode in border_mode: for mode in border_mode:
if not((isinstance(mode, integer_types) and mode > 0) or if not((isinstance(mode, integer_types) and mode >= 0) or
(isinstance(mode, tuple) and len(mode) == 2 and (isinstance(mode, tuple) and len(mode) == 2 and
min(mode) >= 0)): min(mode) >= 0)):
raise ValueError( raise ValueError(
...@@ -2042,7 +2063,7 @@ class AbstractConv(BaseAbstractConv): ...@@ -2042,7 +2063,7 @@ class AbstractConv(BaseAbstractConv):
'tuple of length {}'.format(mode, self.convdim)) 'tuple of length {}'.format(mode, self.convdim))
border = () border = ()
for m in mode: for m in mode:
if isinstance(m, integer_types) and m > 0: if isinstance(m, integer_types) and m >= 0:
border += ((m, m),) border += ((m, m),)
elif isinstance(m, tuple) and len(m) == 2 and \ elif isinstance(m, tuple) and len(m) == 2 and \
min(m) >= 0: min(m) >= 0:
...@@ -2329,7 +2350,7 @@ class AbstractConv_gradWeights(BaseAbstractConv): ...@@ -2329,7 +2350,7 @@ class AbstractConv_gradWeights(BaseAbstractConv):
'tuple of length {}'.format(mode, self.convdim)) 'tuple of length {}'.format(mode, self.convdim))
border = () border = ()
for m in mode: for m in mode:
if isinstance(m, integer_types) and m > 0: if isinstance(m, integer_types) and m >= 0:
border += ((m, m),) border += ((m, m),)
elif isinstance(m, tuple) and len(m) == 2 and \ elif isinstance(m, tuple) and len(m) == 2 and \
min(m) >= 0: min(m) >= 0:
...@@ -2659,7 +2680,7 @@ class AbstractConv_gradInputs(BaseAbstractConv): ...@@ -2659,7 +2680,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
'tuple of length {}'.format(mode, self.convdim)) 'tuple of length {}'.format(mode, self.convdim))
border = () border = ()
for m in mode: for m in mode:
if isinstance(m, integer_types) and m > 0: if isinstance(m, integer_types) and m >= 0:
border += ((m, m),) border += ((m, m),)
elif isinstance(m, tuple) and len(m) == 2 and \ elif isinstance(m, tuple) and len(m) == 2 and \
min(m) >= 0: min(m) >= 0:
...@@ -2696,7 +2717,7 @@ class AbstractConv_gradInputs(BaseAbstractConv): ...@@ -2696,7 +2717,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
dil_kernshp = tuple((kern.shape[-self.convdim + i] - 1) * self.filter_dilation[i] + 1 dil_kernshp = tuple((kern.shape[-self.convdim + i] - 1) * self.filter_dilation[i] + 1
for i in range(self.convdim)) for i in range(self.convdim))
pad = (0,) * self.convdim pad = ((0, 0),) * self.convdim
if mode == "full": if mode == "full":
pad = tuple((dil_kernshp[i] - 1,) * 2 for i in range(self.convdim)) pad = tuple((dil_kernshp[i] - 1,) * 2 for i in range(self.convdim))
elif mode == "half": elif mode == "half":
......
...@@ -75,7 +75,7 @@ class BaseCorrMM(gof.OpenMPOp): ...@@ -75,7 +75,7 @@ class BaseCorrMM(gof.OpenMPOp):
'tuple of length 2'.format(border_mode)) 'tuple of length 2'.format(border_mode))
border = () border = ()
for mode in border_mode: for mode in border_mode:
if isinstance(mode, integer_types) and mode > 0: if isinstance(mode, integer_types) and mode >= 0:
border += ((mode, mode),) border += ((mode, mode),)
elif isinstance(mode, tuple) and len(mode) == 2 and \ elif isinstance(mode, tuple) and len(mode) == 2 and \
min(mode) >= 0: min(mode) >= 0:
...@@ -489,8 +489,8 @@ class BaseCorrMM(gof.OpenMPOp): ...@@ -489,8 +489,8 @@ class BaseCorrMM(gof.OpenMPOp):
// height and width: bottom = (top - 1) * sample + (weights-1)*dil + 1 - 2*pad // height and width: bottom = (top - 1) * sample + (weights-1)*dil + 1 - 2*pad
out_dim[0] = (npy_intp)PyArray_DIMS(top)[0]; out_dim[0] = (npy_intp)PyArray_DIMS(top)[0];
out_dim[1] = (npy_intp)PyArray_DIMS(weights)[wdim-3] * numgroups; out_dim[1] = (npy_intp)PyArray_DIMS(weights)[wdim-3] * numgroups;
out_dim[2] = (npy_intp)((%(height)s != -1) ? %(height)s : (PyArray_DIMS(top)[2] - 1) * dH + (PyArray_DIMS(weights)[wdim-2]-1)*dilH + 1 - 2*padH); out_dim[2] = (npy_intp)((%(height)s != -1) ? %(height)s : (PyArray_DIMS(top)[2] - 1) * dH + (PyArray_DIMS(weights)[wdim-2]-1)*dilH + 1 - padH_l - padH_r);
out_dim[3] = (npy_intp)((%(width)s != -1) ? %(width)s : (PyArray_DIMS(top)[3] - 1) * dW + (PyArray_DIMS(weights)[wdim-1]-1)*dilW + 1 - 2*padW); out_dim[3] = (npy_intp)((%(width)s != -1) ? %(width)s : (PyArray_DIMS(top)[3] - 1) * dW + (PyArray_DIMS(weights)[wdim-1]-1)*dilW + 1 - padW_l - padW_r);
if (unshared) { if (unshared) {
if (out_dim[0] < 0 || out_dim[1] < 0 || out_dim[2] <= 0 || out_dim[3] <= 0) if (out_dim[0] < 0 || out_dim[1] < 0 || out_dim[2] <= 0 || out_dim[3] <= 0)
{ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论