提交 1b01e2f5 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Additional pep8 fixes

上级 bd5dc5a8
...@@ -4,7 +4,7 @@ Planned: ...@@ -4,7 +4,7 @@ Planned:
DownsampleFactorMax, DownsampleAvg, DownsampleSoftmax. DownsampleFactorMax, DownsampleAvg, DownsampleSoftmax.
""" """
#This file should move along with conv.py # This file should move along with conv.py
import __builtin__ import __builtin__
import numpy import numpy
...@@ -196,8 +196,9 @@ class DownsampleFactorMax(Op): ...@@ -196,8 +196,9 @@ class DownsampleFactorMax(Op):
'padding_h and padding_w must be smaller than strides') 'padding_h and padding_w must be smaller than strides')
def __str__(self): def __str__(self):
return '%s{%s, %s, %s, %s}' % (self.__class__.__name__, return '%s{%s, %s, %s, %s}' % (
self.ds, self.st, self.ignore_border, self.padding) self.__class__.__name__,
self.ds, self.st, self.ignore_border, self.padding)
def make_node(self, x): def make_node(self, x):
if x.type.ndim != 4: if x.type.ndim != 4:
...@@ -216,13 +217,14 @@ class DownsampleFactorMax(Op): ...@@ -216,13 +217,14 @@ class DownsampleFactorMax(Op):
z_shape = self.out_shape(x.shape, self.ds, self.ignore_border, self.st, z_shape = self.out_shape(x.shape, self.ds, self.ignore_border, self.st,
self.padding) self.padding)
if (z[0] is None) or (z[0].shape != z_shape): if (z[0] is None) or (z[0].shape != z_shape):
z[0] = numpy.empty(self.out_shape(x.shape, self.ds, z[0] = numpy.empty(
self.ignore_border, self.st, self.padding), self.out_shape(x.shape, self.ds, self.ignore_border,
dtype=x.dtype) self.st, self.padding),
dtype=x.dtype)
zz = z[0] zz = z[0]
#number of pooling output rows # number of pooling output rows
pr = zz.shape[-2] pr = zz.shape[-2]
#number of pooling output cols # number of pooling output cols
pc = zz.shape[-1] pc = zz.shape[-1]
ds0, ds1 = self.ds ds0, ds1 = self.ds
st0, st1 = self.st st0, st1 = self.st
...@@ -356,8 +358,9 @@ class DownsampleFactorMaxGrad(Op): ...@@ -356,8 +358,9 @@ class DownsampleFactorMaxGrad(Op):
self.padding = tuple(padding) self.padding = tuple(padding)
def __str__(self): def __str__(self):
return '%s{%s, %s, %s, %s}' % (self.__class__.__name__, return '%s{%s, %s, %s, %s}' % (
self.ds, self.st, self.ignore_border, self.padding) self.__class__.__name__,
self.ds, self.st, self.ignore_border, self.padding)
def make_node(self, x, maxout, gz): def make_node(self, x, maxout, gz):
# make_node should only be called by the grad function of # make_node should only be called by the grad function of
...@@ -371,9 +374,9 @@ class DownsampleFactorMaxGrad(Op): ...@@ -371,9 +374,9 @@ class DownsampleFactorMaxGrad(Op):
def perform(self, node, inp, out): def perform(self, node, inp, out):
x, maxout, gz = inp x, maxout, gz = inp
gx_stg, = out gx_stg, = out
#number of pooling output rows # number of pooling output rows
pr = maxout.shape[-2] pr = maxout.shape[-2]
#number of pooling output cols # number of pooling output cols
pc = maxout.shape[-1] pc = maxout.shape[-1]
ds0, ds1 = self.ds ds0, ds1 = self.ds
st0, st1 = self.st st0, st1 = self.st
...@@ -411,15 +414,15 @@ class DownsampleFactorMaxGrad(Op): ...@@ -411,15 +414,15 @@ class DownsampleFactorMaxGrad(Op):
ggx, = grads ggx, = grads
if self.padding == (0, 0): if self.padding == (0, 0):
return [theano.tensor.zeros_like(x), return [theano.tensor.zeros_like(x),
theano.tensor.zeros_like(maxout), theano.tensor.zeros_like(maxout),
DownsampleFactorMaxGradGrad( DownsampleFactorMaxGradGrad(
self.ds, ignore_border=self.ignore_border, self.ds, ignore_border=self.ignore_border,
st=self.st)(x, maxout, ggx)] st=self.st)(x, maxout, ggx)]
else: else:
return [theano.tensor.zeros_like(x), return [theano.tensor.zeros_like(x),
theano.tensor.zeros_like(maxout), theano.tensor.zeros_like(maxout),
theano.gradients.grad_not_implemented( theano.gradients.grad_not_implemented(
self, 2, gz, 'Hessian not implemented with padding')] self, 2, gz, 'Hessian not implemented with padding')]
def c_code(self, node, name, inp, out, sub): def c_code(self, node, name, inp, out, sub):
if self.ds != self.st: if self.ds != self.st:
...@@ -635,9 +638,9 @@ class DownsampleFactorMaxGradGrad(Op): ...@@ -635,9 +638,9 @@ class DownsampleFactorMaxGradGrad(Op):
dtype=x.dtype) dtype=x.dtype)
ggz = z[0] ggz = z[0]
#number of pooling output rows # number of pooling output rows
pr = ggz.shape[-2] pr = ggz.shape[-2]
#number of pooling output cols # number of pooling output cols
pc = ggz.shape[-1] pc = ggz.shape[-1]
ds0, ds1 = self.ds ds0, ds1 = self.ds
st0, st1 = self.st st0, st1 = self.st
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论