提交 72fc02e2 authored 作者: Iban Harlouchet's avatar Iban Harlouchet 提交者: Frederic

flake8 for theano/tensor/nnet/ConvTransp3D.py

上级 692f9012
from __future__ import print_function from __future__ import print_function
import numpy as N import numpy as N
from six.moves import xrange from six.moves import xrange
import theano
from theano.tensor import basic as T from theano.tensor import basic as T
from theano.misc import strutil from theano.misc import strutil
import theano
from theano.gradient import grad_undefined from theano.gradient import grad_undefined
from theano.gradient import DisconnectedType from theano.gradient import DisconnectedType
from theano.tensor.nnet.Conv3D import conv3D
from theano.tensor.nnet.ConvGrad3D import convGrad3D
class ConvTransp3D(theano.Op): class ConvTransp3D(theano.Op):
...@@ -31,12 +35,15 @@ class ConvTransp3D(theano.Op): ...@@ -31,12 +35,15 @@ class ConvTransp3D(theano.Op):
else: else:
RShape_ = T.as_tensor_variable([-1, -1, -1]) RShape_ = T.as_tensor_variable([-1, -1, -1])
return theano.Apply(self, inputs=[W_, b_, d_, H_, RShape_], outputs=[ T.TensorType(H_.dtype, (False, False, False, False, False))() ] ) return theano.Apply(self,
inputs=[W_, b_, d_, H_, RShape_],
outputs=[T.TensorType(H_.dtype,
(False, False, False, False, False))()])
def infer_shape(self, node, input_shapes): def infer_shape(self, node, input_shapes):
W, b, d, H, RShape = node.inputs W, b, d, H, RShape = node.inputs
W_shape, b_shape, d_shape, H_shape, RShape_shape = input_shapes W_shape, b_shape, d_shape, H_shape, RShape_shape = input_shapes
return [(H_shape[0], RShape[0], RShape[1], RShape[2], W_shape[4])] return [(H_shape[0], RShape[0], RShape[1], RShape[2], W_shape[4])]
def connection_pattern(self, node): def connection_pattern(self, node):
return [[True], [True], [True], [True], [False]] return [[True], [True], [True], [True], [False]]
...@@ -73,11 +80,13 @@ class ConvTransp3D(theano.Op): ...@@ -73,11 +80,13 @@ class ConvTransp3D(theano.Op):
else: else:
b_name = 'anon_b' b_name = 'anon_b'
dCdW.name = 'ConvTransp3D_dCdW.H='+H_name+',dCdR='+dCdR_name+',W='+W_name dCdW.name = ('ConvTransp3D_dCdW.H=' + H_name + ',dCdR=' + dCdR_name +
dCdb.name = 'ConvTransp3D_dCdb.H='+H_name+',dCdR='+dCdR_name+',W='+W_name+',b='+b_name ',W=' + W_name)
dCdb.name = ('ConvTransp3D_dCdb.H=' + H_name + ',dCdR=' + dCdR_name +
',W=' + W_name + ',b=' + b_name)
dCdH.name = 'ConvTransp3D_dCdH.H=' + H_name + ',dCdR=' + dCdR_name dCdH.name = 'ConvTransp3D_dCdH.H=' + H_name + ',dCdR=' + dCdR_name
return [dCdW, dCdb, dCdd, dCdH, dCdRShape] return [dCdW, dCdb, dCdd, dCdH, dCdRShape]
def perform(self, node, inputs, output_storage): def perform(self, node, inputs, output_storage):
W, b, d, H, RShape = inputs W, b, d, H, RShape = inputs
...@@ -335,7 +344,7 @@ def computeR(W, b, d, H, Rshape=None): ...@@ -335,7 +344,7 @@ def computeR(W, b, d, H, Rshape=None):
assert len(b.shape) == 1 assert len(b.shape) == 1
assert len(d) == 3 assert len(d) == 3
outputChannels, filterHeight, filterWidth, filterDur, \ outputChannels, filterHeight, filterWidth, filterDur, \
inputChannels = W.shape inputChannels = W.shape
batchSize, outputHeight, outputWidth, outputDur, \ batchSize, outputHeight, outputWidth, outputDur, \
outputChannelsAgain = H.shape outputChannelsAgain = H.shape
...@@ -367,7 +376,7 @@ def computeR(W, b, d, H, Rshape=None): ...@@ -367,7 +376,7 @@ def computeR(W, b, d, H, Rshape=None):
# print "video size: "+str((videoHeight, videoWidth, videoDur)) # print "video size: "+str((videoHeight, videoWidth, videoDur))
R = N.zeros((batchSize, videoHeight, R = N.zeros((batchSize, videoHeight,
videoWidth, videoDur, inputChannels), dtype=H.dtype) videoWidth, videoDur, inputChannels), dtype=H.dtype)
# R[i,j,r,c,t] = b_j + sum_{rc,rk | d \circ rc + rk = r} sum_{cc,ck | ...} sum_{tc,tk | ...} sum_k W[k, j, rk, ck, tk] * H[i,k,rc,cc,tc] # R[i,j,r,c,t] = b_j + sum_{rc,rk | d \circ rc + rk = r} sum_{cc,ck | ...} sum_{tc,tk | ...} sum_k W[k, j, rk, ck, tk] * H[i,k,rc,cc,tc]
for i in xrange(0, batchSize): for i in xrange(0, batchSize):
...@@ -404,8 +413,8 @@ def computeR(W, b, d, H, Rshape=None): ...@@ -404,8 +413,8 @@ def computeR(W, b, d, H, Rshape=None):
if tk < 0: if tk < 0:
break break
R[ R[i, r, c, t, j] += N.dot(
i, r, c, t, j] += N.dot(W[:, rk, ck, tk, j], H[i, rc, cc, tc, :] ) W[:, rk, ck, tk, j], H[i, rc, cc, tc, :])
tc += 1 tc += 1
"" # close loop over tc "" # close loop over tc
...@@ -421,7 +430,3 @@ def computeR(W, b, d, H, Rshape=None): ...@@ -421,7 +430,3 @@ def computeR(W, b, d, H, Rshape=None):
"" # close loop over i "" # close loop over i
return R return R
from theano.tensor.nnet.Conv3D import conv3D
from theano.tensor.nnet.ConvGrad3D import convGrad3D
...@@ -89,7 +89,6 @@ whitelist_flake8 = [ ...@@ -89,7 +89,6 @@ whitelist_flake8 = [
"tensor/signal/tests/test_conv.py", "tensor/signal/tests/test_conv.py",
"tensor/signal/tests/test_downsample.py", "tensor/signal/tests/test_downsample.py",
"tensor/nnet/__init__.py", "tensor/nnet/__init__.py",
"tensor/nnet/ConvTransp3D.py",
"tensor/nnet/sigm.py", "tensor/nnet/sigm.py",
"tensor/nnet/ConvGrad3D.py", "tensor/nnet/ConvGrad3D.py",
"tensor/nnet/conv3d2d.py", "tensor/nnet/conv3d2d.py",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论