Remove experiemental conv_2d_offset code.

上级 b3b502cd
...@@ -83,93 +83,6 @@ def conv2d(input, filters, image_shape=None, filter_shape=None, ...@@ -83,93 +83,6 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
return op(input, filters) return op(input, filters)
def conv2d_offset(input, filters, image_shape=None, filter_shape=None,
border_mode='valid', subsample=(1,1), offsets = [], **kargs):
"""
Build a graph for nnet convolutions with subsampling and offsetting.
Refer to conv2d for a general explanation of the context.
*Subsampling* means, we only compute convolutions at a fraction of the
sites. *Offsetting* convolutions in the context of subsampling means not
computing all of them at the same sites (starting in upper left corner).
This function allows offsets to be used.
Most parameters are shared with conv2d, except:
:param offsets: list of 2-tuples that specify sites wrt the subsampling
scheme. The filters are split evenly accross the different sites. For
example with subsample (2,2) we can use the sites [(0,0), (0,1), (1,0),
(1,1)]. An empty list is interpreted as all offsets.
"""
# There should be subsampling for offsets to make any sense.
if not (subsample[0] > 1 or subsample[1] > 1):
raise ValueError('conv2d_offset requires subsampling.')
# Haven't thought about this case.
if numpy.any(numpy.array(subsample) > filter_shape[2:]):
raise ValueError('conv2d_offset subsample greater than filter shape. Not supported?')
# No offsets specified is interpreted as all offsets.
if len(offsets) == 0:
offsets = []
for i in range(subsample[0]):
for j in range(subsample[1]):
offsets.append((i,j))
# Find the largest offsets in both image dimensions. Used to determine the
# size of the image used.
max_offset = list(offsets[0])
for offset in offsets:
if offset[0] > max_offset[0]:
max_offset[0] = offset[0]
if offset[1] > max_offset[1]:
max_offset[1] = offset[1]
if not (max_offset[0] < subsample[0] and max_offset[1] < subsample[1]):
raise ValueError('conv2d_offset: invalid offset sites.')
# Determine the reduced size of input so all feature maps get an input of
# the same size.
sub_image_shape = list(image_shape)
sub_image_shape[2] -= max_offset[0]
sub_image_shape[3] -= max_offset[1]
# Determine number of filters per offset position.
if (filter_shape[0] % len(offsets)) != 0:
print 'nfilts ', filter_shape[0], ' noffsets ', len(offsets)
raise ValueError('conv2d_offset: invalid number of filters wrt offsets.')
n_filters = filter_shape[0] / len(offsets)
sub_filter_shape = list(filter_shape)
sub_filter_shape[0] = n_filters
# Call conv2d at each offset using same fraction of kernels.
outputs = []
for i, offset in enumerate(offsets):
# Crop the input so all offsets get an input of the same size.
sub_input = input[:, :, offset[0]:sub_image_shape[2] + offset[0],
offset[1]:sub_image_shape[3] + offset[1]]
# Grab part of the filters.
sub_filters = filters[i*n_filters:(i+1)*n_filters]
out = conv2d(sub_input, sub_filters, sub_image_shape, sub_filter_shape,
border_mode=border_mode, subsample=subsample, **kargs)
outputs.append(out)
# Join the outputs on the leading axis.
if len(outputs) > 1:
output = tensor.join(1, *outputs)
else:
output = outputs[0]
outshp = ConvOp.getOutputShape(sub_image_shape[2:], filter_shape[2:], subsample, border_mode)
return [output, outshp]
class ConvOp(Op): class ConvOp(Op):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论