提交 bb3fe454 authored 作者: Dustin Webb's avatar Dustin Webb

Started adding infer_shape to cudnn related operators.

Conflicts: theano/sandbox/cuda/dnn.py
上级 0c11332c
...@@ -368,6 +368,31 @@ class GpuDnnConv(DnnBase, COp): ...@@ -368,6 +368,31 @@ class GpuDnnConv(DnnBase, COp):
# not connected to desc # not connected to desc
return [[1], [1], [0]] return [[1], [1], [0]]
def infer_shape(self, node, shape):
b = shape[0][0] # Number of inputs
h = shape[0][2] # Height of input feature maps
w = shape[0][3] # Width of input feature maps
nb = shape[1][0] # Number of output feature maps
kh = shape[1][2] # Height of each filter
kw = shape[1][3] # Width of each filter
padh = 0
padw = 0
sh = 1
sw = 1
desc = node.inputs[2].owner.op
if desc.border_mode == 'full':
padh = kh - 1
padw = kw - 1
sh = desc.subsample[0]
sw = desc.subsample[1]
return [(
b, nb,
(h + 2*padh - kh)/sh + 1,
(w + 2*padw - kw)/sw + 1
)]
class GpuDnnConvGradW(DnnBase, COp): class GpuDnnConvGradW(DnnBase, COp):
""" """
...@@ -655,6 +680,31 @@ class GpuDnnPool(DnnBase): ...@@ -655,6 +680,31 @@ class GpuDnnPool(DnnBase):
return Apply(self, [img, desc], return Apply(self, [img, desc],
[img.type()]) [img.type()])
def infer_shape(self, node, shape):
n = shape[0][0] # Number of inputs
h = shape[0][2] # Height of input feature maps
w = shape[0][3] # Width of input feature maps
nb = shape[1][0] # Number of output feature maps
kh = shape[1][2] # Height of each filter
kw = shape[1][3] # Width of each filter
padh = 0
padw = 0
sh = 1
sw = 1
desc = node.inputs[2].owner.op
if desc.border_mode == 'full':
padh = kh - 1
padw = kw - 1
sh = desc.stride[0]
sw = desc.stride[1]
return (
b, nb,
(h + 2*padh - kh)/sh + 1,
(w + 2*padw - kw)/sw + 1
)
def c_support_code_struct(self, node, name): def c_support_code_struct(self, node, name):
return """ return """
cudnnTensorDescriptor_t input%(name)s; cudnnTensorDescriptor_t input%(name)s;
...@@ -1016,6 +1066,12 @@ class GpuDnnSoftmaxBase(DnnBase): ...@@ -1016,6 +1066,12 @@ class GpuDnnSoftmaxBase(DnnBase):
for softmax_input in self.softmax_inputs] for softmax_input in self.softmax_inputs]
self.tensor_4d_descs.append('softmax_output') self.tensor_4d_descs.append('softmax_output')
def infer_shape(self, node, shape):
if isinstance(shape, list):
return [shape[0]]
else:
return shape
def _define_tensor4d_desc(self, name, id): def _define_tensor4d_desc(self, name, id):
return """ return """
cudnnTensorDescriptor_t %(id)s_%(name)s; cudnnTensorDescriptor_t %(id)s_%(name)s;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论